Jump to content
  • Advertisement
Sign in to follow this  

Problem with mesh when locking attrib, vertex buffers

This topic is 4263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
struct Vertex{
    float x, y, z, u, v;
    DWORD color;

    enum FVF{
Vertex* verts;	
int i, indicesPos;
short* indices;
short* attribs;
const int geomPos = 0;
verts = new Vertex[clump.geometryList.geometry[geomPos].vertexCount];
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;
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex1;
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex3;
    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->LockVertexBuffer(0, &data);
memcpy(data, verts, sizeof(Vertex) * clump.geometryList.geometry[geomPos].vertexCount);

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

//delete aData;
delete [] verts;
delete [] indices;
delete [] attribs;

Share this post

Link to post
Share on other sites
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]


Share this post

Link to post
Share on other sites
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.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!