Problem with mesh when locking attrib, vertex buffers

Started by
1 comment, last by REspawn 17 years ago
Hi, im making the move from managed dx to proper dx with c++ and I have run into a bit of trouble when it comes to turning the mesh data I have read in into a proper mesh. Im sure the problem is at the final level where i lock the buffers and copy in the data because all the attributes, vertexs and indices are correct. Bellow is the mesh create code and the vertex structure im using, any help or a point in the right direction would be excellent. Cheers, -Dave Vertex Struct
[SOURCE]
struct Vertex{
    float x, y, z, u, v;
    DWORD color;

    enum FVF{
        FVF_Flags = D3DFVF_XYZ | D3DFVF_TEX2 | D3DFVF_DIFFUSE 
    };
};
[/SOURCE]
[SOURCE]
Vertex* verts;	
int i, indicesPos;
short* indices;
short* attribs;
const int geomPos = 0;
		
verts = new Vertex[clump.geometryList.geometry[geomPos].vertexCount];
	
//color
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++)
    verts.color = 0xffffff00;

//mapping info
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++){
    verts.u = clump.geometryList.geometry[geomPos].mappinginfo.u;
    verts.v = clump.geometryList.geometry[geomPos].mappinginfo.v;
}
	
//vertex info
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++){
    verts.x = clump.geometryList.geometry[geomPos].vertexInfo.x;
    verts.y = clump.geometryList.geometry[geomPos].vertexInfo.y;
    verts.z = clump.geometryList.geometry[geomPos].vertexInfo.z;
}
	
//indices & attributes
indices = new short[clump.geometryList.geometry[geomPos].triangleCount * 3];
attribs = new short[clump.geometryList.geometry[geomPos].triangleCount];

indicesPos = 0;
for(i=0; i<clump.geometryList.geometry->triangleCount; i++){
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex2;
    indicesPos++;
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex1;
    indicesPos++;
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex3;
    indicesPos++;
    attribs = clump.geometryList.geometry[geomPos].faceinfo.flags;
}

D3DXCreateMeshFVF(clump.geometryList.geometry[geomPos].materialsplit.faceCount, clump.geometryList.geometry[geomPos].vertexCount, D3DXMESH_MANAGED, Vertex::FVF_Flags, *ptrDevice, &clump.geometryList.geometry[geomPos].mesh);

LPVOID data;
DWORD* aData;

clump.geometryList.geometry[geomPos].mesh->LockIndexBuffer(0, &data);
memcpy(data, indices, 2 * (clump.geometryList.geometry[geomPos].triangleCount * 3));
clump.geometryList.geometry[geomPos].mesh->UnlockIndexBuffer();

clump.geometryList.geometry[geomPos].mesh->LockVertexBuffer(0, &data);
memcpy(data, verts, sizeof(Vertex) * clump.geometryList.geometry[geomPos].vertexCount);
clump.geometryList.geometry[geomPos].mesh->UnlockVertexBuffer();

clump.geometryList.geometry[geomPos].mesh->LockAttributeBuffer(0, &aData);
memcpy(aData, attribs, 2 * clump.geometryList.geometry[geomPos].triangleCount);
clump.geometryList.geometry[geomPos].mesh->UnlockAttributeBuffer();

//delete aData;
delete [] verts;
delete [] indices;
delete [] attribs;
[/SOURCE]
Advertisement
hmm, so whats your problem then?! You haven't really described what your error is - how and when it appears etc...?

You're not checking HRESULT return codes.

Are you getting any debug output from the runtimes - is it warning you about something you should(n't) be doing?

You don't seem to be filling the attribute table, only the buffer.

Your FVF contains D3DFVF_TEX2 when the data only uses D3DFVF_TEX1 which could cause you problems [wink]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Cheers for the reply jollyjeffers,
when I run the app its polys all over the place like this.. http://img220.imageshack.us/img220/2084/polysoupuz6.jpg

I changed the TEX2 to TEX2 and put in HRESULTS, all of which came back ok.

You think the problem is the attribute table, im just looking up how to fill one in now, never had to do that in the managed code.

Cheers,
-Dave

This topic is closed to new replies.

Advertisement