Jump to content
  • Advertisement

Archived

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

Christiaan

Minimal D3D code

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can someone give me the absolute minimal code to initialize Direct3D and draw a triangle on screen I just can''t figure out how to do it or.... probably I''m just too lazy to read the all the unclear tutorials... chris

Share this post


Link to post
Share on other sites
Advertisement
First you need to create the window. I''ll assume you know how to do that until you tell me otherwise.

Then you can initalize D3D with the following code

D3DXInitialize();
IDirect3DXContext *pContext;
D3DXCreateContext(D3DX_DEFAULT,0,hWnd,D3DX_DEFAULT,D3DX_DEFAULT,&pContext);
IDirect3DDevice7 *p3DDev;
pD3DDev = pContext->GetD3DDevice();
pContext->SetClearColor(0xFFFFFFFF);

Then you can render a triangle like this:

pContext->Clear(D3DCLEAR_TARGET/D3DCLEAR_ZBUFFER);
D3DVERTEX Verts[3] = {
D3DVERTEX(D3DVECTOR(1,-1,1),D3DVECTOR(0,0,-1),0,0),
D3DVERTEX(D3DVECTOR(-1,-1,1),D3DVECTOR(0,0,-1),0,0),
D3DVERTEX(D3DVECTOR(0,1,1),D3DVECTOR(0,0,-1),0,0)};
pD3DDev->DrawPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,Verts,3,0);
pContext->UpdateFrame(0);

Finally you clean up the code like this

pD3DDev->Release();
pContext->Release();
D3DXUnitialize();

This code should render a black triangle on a white background.

- WitchLord

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!