Original Post
I posted in the beginners forum, but i didn''t get much help, so here''s my problem again:
I''m trying to get my vertex buffer to work, but when I run my program, nothing shows up on screen. I''ve tried changing alot of stuff, but nothing works. Heres some code for initialization and rendering:
If anyone could please look over it and see if anything is wrong, I''d be very grateful. Also, I''m using C++ (if you didn''t look at the code) and DX9.
Thanks
Hibiki
Wheres the any key?
www.geocities.com/dragongames123/home.html
INSERT MY OVER-SIZED EXTRAVOGENT PIC HERE:
int CDragonVertexBuffer::Create(IDirect3DDevice9 *tempG,unsigned long verts,DWORD descriptor,long vsize)
{
graphics = tempG; //store device in member variable
FVF = descriptor;
vertexsize = vsize;
num_verticies = verts;
//VB is the IDirect3DVertexBuffer9 object
if(FAILED(tempG->CreateVertexBuffer(num_verticies * vertexsize,0,FVF,
D3DPOOL_DEFAULT,&VB,NULL)))
{
Error_Message("Create Vertex Buffer");
return(0);
}
assert(VB != NULL);
return(1);
}
int CDragonVertexBuffer::Set(unsigned long FirstVertex,unsigned long numverts,void *Vlist)
{
assert(Vlist != NULL);
//vlist is a pointer to an array of initalized vertexes
Lock(FirstVertex,numverts);
Ptr is a pointer to void
memcpy(Ptr, Vlist, numverts * vertexsize);
Unlock();
graphics->SetStreamSource(0,VB,0,sizeof(DragonVertex));
graphics->SetVertexShader(NULL);
return(1);
}
int CDragonVertexBuffer::Lock(unsigned long FirstV,unsigned long NumVerts)
{
if(locked) //test if the buffer is alreadylocked
return(1);
if(FAILED(VB->Lock(0,NumVerts * vertexsize,(void**)&Ptr,
0)))
{
Error_Message("Lock VB");
return(0);
}
locked = true;
return(1);
}
int CDragonVertexBuffer::Unlock()
{
if(!locked)
return(1);
if(FAILED(VB->Unlock()))
{
Error_Message("Unlock VB");
return(0);
}
locked = false;
return(1);
}
int CDragonVertexBuffer::Render(unsigned long FirstV,unsigned long numprimitives,DWORD type)
{
assert(VB != NULL);
if(FAILED(graphics->DrawPrimitive((D3DPRIMITIVETYPE)type,
FirstV,numprimitives)))
{
Error_Message("Draw Primitive");
return(0);
}
return(1);
}
#define CUSTOMDRAGON_VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
struct DragonVertex
{
float x,y,z;
float nx,ny,nz;
D3DCOLOR DiffuseColor;
D3DCOLOR SpecularColor;
//float tu, tv;
};