• ### Popular Now

• 12
• 12
• 9
• 10
• 13

#### Archived

This topic is now archived and is closed to further replies.

# Problems with Getting DX9 set up

This topic is 5477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.BackBufferFormat = D3DFMT_UNKNOWN;

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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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.