Original Post
Today is my third day getting down and dirty with Direct Graphics, which I think is an odd name since in the SDK demos they use Direct Draw 7 and Direct3D8. Anywho, I''m trying to figure out how I can render a scene using an object oriented approach, like I did when I would blit stuff in DDraw. So I wrote a class that has a draw() function, and I am calling it after I invoke BeginScene(). But my problem is that I''m getting an error from the VC++ debugger saying that "Streams do not have required number of vertices... DrawPrimitive failed." So I figured I would play around with the number of primitives I specified in DrawPrimitive() but I''ve been unable to get anything to work! So I''ve included the code for my class below, if anyone knows whats wrong with it please let me know! Also, I''ve been searching around for about a month or so looking for good tutorials and books on Direct Graphics. I found nexe, with the help of gamedev but thats about it. So if anyone knows of any good books or sites on Direct X 8 or Direct Graphics share them!
BTW, the Draw function is where the problem is I think.
Here''s my code:
- Clash
- www.zeroinfinity.net
- A New World, Built By New Minds
// The Flexible Vertex Format Constant
// We are specifying XYZ coords and a diffuse color
const DWORD FVFCPoint = D3DFVF_XYZ | D3DFVF_DIFFUSE;
const DWORD FVFCProcessedPoint = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
// Holds the coords and color of a vertex
class CPoint {
public:
float x, // X coord
y, // Y coord
z; // Z coord
DWORD dwColor; // Color
// A helper function for filling in class members
void Init(float fX, float fY, float fZ, float fR, float fG, float fB)
{
// Fill in our coords
x = fX;
y = fY;
z = fZ;
// Convert the arguments from % of 255 to an actual value
// Then get D3D to convert it into a color value
dwColor = D3DCOLOR_XRGB(BYTE(fR * 255), BYTE(fG * 255), BYTE(fB * 255));
}
};
// Holds the coords of a processed point
class CProcessedPoint {
public:
float x, // X coord
y, // Y coord
z, // Z coord
RHW;
DWORD dwColor; // Color
};
class C3DRect {
public:
C3DRect(IDirect3DDevice8** D3DDevice)
{
// get our D3D Device
myD3DDevice = *D3DDevice;
// Create our vertex buffer
myD3DDevice->CreateVertexBuffer(sizeof(CPoint) * 8, NULL, FVFCPoint, D3DPOOL_MANAGED, &myBuffer);
// Create our processed vertex buffer
myD3DDevice->CreateVertexBuffer(sizeof(CProcessedPoint) * 8, NULL, FVFCProcessedPoint, D3DPOOL_MANAGED, &myProcessedBuffer);
// Set our initialization value to false
init = false;
}
// Destructor
~C3DRect()
{
SafeRelease(myBuffer);
SafeRelease(myProcessedBuffer);
}
//------------------------------------------
//Name: SetPoints
//Desc: Sets the internal variables of the C3DRect class
//------------------------------------------
void SetPoints(float nx, float ny, float nz, float nheight, float nwidth, float ndepth)
{
x = nx;
y = ny;
z = nz;
height = nheight;
width = nwidth;
depth = ndepth;
myBuffer->Lock(0, 0, (BYTE**) &myVertices, NULL);
myVertices[0].Init(x, y, z, .80, .80, .80);
myVertices[1].Init(x, y + height, z, .80, .80, .80);
myVertices[2].Init(x, y, z + depth, .80, .80, .80);
myVertices[3].Init(x, y + height, z + depth, .80, .80, .80);
myVertices[4].Init(x + width, y , z + depth, .80, .80, .80);
myVertices[5].Init(x + width, y + height, z + depth, .80, .80, .80);
myVertices[6].Init(x + width, y, z , .80, .80, .80);
myVertices[7].Init(x + width, y + height, z , .80, .80, .80);
myBuffer->Unlock();
init = true;
}
// Change the internal D3D Device
void setD3DDevice(IDirect3DDevice8* D3DDevice)
{
myD3DDevice = D3DDevice;
}
// Draw me!
void Draw()
{
if(!init)
return;
// Tell it which buffer we are using
myD3DDevice->SetStreamSource(0, myBuffer, sizeof(CPoint));
// Give it out FVF
myD3DDevice->SetVertexShader(FVFCPoint);
// Do some D3D Voodoo (ehh????)
myD3DDevice->ProcessVertices(0, 0, 8, myProcessedBuffer, NULL);
//myD3DDevice->SetTexture() NOT YET! hehe
// Set the new buffer we are working with
myD3DDevice->SetStreamSource(0, myProcessedBuffer, sizeof(CProcessedPoint));
// Give it out new FVF
myD3DDevice->SetVertexShader(FVFCProcessedPoint);
// Render the rectangle
myD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 8);
}
private:
float x,
y,
z,
height, // object properties
width,
depth;
bool init;
IDirect3DDevice8 *myD3DDevice; //inter d3d device
IDirect3DVertexBuffer8 *myBuffer; //our vertex buffer
IDirect3DVertexBuffer8 *myProcessedBuffer; //our vertex buffer
CPoint *myVertices; //our vertex info
};
|