Sign in to follow this  
REspawn

Problem with mesh when locking attrib, vertex buffers

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
[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[i].color = 0xffffff00;

//mapping info
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++){
    verts[i].u = clump.geometryList.geometry[geomPos].mappinginfo[i].u;
    verts[i].v = clump.geometryList.geometry[geomPos].mappinginfo[i].v;
}
	
//vertex info
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++){
    verts[i].x = clump.geometryList.geometry[geomPos].vertexInfo[i].x;
    verts[i].y = clump.geometryList.geometry[geomPos].vertexInfo[i].y;
    verts[i].z = clump.geometryList.geometry[geomPos].vertexInfo[i].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[i].vertex2;
    indicesPos++;
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo[i].vertex1;
    indicesPos++;
    indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo[i].vertex3;
    indicesPos++;
    attribs[i] = clump.geometryList.geometry[geomPos].faceinfo[i].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]

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]

hth
Jack

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.

Cheers,
-Dave

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this