well as the title says I''m trying to make a class so I can make "infinite" quads
but here''s my problem, how do I deal with the variables that always need a new name?!?
I mean for each quad I need a new pointer to a IDirect3DVertexBuffer8, right. so how do I solve this?
here''s my CQuad.h :
#include <d3d8.h> // Direct3D header file
//class definition of Quad :
class CQuad
{
private:
struct my_vertex
{
FLOAT x, y, z, rhw; // The transformed position for the vertex.
DWORD color; // The vertex color.
} ; // end of struct
public:
void DrawQuad() ;
void InitQuad(float fStartX, float fStartY, float fEndX, float fEndY, DWORD color) ;
void ReleaseQuad() ;
} ; // end of class
and this is my CQuad.cpp :
#include "CQuad.h"
IDirect3DVertexBuffer8 *g_square=NULL ; // what to do with this one???
void CQuad::DrawQuad()
{
#define D3D8T_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
// Vertex shaders are a complex topic, but you can do some amazing things with them
// For this example we''re not creating one, so we tell Direct3D that we''re just
// using a plain vertex format.
g_lpDevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
// Set the active stream to be our square.
// NOTE: Because of the offsets that DrawPrimitive takes, we could
// have built the triangle & square into a single VB and still
// drawn them seperately.
g_lpDevice->SetStreamSource(0,g_square,sizeof(my_vertex));
// Now we''re drawing a Triangle Strip, 4 vertices to draw 2 triangles.
g_lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
void CQuad::InitQuad(float fStartX, float fStartY, float fEndX, float fEndY, DWORD color)
{
// Declare a structure to hold a vertex with all the information that we need
struct my_vertex
{
FLOAT x, y, z, rhw ; // The transformed position for the vertex.
DWORD color; // The vertex color.
} ; // end of struct
// A handy little ''macro'' for our definition of the vertex. When we use the vertex data
// we have to tell D3D what data we''re passing it. D3DFVF_DIFFUSE specifies that the
// vertex will have a colour, the D3DFVF_XYZRHW specifies that the vertex will have
// coordinate given in screen space.
#define D3D8T_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
my_vertex g_square_vertices[] =
{
{ fStartX, fEndY , 0.5f, 1.0f, color }, // x, y, z, rhw, color
{ fStartX, fStartY, 0.5f, 1.0f, color },
{ fEndX , fEndY , 0.5f, 1.0f, color },
{ fEndX , fStartY, 0.5f, 1.0f, color }
} ; // end of my_vertex g_square_vertices[]
unsigned char *vb_vertices;
if(FAILED(g_lpDevice->CreateVertexBuffer(4*sizeof(my_vertex),//Size of memory to be allocated
// Number of vertices * size of a vertex
D3DUSAGE_WRITEONLY, // We never need to read from it so
// we specify write only, it''s faster
D3D8T_CUSTOMVERTEX, // Our custom vertex specifier (coordinates & a colour)
D3DPOOL_MANAGED, // Tell DirectX to manage the memory of this resource
&g_square))) // Pointer to our triangle, after this call
// It will point to a valid vertex buffer
{
Write2Log("Failed to initialize a square") ;
} // end of if
// Now we go through the same process to fill in our VB for the square.
if(FAILED(g_square->Lock(0, //Offset, we want to start at the beginning
0, //SizeToLock, 0 means lock the whole thing
&vb_vertices, //If successful, this will point to the data in the VB
0))) //Flags, nothing special
{
Write2Log("Failed to lock Square") ;
}
memcpy(vb_vertices, g_square_vertices, sizeof(g_square_vertices)) ;
g_square->Unlock() ;
} // end of InitASquare
void CQuad::ReleaseQuad()
{
if(g_square)
{
g_square->Release() ;
g_square=NULL ;
}
} // end of ReleaseSquare()
thanx in advance for any tips