Problems with Getting DX9 set up

Started by
4 comments, last by Peon 21 years ago
I''ve spent about an HOUR going over the D3D9 tutorial that comes with the DirectX9 SDK, about how to set up a basic program. So far, I''ve created a window, requested an interface, created a device, and tried to "Clear()" it to a certain color. All of it works, except the Clear() part. I have some basic error checking, and there doesn''t seem to be any problems (though if I set the d3dpp.Windowed to false (ie: fullscreen) I get a "Cannot Create Device error"... strange) By default, my window is white, and it stays white. Having read the description of Clear(), I would expect it to become the color I assign it. Take a look at my code:
  
if (FAILED(ID3D = Direct3DCreate9(D3D_SDK_VERSION)))
	{
		MessageBox(NULL, "Could not create Direct 3D 9 interface", "Error", MB_OK);
	}

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed		   = false;
	d3dpp.SwapEffect	   = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	if (FAILED(ID3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, myWindow,
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                   &d3dpp, &device ) ) )

	{
		MessageBox(NULL, "Could not create device", "Error", MB_OK);

	}//endif


	//paint the screen red

	device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);  
The code is almost word for word out of the MS tutorial, yet I still can''t get my window to become a certain color. Perhaps I am misinterpreting the actual function of Clear(), though it does sound like, to me, that you can set the color of the background using clear. I know this is a really stupid problem, but help is greatly appreciated Peon
Peon
Advertisement
Just based on a quick glance at your code, I''d say the problem is you''re not calling:
device->Present(0, 0, 0, 0); 

Present has the effect of swapping the back buffers, displaying the rendering you''ve done in the current frame.

Just a guess though, I could be wrong.
Oh interesting... that did it, alright. I''m a little confused now though. How is it that I drew to the backbuffer? Does Clear() do that automatically? I would have thought I would have had to tell it SPECIFICALLY to draw to the back buffer.
Peon
Hi,

Generally you will always *want* draw to the backbuffer, even if you wrote your own renderer. These reason is that rendering to the primary surface will cause nasty artifacts as you watch the rendering take place. I think this is why D3D automatically assumes the backbuffer is being used.

Of course I could be wrong so if anyone else knows any other reason post it. I''d be interested to know if this is true or not.
Yea, I know what you mean, I just thought it would be something you had to tell it to do. Still, it''s a nice feature, to automatically draw to the backbuffer, if that is indeed the case.

Off the main topic I guess, but can anyone see a problem in the above code that would cause CreateDevice() to fail when trying to run it full screen?
Peon
quote:Original post by Peon
Off the main topic I guess, but can anyone see a problem in the above code that would cause CreateDevice() to fail when trying to run it full screen?


you cant use D3DFMT_UNKNOWN as a back buffer format when in full screen.

This topic is closed to new replies.

Advertisement