Skip to main content
gamedev.net
🔒 Locked

Minimal D3D code

Started by Christiaan 1 reply 900+ views
Original Post
Christiaan
Christiaan
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
WitchLord
WitchLord
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
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Buster
Buster
Microsoft''s DX help files show you the code for that.

Topic Locked

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

Sign in to reply to this topic.