Hey,
I'm trying to add a class to deal with vertex buffers for me, but I think something is wrong. When I set the verts and everything nothing renders. I just don't see anything. I have checked the order and it's clockwise. Anyway I just want to be able to render a triangle. This is my class:
class iVertexBuffer
{
protected:
IDirect3DVertexBuffer9 *m_buffer;
Graphics::DirectX::DirectXLayer *m_parent;
UINT m_size; //size of the buffer (vertices * size of structure)
UINT m_verts; //number of verts
UINT m_vertsize; //size of vertex structure
bool m_Locked;
DWORD m_FVF; //holds the FVF structure
public:
iVertexBuffer(Graphics::DirectX::DirectXLayer *parent);
bool Create(DWORD fvf); //create the buffer using default settings
bool Create(DWORD use, DWORD fvf, D3DPOOL pool); //create the buffer using verbose settings
~iVertexBuffer();
bool Fill(void **vertices, UINT offset = 0, UINT size = 0, DWORD flags = NULL); //fills buffer with data
void SetVertInfo(UINT verts, UINT sizeofverts); //Pass Number of verts to this before calling create (pass sizeof(FVFstructure) to sizeofverts)
bool GetState(); //get the locked state of the buffer
bool Done(); //Call after Fill once vertex operations
bool RenderSimple(UINT vertsize);
bool RenderDefault(UINT vertsize);
};
And the definitions
Graphics::DirectX::iVertexBuffer::iVertexBuffer(Graphics::DirectX::DirectXLayer *parent)
{
m_size = 0;
m_parent = parent;
m_buffer = NULL;
m_texture = NULL;
m_material = NULL;
m_indexbuffer = NULL;
}
bool Graphics::DirectX::iVertexBuffer::Create(DWORD fvf)
{
m_FVF = fvf;
if(FAILED(m_parent->Device()->CreateVertexBuffer(m_size, D3DUSAGE_WRITEONLY, fvf, D3DPOOL_MANAGED, &m_buffer, NULL)))
return false;
return true;
}
bool Graphics::DirectX::iVertexBuffer::Create(DWORD use, DWORD fvf, D3DPOOL pool)
{
m_FVF = fvf;
if(FAILED(m_parent->Device()->CreateVertexBuffer(m_size, use, fvf, pool, &m_buffer, NULL)))
return false;
return true;
}
bool Graphics::DirectX::iVertexBuffer::Fill(void **vertices, UINT offset, UINT size, DWORD flags)
{
m_Locked = (SUCCEEDED(m_buffer->Lock(offset, size,(void**) vertices, flags)));
return m_Locked;
}
void Graphics::DirectX::iVertexBuffer::SetVertInfo(UINT verts, UINT sizeofverts)
{
m_size = (verts * sizeofverts);
m_verts = verts;
m_vertsize = sizeofverts;
}
bool Graphics::DirectX::iVertexBuffer::GetState()
{
return m_Locked;
}
bool Graphics::DirectX::iVertexBuffer::Done()
{
return SUCCEEDED(m_buffer->Unlock());
}
Graphics::DirectX::iVertexBuffer::~iVertexBuffer()
{
if(m_buffer)
m_buffer->Release();
m_buffer = NULL;
m_size = NULL;
m_Locked = false;
}
bool Graphics::DirectX::iVertexBuffer::RenderSimple(UINT vertsize)
{
if(m_parent->GetRenderOK())
{
if(m_material)
m_parent->Device()->SetMaterial(m_material->Get());
if(m_texture)
m_parent->Device()->SetTexture(0, m_texture->Image());
else
m_parent->Device()->SetTexture(0, NULL);
m_parent->Device()->SetStreamSource( 0, m_buffer, 0, vertsize);
m_parent->Device()->SetFVF(m_FVF);
if(FAILED(m_parent->Device()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (m_verts/3))))
return false;
}
return true;
}
bool Graphics::DirectX::iVertexBuffer::RenderDefault(UINT vertsize)
{
if(m_parent->GetRenderOK())
{
m_parent->Device()->SetTexture(0, NULL);
m_parent->Device()->SetStreamSource(0 , m_buffer, 0, vertsize);
m_parent->Device()->SetFVF(m_FVF);
if(FAILED(m_parent->Device()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (m_verts/3))))
return false;
}
return true;
}
This is slightly stripped down, but the other parts don't matter
I don't understand why it doesn't work. I can't debug since breaking the program makes it stop processing windows messages, meaning that it won't minimize.
(I could change that with the Exclusive tag right?)
Here is how I am using this
Graphics::DirectX::iVertexBuffer VB(&Direct3D);
VB.SetVertInfo(3, sizeof(Graphics::DirectX::iFVF_S));
VB.Create(FVF_S);
Graphics::DirectX::iFVF_S *vertex;
VB.Fill((void**) &vertex);
vertex[0] = Graphics::DirectX::iFVF_S(-1.0f, 0.0f, 2.0f);
vertex[1] = Graphics::DirectX::iFVF_S(0.0f, 1.0f, 2.0f);
vertex[2] = Graphics::DirectX::iFVF_S(1.0f, 0.0f, 2.0f);
VB.Done();
while(on)
{
App.MsgLoop();
App.Update();
if(App.Active)
{
Direct3D.ClearScreen();
Direct3D.StartRender();
VB.RenderDefault(sizeof(iFVF_S));
Direct3D.EndRender();
keyboard.Scan();
//methods of escape
if(keyboard.CheckKey(DIK_ESCAPE))
break;
if(keyboard.CheckKey(DIK_M))
PostMessage(App.m_hWnd, WM_ACTIVATEAPP, false, NULL);
if(App.Done)
break;
Direct3D.Present();
}
}
App.End();
Direct3D.End();
that's just a slice of my winmain
I am working to track down this problem, but I have been over my code several times and I am getting frusterated. Any help would be greatly appreciated. (Oh, and iFVF_S is just X,Y, and Z. Untransformed cords.)
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be