Original Post
Hey all,
I didn''t know what to put for the subject, so I just put that (although it probably doesn''t really imply the problem that I have.)
Anyway, I have quad class. Basically this quad class can create and draw either a flat (untextured) quad, or a textured quad. I let the programmer decide on what type they would like to create by letting them set a flag when they call the function.
Anyway, I have an if statement that checks the flag''s value (type) and then creates veticies based on that type of structure (which i have defined in a header file). However, later on when i try to lock and copy the vertices into the vertex buffer, i get a compiler error saying that my verticies are undeclared. Does that mean that variables in the if statement have a specific scope? I thought it was only for functions and such.
anyway.. here is my code:
Thanks in advance!!
¬_¬
// Init everything
HRESULT D3D_quad::Init(QUAD_TYPE type, float width, float height, float z, D3D_material * material, D3D_texture * texture){
Free();
DWORD tempFVF = 0;
if((pro_lpGMain == NULL) || (pro_lpGMain->GetDevice == NULL))
return E_FAIL;
// Find the type of quad
if(type == QUAD_TEX3D){ // Textured (3D)
// Get vertex size
pro_VertSize = sizeof(TEX3D);
// Get number of vertices
pro_NumVerts = 4 * pro_VertSize;
// Create vertices
TEX3D Verts[4] = {
{0.0f, 0.0f, z, 0.0f, 0.0f},
{width, 0.0f, z, 1.0f, 0.0f},
{0.0f, height, z, 0.0f, 1.0f},
{width, height, z, 1.0f, 1.0f}
};
// Get FVF
tempFVF = FVF_TEX3D;
}else if(type == QUAD_FLAT3D){ // Flat (no texture) (3D)
// Get vertex size
pro_VertSize = sizeof(FLAT3D);
// Get number of vertices
pro_NumVerts = 4 * pro_VertSize;
// Create vertices
FLAT3D Verts[4] = {
{0.0f, 0.0f, z},
{width, 0.0f, z},
{0.0f, height, z},
{width, height, z}
};
// Get FVF
tempFVF = FVF_FLAT3D;
}else
return E_FAIL;
// Create the vertex buffer
if(FAILED(pro_lpGMain->GetDevice()->CreateVertexBuffer(pro_NumVerts, 0, tempFVF, D3DPOOL_DEFAULT, &pro_lpVB)))
return E_FAIL;
// Lock
if(FAILED(Lock()))
return E_FAIL;
else{
// Load vertices into buffer (error occures here)
memcpy(pro_Ptr, Verts, sizeof(Verts));
// Unlock
if(FAILED(Unlock()))
return E_FAIL;
}
// Clear temp FVF, set loaded to true and set class FVF to temp FVF.
tempFVF = 0;
pro_Loaded = true;
pro_FVF = tempFVF;
return S_OK;
}