Original Post
Hi,
just writing as I have problems locking my vertex buffer. I have used the D3DXCreateMesh command to successfully create a mesh to work from, then in attempting to obtain a pointer to the meshs'' vertex buffer with the comman below, problems arise. If I comment out the following line in my program it works fine... if I don''t comment the line out, the program attempts to start up and then drops back to the desktop (and yes I do proceed this call with an unlock directly after)
Mesh->LockVertexBuffer(D3DLOCK_DISCARD,(BYTE **)&pVB)
The program compiles successfully with or without the command yet doesnt run correctly with it. I am using memcpy just before unlocking the vertex buffer to fill it with the data I have pre-defined (a box with 16 vertices and 8 faces just to test it out). A similar problem happened previous to this and I discovered it was because I needed to pass a pointer to the class function so that it had reference to the existing device... I made the mistake of declaring a device directly inside the class function without using the one that existed, this led to exactly the same dropping back to desktop scenario.
the full function is below if needed, thanks in advance if anyone can help at all,
Steve AKA Mephs
BOOL cMap::Load(cGraphics *Graphics, ID3DXMesh *Mesh, LPDIRECT3DVERTEXBUFFER8 *pVB)
{
//LPDIRECT3DVERTEXBUFFER8 pVB;
typedef struct {
FLOAT x, y, z; // 3-D coordinates
FLOAT xn, yn, zn; // Normals
FLOAT u, v; // Texture coordinates
} sVertex2;
#define VERTEXFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)
const DWORD VERTEXFVF2 (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
// Fill the vertex buffer
sVertex2 CubeVerts[16] = {
{ -100.0f, 100.0f, -100.0f, 0.0f,0.0f,-1.0f, 0.0f,0.0f},
{ 100.0f, 100.0f, -100.0f, 0.0f,0.0f,-1.0f, 1.0f,0.0f},
{ -100.0f, -100.0f, -100.0f, 0.0f,0.0f,-1.0f, 0.0f,1.0f},
{ 100.0f, -100.0f, -100.0f, 0.0f,0.0f,-1.0f, 1.0f,1.0f},
{ 100.0f, 100.0f, -100.0f, 1.0f,0.0f,0.0f, 0.0f,0.0f},
{ 100.0f, 100.0f, 100.0f, 1.0f,0.0f,0.0f, 1.0f,0.0f},
{ 100.0f, -100.0f, -100.0f, 1.0f,0.0f,0.0f, 0.0f,1.0f},
{ 100.0f, -100.0f, 100.0f, 1.0f,0.0f,0.0f, 1.0f,1.0f},
{ 100.0f, 100.0f, 100.0f, 0.0f,0.0f,1.0f, 0.0f,0.0f},
{ -100.0f, 100.0f, 100.0f, 0.0f,0.0f,1.0f, 1.0f,0.0f},
{ 100.0f, -100.0f, 100.0f, 0.0f,0.0f,1.0f, 0.0f,1.0f},
{ -100.0f, -100.0f, 100.0f, 0.0f,0.0f,1.0f, 1.0f,1.0f},
{ -100.0f, 100.0f, 100.0f, -1.0f,0.0f,0.0f, 0.0f,0.0f},
{ -100.0f, 100.0f, -100.0f, -1.0f,0.0f,0.0f, 1.0f,0.0f},
{ -100.0f, -100.0f, 100.0f, -1.0f,0.0f,0.0f, 0.0f,1.0f},
{ -100.0f, -100.0f, -100.0f, -1.0f,0.0f,0.0f, 1.0f,1.0f}
};
D3DXCreateMesh(8,16,D3DXMESH_MANAGED,&VERTEXFVF2,Graphics->GetDeviceCOM(),&Mesh);
//Graphics->GetDeviceCOM()->CreateVertexBuffer(
// 16 * sizeof(sVertex2),
// D3DUSAGE_WRITEONLY, VERTEXFVF,
// D3DPOOL_MANAGED, &pVB);
Mesh->LockVertexBuffer(D3DLOCK_DISCARD,(BYTE **)&pVB);
memcpy(pVB,CubeVerts,sizeof(CubeVerts));
Mesh->UnlockVertexBuffer();
return TRUE;
}