Skip to main content
gamedev.net
🔒 Locked

Post your optimized D3D Init code

Started by Insodus Jan 16, 2003 at 5:26 PM 4 replies 400+ views
Original Post
Insodus
Insodus
I've just got my engine working, as you can proly see in a near by post, and I was wondering how I can optimize the Direct3D Init calls to use all the hardware each client has to offer. Any specific tricks would also be welcome.
    
	pD3D = Direct3DCreate8( D3D_SDK_VERSION );
	if( pD3D == NULL) {
		MainErr->HandleError(__FILE__, __LINE__, CRITICAL, D3D_ERROR, "Error creating Direct3D object.");
	}

	D3DDISPLAYMODE d3ddm;
	hRet = pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
	if( FAILED( hRet ) ) {
		MainErr->HandleError(__FILE__, __LINE__, CRITICAL, D3D_ERROR, "Error getting display mode.", hRet);
	}

	pD3DCaps = new D3DCAPS8();
	hRet = pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pD3DCaps );
	if( FAILED( hRet ) ) {
		MainErr->HandleError(__FILE__, __LINE__, CRITICAL, D3D_ERROR, "Error getting device capabilities.", hRet);
	}

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = Windowed;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.Flags = 0;
	d3dpp.hDeviceWindow = main_window_handle;
	d3dpp.BackBufferFormat = d3ddm.Format;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferWidth = WINDOW_WIDTH;
	d3dpp.BackBufferHeight = WINDOW_HEIGHT;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

	switch(DefaultBitsPerPixel) {
		case 16:
			d3dpp.BackBufferFormat = D3DFMT_R5G6B5;
			break;
		case 24:
			d3dpp.BackBufferFormat = D3DFMT_R8G8B8;
			break;
		case 32:
			d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
			break;
	}


	hRet = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, main_window_handle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pD3DDevice );
	if (FAILED(hRet)) {
		MainErr->HandleError(__FILE__, __LINE__, CRITICAL, D3D_ERROR, "Error creating Direct3D object.", hRet);
	}
    
[edited by - Insodus on January 16, 2003 9:03:12 PM]
---------------------------------"Without C, all we would have is Pasal, Basi, and obol.""Black holes are where god divided by zero."http://www.insodus.com
IFooBar
IFooBar
well you can try something like this. There is no source code yet, but there will be within 2-3 days...

The piece of software selects the best display mode configuration depending on the options you give it.


:::Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile
[size=2]aliak.net
don
don
Do a big favor for blokes like me and present a list of which card/device to run the game on. I''ve got three 19" LCD monitors and I get really pissed when a game just uses the default instead of allowing me to select which monitor I want. Thanks!

Insodus
Insodus
I think that is trickier than it sounds. Anyone out there with some code to do that? Or at least find out how many displays there are, I think we can deal with displaying them.
---------------------------------"Without C, all we would have is Pasal, Basi, and obol.""Black holes are where god divided by zero."http://www.insodus.com
IFooBar
IFooBar
quote:
Do a big favor for blokes like me and present a list of which card/device to run the game on

that's what the app i gave the link to does
quote:
I've got three 19" LCD monitors...

can i have one??
quote:
...and I get really pissed when a game just uses the default instead of allowing me to select which monitor I want


I dotnt hink there is anything with direct3d that allows for monitor enumeration. I think you'll have to manage that on your own with the monitors. If you have an nVidia display card, then nVidia provides this software with it called nView. And you can use nView to move applications from one monitor to the other. If you dont have an nvidia card then maybe there is other software out there like that (more specific to your card).

So we can let you select the device/display mode. but i havent see the s"select a monitor" thingy before, and i cant say id know how to do that. Maybe there are some functions with the windows sdk that lets you do that?


::: Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile

[edited by - IFooBar on January 18, 2003 3:12:17 AM]
[size=2]aliak.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.