This method of the Direct3dRM Class creates a Microsoft® Windows® device for rendering from the specified DirectDraw surfaces. It is important that all objects are derived from the same DirectDraw object. In DirectX for Java, it is also important to use create methods to construct objects, rather than using new. Using new to create certain DirectX for Java objects creates uninitialized objects that can be difficult or impossible to manipulate.
public Direct3dRMDevice createDeviceFromSurface(_Guid g, DirectDraw dd, DirectDrawSurface DDsBack);
The following code example shows how to use the createDeviceFromSurface method and create appropriate objects without using new:
int hw =0; //depends on hardware dd = new DirectDraw(); dd.setCooperativeLevel (this, DDSCL_NORMAL); //Create a surface ddsd = new DDSurfaceDesc(); ddsd.flags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; if (hw==1){ ddsd.ddsCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN | CAPS_VIDEOMEMORY; } else{ ddsd.ddsCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; } ddsd.width = w; ddsd.height = h; ddsOffscreen = dd.createSurface(ddsd); d3d = dd.createD3D(); // Find the device's Guid for a device type specified by // application info object - can be RGB or MONO // _Guid g = d3d.findDeviceForColorModel(D3DCOLOR_RGB, hw ); rmDevice = d3drm.createDeviceFromSurface(g, dd,ddsOffscreen);
Returns the Direct3dRMDevice object if successful; otherwise, null.
g | The globally unique identifier (GUID) used as the required device driver. If this parameter is null, the default device driver is used. |
dd | The DirectDraw object that is the source of the DirectDraw surface. |
DDsBack | The DirectDrawSurface object that represents the back buffer. |