Nothing Rendering in D3D9

I think I've coded this stuff right, but all I get is a blank screen when I run the program. In my init function I have this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* initialize 3D components */

//creating the view matrix
m_eyePos = D3DXVECTOR3(0, -2, 10);
m_lookAt = D3DXVECTOR3(0, 0, 0);
m_upVec = D3DXVECTOR3(0, 1, 0);
D3DXMatrixLookAtLH(&m_V, &m_eyePos, &m_lookAt, &m_upVec);

//creating the projection matrix
D3DXMatrixPerspectiveFovLH(&m_proj, D3DX_PI * 0.361f, (float)m_width / (float)m_height, 1.0f, 1000.0f);

//create vertex declaration
D3DVERTEXELEMENT9 VertexElements[] = {
	{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
	{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
	{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
	D3DDECL_END()
};
m_pD3DDevice->CreateVertexDeclaration(VertexElements, &VertexDecl);

/* define the cube geometry */
DefineCube();

//create vertex and index buffer /* might need to change some of these values if I have problems */
m_pD3DDevice->CreateVertexBuffer(24 * sizeof(Vertex), 0, 0, D3DPOOL_MANAGED, &VertexBuffer, 0);
m_pD3DDevice->CreateIndexBuffer(36 * sizeof(WORD), D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &IndexBuffer, 0);


In the actual render function I have this:
1
2
3
4
5
6
7
8
9
m_pD3DDevice->SetTransform(D3DTS_VIEW, &m_V);
m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &m_proj);
m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

m_pD3DDevice->SetStreamSource(0, VertexBuffer, 0, sizeof(Vertex));
m_pD3DDevice->SetIndices(IndexBuffer);
m_pD3DDevice->SetVertexDeclaration(VertexDecl);

m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);


Am I missing something in my code? or is my logic for how I have it wrong? It should be drawing a cube. I have all the vertices and indices set up properly in the DefineCube() function, so I am not sure what is wrong.
Last edited on
Sanity check: are you doing a framebuffer swap?
Yeah, in the beginning of Render() I have:
1
2
3
// Clear the back buffer, call BeginScene()
HR(m_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , m_clearColor, 1.0f, 0));
HR(m_pD3DDevice->BeginScene())


And at the end of Render() I have:
1
2
3
// EndScene, and Present the back buffer to the display buffer
HR(m_pD3DDevice->EndScene())
HR(m_pD3DDevice->Present(0, 0, 0, 0));
Last edited on
I finally got it working. I think the problem was simply the variable types I was using for VertexBuffer, IndexBuffer, and VertexDecl.

Originally, I had this:
1
2
3
IDirect3DVertexDeclaration9*	        VertexDecl;	//stores vertex element description
IDirect3DVertexBuffer9*			VertexBuffer;	//stores vertices in memory
IDirect3DIndexBuffer9*			IndexBuffer;	//stores indices in memory 


Then I changed it to this:
1
2
3
LPDIRECT3DVERTEXBUFFER9				VertexBuffer;	//stores vertices in memory
LPDIRECT3DINDEXBUFFER9				IndexBuffer;	//stores indices in memory
LPDIRECT3DVERTEXDECLARATION9		        VertexDecl;


Now I see it rendered in all its dark unlit glory. Off to adding lighting and eventually animation for the cube then! :D
closed account (10X9216C)
Those are exactly the same, they are just typedefs to remove the *.
Topic archived. No new replies allowed.