Hi! I'm currently trying to build a little 2D engine with direct3D. I'm pretty new at D3D so be nice :P The problem is that i'm not getting anything on the screen. Now, I'm not going to post my whole code. But maby you guys can check out if the vertex bruffer creating code is valid.
I'm trying to create a chain of quads that can handle diffrent sizes of textures, so i have written a algorithm that generates quads with the size 2*2, 4*4, 8*8, 16*16, you get the point. nMaxExponent is the maximun exponent i'm going to use to create the biggest quats... I thing you get the rest.
some of the code inside the .h file...
//
#define VertexFormatTex (D3DFVF_XYZ | D3DFVF_TEX1)
//
struct Vertex{ Vertex(float _x, float _y, float _z,
float _v, float _u)
{ x = _x;
y = _y;
z = _z;
v = _v;
u = _u;
}
float x,
y,
z;
float u,
v;
};
//
IDirect3DVertexBuffer9* m_ppVB;
//
//-----------------------------------------------------
some of the code inside the .cpp file...
//
m_Device->CreateVertexBuffer((120 * nMaxExponent),
D3DUSAGE_WRITEONLY,
VertexFormatTex,
D3DPOOL_DEFAULT, &m_ppVB, 0);
//
Vertex* pVertices = 0;
m_ppVB->Lock(0, 0, (void**)&pVertices, 0);
//
float nExponent = 1;
//
for(unsigned int i = 0; nExponent < nMaxExponent; nExponent++, i+= 6){ //left-down
pVertices[i].x = 0;
pVertices[i].y = 0;
pVertices[i].z = 0;
pVertices[i].u = 0;
pVertices[i].v = 1;
//left-top
pVertices[i+1].x = 0;
pVertices[i+1].y = pow(2, nExponent);
pVertices[i+1].z = 0;
pVertices[i+1].u = 0;
pVertices[i+1].v = 0;
//riht-top
pVertices[i+2].x = pow(2, nExponent);
pVertices[i+2].y = pow(2, nExponent);
pVertices[i+2].z = 0;
pVertices[i+2].u = 1;
pVertices[i+2].v = 0;
//
//riht-top
pVertices[i+3].x = pow(2, nExponent);
pVertices[i+3].y = pow(2, nExponent);
pVertices[i+3].z = 0;
pVertices[i+3].u = 1;
pVertices[i+3].v = 0;
//right-down
pVertices[i+4].x = pow(2, nExponent);
pVertices[i+4].y = 0;
pVertices[i+4].z = 0;
pVertices[i+4].u = 1;
pVertices[i+4].v = 1;
//left-down
pVertices[i+5].x = 0;
pVertices[i+5].y = 0;
pVertices[i+5].z = 0;
pVertices[i+5].u = 0;
pVertices[i+5].v = 1;
}