Exemplo n.º 1
0
static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
{
    IDirect3DDevice7 *device = NULL;
    IDirectDrawSurface7 *surface;
    DDSURFACEDESC2 surface_desc;
    IDirectDraw7 *ddraw;
    IDirect3D7 *d3d7;
    HRESULT hr;

    if (!(ddraw = create_ddraw()))
        return NULL;

    hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);

    memset(&surface_desc, 0, sizeof(surface_desc));
    surface_desc.dwSize = sizeof(surface_desc);
    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
    surface_desc.dwWidth = 640;
    surface_desc.dwHeight = 480;

    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
    ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);

    if (coop_level & DDSCL_NORMAL)
    {
        IDirectDrawClipper *clipper;

        hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
        ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
        hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
        ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
        hr = IDirectDrawSurface7_SetClipper(surface, clipper);
        ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
        IDirectDrawClipper_Release(clipper);
    }

    hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
    IDirectDraw7_Release(ddraw);
    if (FAILED(hr))
    {
        IDirectDrawSurface7_Release(surface);
        return NULL;
    }

    hr = IDirect3D7_CreateDevice(d3d7, &IID_IDirect3DTnLHalDevice, surface, &device);
    IDirect3D7_Release(d3d7);
    IDirectDrawSurface7_Release(surface);
    if (FAILED(hr))
        return NULL;

    return device;
}
Exemplo n.º 2
0
int create_test_d3d_device ( int width, int height )
{

	D3DDEVICEDESC7
		hardware_desc;

	unsigned int
		d3drval;

	//
	// Get a d3d3 driver interface
	//
#ifdef _WIN32
	d3drval = IDirectDraw7_QueryInterface ( ddraw.ddraw, &IID_IDirect3D7, &d3d.d3d );

	if ( d3drval != DD_OK )
	{

		debug_log ( "Can't get a d3d device in this resolution" );

		return ( FALSE );
	}

	//
	// Query for a D3DDEVICE2 object
	//

	d3drval = IDirect3D7_CreateDevice ( d3d.d3d, &IID_IDirect3DHALDevice, ddraw.lpRenderBuffer, &d3d.device );

	if ( d3drval != DD_OK )
	{

		debug_log ( "Can't get a d3d device2 in this resolution" );

		return ( FALSE );
	}

	//
	// Get the capabilities of the device
	//

	d3drval = IDirect3DDevice7_GetCaps ( d3d.device, &hardware_desc );

	if ( d3drval != DD_OK )
	{

		debug_log ( "Unable to get the d3d device capabilities at this resolution" );

		return ( FALSE );
	}
#endif
	//
	// Set the capabilities of the 3dvisual according to the capabilities of the card.
	//

	set_d3d_capabilities ( &hardware_desc );

	//
	// Set render target
	//
#ifdef _WIN32
	d3drval = IDirect3DDevice7_SetRenderTarget ( d3d.device, ddraw.lpRenderBuffer, 0 );

	if ( d3drval != DD_OK )
	{

		debug_log ( "Unable to set render target" );

		return ( FALSE );
	}
#endif
	{

		D3DVIEWPORT7
			viewdata;

		viewdata.dwX = 0;
		viewdata.dwY = 0;

		viewdata.dwWidth = application_video_width;
		viewdata.dwHeight = application_video_height;

		viewdata.dvMinZ = 0;
		viewdata.dvMaxZ = 1;
#ifdef _WIN32
		d3drval = IDirect3DDevice7_SetViewport ( d3d.device, &viewdata );

		if ( d3drval != D3D_OK )
		{

			debug_log ( "Unable to set viewport2: %d, %d, %s", application_video_width, application_video_height, get_d3d_error_message ( d3drval ) );

			return ( FALSE );
		}
#endif
        glViewport(viewdata.dwX, viewdata.dwY, viewdata.dwWidth, viewdata.dwHeight);
        glDepthRange(viewdata.dvMinZ, viewdata.dvMaxZ);
	}

	//
	// Create the vertex buffers
	//

	create_d3d_vertex_buffers ();

	return ( TRUE );
}