Archived

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

infinitycool

ZBuffer + (Screen) Transformed Vertices

Recommended Posts

I''m losing sleep over this most likely very stupid problem. For some reason I cannot see my square (transformed vertices) after I set up and enable my z-buffer. Has anyone else ever had this kind of problem? I can see it fine before adding these two lines of code to my D3DPRESENT_PARAMETERS struct: d3dpp.EnableAutoDepthStencil = TRUE; // for the z buffer d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // ditto I''ve got my viewing plane set from 1.0 to 100.0 and.... this is the code I''m using to render the square: g_d3dDev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB255,255,255), 1.0f,0); theDevice->SetTransform( D3DTS_WORLD, &m_LocalMatrix ); theDevice->SetStreamSource(0,m_VertexBuffer, sizeof(HPBOXVERTEX)); theDevice->SetVertexShader(D3DFVF_HPBOXVERTEX); theDevice->SetTexture(0,m_Texture); theDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); I''ve tried increasing the z coordinates of the squares vertices and I''ve tried moving the camera around but I still can''t see it. The funny thing is, if I remove the z-buffer in the D3DPRESENT_PARAM.. structure , I can see the square again. If anyone can see an obvious mistake on my part I''ll be greatly appreciative.

Share this post


Link to post
Share on other sites
The code is this:

struct HPBOXVERTEX
{
D3DXVECTOR3 position;
FLOAT znorm;
FLOAT tu, tv;
};

#define D3DFVF_HPBOXVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1)


btw, xStart is used to create a horixontal offset for the box and is set to zero.

HPBOXVERTEX g_Vertices[4];
g_Vertices[0].position = D3DXVECTOR3( xStart, 352.0f, 2.0f);
g_Vertices[0].znorm = 1.0f;
g_Vertices[0].tu = 0.0f;
g_Vertices[0].tv = 0.0f;
g_Vertices[1].position = D3DXVECTOR3(xStart+128.0f, 352.0f, 2.0f);
g_Vertices[1].tu = 1.0f;
g_Vertices[1].tv = 0.0f;
g_Vertices[1].znorm = 1.0f;
g_Vertices[2].position = D3DXVECTOR3( xStart, 480.0f, 2.0f);
g_Vertices[2].tu = 0.0f;
g_Vertices[2].tv = 1.0f;
g_Vertices[2].znorm = 1.0f;
g_Vertices[3].position = D3DXVECTOR3(xStart+128.0f, 480.0f, 2.0f);
g_Vertices[3].tu = 1.0f;
g_Vertices[3].tv = 1.0f;
g_Vertices[3].znorm = 1.0f;
//g_Vertices[4].position = D3DXVECTOR3(-50.0f, 0.0f, 50.0f);
//g_Vertices[4].tu = 1.0f;
//g_Vertices[4].tv = 0.0f;

theDevice->CreateVertexBuffer( 4*sizeof(HPBOXVERTEX),0, D3DFVF_HPBOXVERTEX,
D3DPOOL_DEFAULT, &m_VertexBuffer);
VOID* pVertices;
m_VertexBuffer->Lock( 0,0, (BYTE**)&pVertices, 0 );
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
m_VertexBuffer->Unlock();


Share this post


Link to post
Share on other sites
On first glance it appears that you need to switch the coords for vertex 1 with vertex 2...it seems you are drawing your triangle with its back to the camera
so to get correct clockwise orientation draw your square with its for vertices as vertex0(x,y,z) vertex1(x,y+Height,z) vertex2(x+width,y,z) vertex3(x+width,y+height,z)
why it draws in the 2d without that i am not sure as i have not worked without the zbuffer enabled much at all

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
On first glance it appears that you need to switch the coords for vertex 1 with vertex 2...it seems you are drawing your triangle with its back to the camera
so to get correct clockwise orientation draw your square with its for vertices as vertex0(x,y,z) vertex1(x,y+Height,z) vertex2(x+width,y,z) vertex3(x+width,y+height,z)
why it draws in the 2d without that i am not sure as i have not worked without the zbuffer enabled much at all

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m pretty sure that I''m using the correct vertices. Grrr so very confused. Oh well at least my Direct Input is working lol.

Share this post


Link to post
Share on other sites