Original Post
ok, I am new to direct x programming, and attempted to do my first vertex/index buffers and display primitives. The buffers are created and filled without any trouble, however, they fail to display,
here is the class declaration :
#define BUFTYPE_TRI 0
#define BUFTYPE_QUAD 1
class Vertex
{
public:
Vertex();
Vertex(float X,float Y,float Z)
{
x=X;y=Y;z=Z;
};
float x,y,z;
};
class GObject
{
public:
int nVertices;
Vertex* Vertices;
WORD* Indices;
IDirect3DVertexBuffer9* vb;
IDirect3DIndexBuffer9* ib;
void CreateBuffer(int NumOfVertices);
void FillBuffer(char* szFileName);
void DisplayBuffer(unsigned int uType);
};
here is the code for my creation/filling
void GObject::CreateBuffer(int NumOfVertices)
{
HRESULT hRes;
nVertices = NumOfVertices;
hRes = g_EchD3D.g_d3d_device->CreateVertexBuffer(nVertices * sizeof(Vertex),
D3DUSAGE_WRITEONLY,
D3DFVF_XYZ,
D3DPOOL_MANAGED,
&vb,
0);
if(hRes != D3D_OK)
MessageBox(NULL,"Could Not Initialize VertexBuffer","D3D Init Error",MB_OK);
hRes = g_EchD3D.g_d3d_device->CreateIndexBuffer(nVertices * sizeof(Vertex),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&ib,
0);
if(hRes != D3D_OK)
MessageBox(NULL,"Could Not Initialize IndexBuffer","D3D Init Error",MB_OK);
};
void GObject::FillBuffer(char* szFileName)
{
HRESULT hRes;
hRes = vb->Lock(0,0,(void**)&Vertices,0);
if(hRes != D3D_OK)
{
MessageBeep(0);
MessageBox(NULL,"Could Not Lock VertexBuffer","D3D Init Error",MB_OK);
}
Vertices[0] = Vertex(-1.0f,0.0f,3.0f);
Vertices[2] = Vertex(0.0f,1.0f,3.0f);
Vertices[3] = Vertex(1.0f,0.0f,3.0f);
hRes = vb->Unlock();
if(hRes != D3D_OK)
{
MessageBeep(0);
MessageBox(NULL,"Could Not unlock VertexBuffer","D3D Init Error",MB_OK);
}
hRes = ib->Lock(0,0,(void**)&Indices,0);
if(hRes != D3D_OK)
{
MessageBeep(0);
MessageBox(NULL,"Could Not Lock IndexBuffer","D3D Init Error",MB_OK);
}
Indices[0] = 0;
Indices[1] = 1;
Indices[2] = 2;
hRes = ib->Unlock();
if(hRes != D3D_OK)
{
MessageBeep(0);
MessageBox(NULL,"Could Not unLock IndexBuffer","D3D Init Error",MB_OK);
}
};
and the display code:
void GObject::DisplayBuffer(unsigned int uType)
{
g_EchD3D.g_d3d_device->SetStreamSource(0,vb,0,sizeof(Vertex));
g_EchD3D.g_d3d_device->SetIndices(ib);
g_EchD3D.g_d3d_device->SetFVF(D3DFVF_XYZ);
g_EchD3D.g_d3d_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,3,0,1);
return;
};
and here is the rendering code:
void InitScene()
{
CameraAtOrig();
SetDefaultProj();
gObj.CreateBuffer(3);
gObj.FillBuffer((char*) 0);
};
void EchD3DxGUI::Render()
{
g_d3d_device->Clear(0,0,D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET,0x00000000,1.0f,0);
g_d3d_device->BeginScene();
gObj.DisplayBuffer(BUFTYPE_TRI);
g_d3d_device->EndScene();
g_d3d_device->Present(0,0,0,0);
};
It loads up and starts fine, however, nothing is blitted to the screen.