I'm working on a simple program where I start by initializing an array of VertexPos structures that each carry an XMFLOAT3 and XMFLOAT2 inside the cube's constructor. Then, the RenderCube function reads these vertices and displays the cube to the screen.
The code I have works perfectly fine when I declare an array (of the same type) within the RenderCube function like so:
VertexPos vertices[] = {
{XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT2( 0.0f, 0.0f )},
...
Problem is, when I attempt to read vertices[] from the cube object, defined and initialized below (Only the first vertex of the cube is defined below for brevity), I see crazy values in the debugger when looking at cube->vertices, such as:
cube->vertices[0].pos.x=5.736e-039#DEN
RenderCube():
bool Render::RenderCube(Cube* cube)
{
...
D3D11_SUBRESOURCE_DATA resourceData;
ZeroMemory(&resourceData, sizeof(resourceData));
resourceData.pSysMem = cube->vertices;
}
Cube.h
struct VertexPos
{
XMFLOAT3 pos;
XMFLOAT2 tex0;
VertexPos(){}
VertexPos(XMFLOAT3 p, XMFLOAT2 t)
{
pos = p;
tex0 = t;
}
};
class Cube
{
public:
Cube::Cube(LPCWSTR textureFileName);
VertexPos vertices[NUMBER_OF_VERTICES];
LPCWSTR getTextureFileName();
private:
LPCWSTR textureFileName;
};
Cube.cpp:
Cube::Cube(LPCWSTR textureFileName)
{
//set texture
this->textureFileName = textureFileName;
vertices[0] = VertexPos(XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT2( 0.0f, 0.0f ));
}
LPCWSTR Cube::getTextureFileName(){
return textureFileName;
}
What am I doing wrong?