Sign in to follow this  
Scar

Vertex Buffer Help

Recommended Posts

It looks like everything is right to me, but nothing is showing up. Can anyone shed some light on my poor soul:
// VERTEX FORMAT ///////
typedef struct __declspec(dllexport) CUSTOMLINEVERTEX
{
	float x,y,z;
	D3DCOLOR color;
}CUSTOMLINEVERTEX;
#define CUSTOMLINEFVF D3DFVF_XYZ|D3DFVF_DIFFUSE


// Creating buffer////////
m_VertexBuffer = NULL;
ZDriver->GetDeviceCOM()->CreateVertexBuffer(4*sizeof(CUSTOMLINEVERTEX), 0, CUSTOMLINEFVF, D3DPOOL_DEFAULT, &m_VertexBuffer, 0);

// Setting up vertex///////
if( m_VertexBuffer == NULL )
		return;

CUSTOMLINEVERTEX* pVertex;

m_VertexBuffer->Lock(0, 0, (void**)&pVertex, 0);
pVertex->x = 2.0f; //UPPER RIGHT CORNER
pVertex->y = 2.0f;
pVertex->z = 0.0f;
pVertex->color = m_Color;
pVertex++;

pVertex->x = 2.0f; //BOTTOM RIGHT CORNER
pVertex->y = -2.0f;
pVertex->z = 0.0f;
pVertex->color = m_Color;
pVertex++;

pVertex->x = -2.0f; //TOP LEFT CORNER
pVertex->y = 2.0f;
pVertex->z = 0.0f;
pVertex->color = m_Color;
pVertex++;

pVertex->x = -2.0f; //BOTTOM LEFT CORNER
pVertex->y = -2.0f;
pVertex->z = 0.0f;
pVertex->color = m_Color;
m_VertexBuffer->Unlock();

// RENDER LOOP //////
_Device->SetStreamSource(0, line->m_VertexBuffer, 0, sizeof(CUSTOMLINEVERTEX));
_Device->SetFVF(CUSTOMLINEFVF);
_Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
_Device->SetStreamSource(0, 0, 0, 0);

And that's about it, the world/proj/view matrices are set correctly btw, I have other stuff rendering this is the only thing that doesn't work. By a glance, does anyone see anything wrong with it? Any help will be greatly appreciated, thanks. -Scar

Share this post


Link to post
Share on other sites
Hi bud,

As far as i can see there is nothing wrong with that. Although i usually memcpy into the vertex buffer from a standars array of std::vector. Are you setting any renderstates or anything in your main loop. Have you turn off culling and turned on the z-buffer?


Ace

Share this post


Link to post
Share on other sites
Your triangle is counter clockwise. You need either change your culling to D3DCULL_CW or else change the orientation of your triangle.

Also a possibility, since you specified XYZ instead of XYZW, it goes through TnL before it hits the screen. You say transform is correct, so that leaves lighting. If lighting is on (render state), but you haven't specified any lights, this will be the result.

If this isn't the problem, then we will need a bit more detail about the rest of the scene. Perhaps you have z-fighting etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this