Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Vulc777

Something wrong with index buffer

This topic is 5741 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

Ok, i can't found bug, in my index buffer, when i render through DrawPrimitiveUP and pass my indiex and vertex lists it is work, but when i try to tender through index buffer, it is not work. I try to debug index and vertex buffers, when i render my model through vertex buffer and D3DPT_POINTLIST all is ok, but when i render from vertex buffer with indices something wrong, this is my code: For j=0 all TotalMeshes Indices += TotalFaces[j]; RenderDevice->CreateIndexBuffer(Indices*sizeof(unsigned short)*3 , D3DUSAGE_DYNAMIC,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&IndexBuffer); void *pIndices; i=0; For j=0 all TotalMeshes{ IndexBuffer->Lock(i,sizeof(unsigned short)*TotalFaces[j]*3,(BYTE**)&pIndices,0); memcpy(pIndices,Index[j],sizeof(unsigned short)*TotalFaces[j]*3); IndexBuffer->Unlock(); i+=sizeof(unsigned short)*TotalFaces[j]*3; } TotalMeshes - total models, TotalFaces[j] - total faces in my sub model, Index[j] - indices of my sub model, i multiply TotalFaces[j] by 3 cause face has A,B,C vertices. [edited by - Vulc777 on February 1, 2003 7:29:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
Enable the debug runtime, turn up the ouput level in the control panel and run your code again. The debug output window should contain details of any problems.

Unfortunately we need more information than "when I render from vertex buffer with indices something wrong"

WHAT is wrong - can you show us a screenshot?, can you show us a simple part of your data?, can you show us the exact error message? or crash you get?... etc

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Ok, here is my problem. I have some structures which include information about my model(s), i have array of structures, and the number of structures is “TotalMeshes”. This structure is
Typedef struct{
D3DVECTOR vector; //Vertex vector;
D3DCOLOR diffuse; //Vertex color;
FLOAT u, v; //Mapping coordinates;
}D3DVERTEX;
When I’ve read this information from 3ds, then I’ve create vertex and index buffer:
TotalFaces[j]– total faces of the j model; type unsigned long;
Total[j]- total vertices of the j model; type unsigned long;
i,j- counters; type unsigned long;
Vertex[j]- array of j model of vertices; type float;
Index[j]- array of j model of indices; type unsigned short;(WORD)

//Calculate total faces;
for(j=0; j//Create index buffer;
RenderDevice->CreateIndexBuffer(Indices*sizeof(WORD)*3,
D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&IndexBuffer);

//Calculate total vertices;
for(j=0; j//Create vertex buffer;
RenderDevice->CreateVertexBuffer(Vertices*sizeof(D3DVERTEX),
0,D3DFVF_VERTEX,D3DPOOL_DEFAULT,&VertexBuffer);

VOID *pIndices,*pVertices;

//Then i put all information to my buffers(index and vertex buffer);
for(j=0,i=0; j buffer(by pieces);
IndexBuffer->Lock(i,sizeof(WORD)*TotalFaces[j]*3,(BYTE**)
&pIndices,0);
memcpy((VOID*)pIndices,(VOID*)Index[j],
sizeof(WORD)*TotalFaces[j]*3);
IndexBuffer->Unlock();
i+=sizeof(WORD)*TotalFaces[j]*3;//To the next memory block;
}

for(j=0,i=0; j buffer(by pieces);
VertexBuffer->Lock(i,Total[j]*sizeof(D3DVERTEX),(BYTE**)
&pVertices,0);
memcpy((VOID*)pVertices,(VOID*)Mesh[j],
sizeof(D3DVERTEX)*Total[j]);
VertexBuffer->Unlock();
i+=sizeof(D3DVERTEX)*Total[j];//To the next memory block;
}
Then i call my procedure render();
RenderDevice->BeginScene();
RenderDevice->SetVertexShader(D3DFVF_VERTEX);
RenderDevice->SetStreamSource(0,VertexBuffer,
sizeof(D3DVERTEX));
RenderDevice->SetIndices(IndexBuffer,0);

RenderDevice->SetTexture(0,Texture);
RenderDevice->DrawPrimitive(D3DPT_POINTLIST,0,Vertices); (1)
//When I call that method (1) all vertices are read from vertex
//buffer well;
RenderDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,
Vertices,0,Indices);(2)
//When I call that method (2) all vertices are read bad (first
//model render and other models are not rendered)
//There is one interesting thing when model contains a lot of
//vertices and faces, I didn’t see it.
//Even if render with (1) method
//This method (3) render through arrays and work well for all
//model(s), even if the model contains a lot of submodels.
for(int j=0; j RenderDevice->DrawIndexedPrimitiveUP (D3DPT_TRIANGLELIST,0,
Total[j],TotalFaces[j],
Index[j],D3DFMT_INDEX16,Mesh[j],
sizeof(D3DVERTEX));(3)
RenderDevice->SetTexture(0,NULL);
RenderDevice->EndScene();
RenderDevice->Present(0,0,0,0);
RenderDevice->EndScene();

I don’t understand where is the bug, I locked entire index and vertex buffer, and tested every byte and every byte same as in the arrays, what’s the problem I need your help, I can’t find this bug, maybe someone can help me. Thanks.

Share this post


Link to post
Share on other sites
And one more question, if you know how 3ds stores vertex ambient, diffuse and specualar component of the color. I know that chunks, but chunk lenght only 15 bytes. Does it store information only in one byte? It''s not so interesting for me now like problem with index buffer, and prbably with vertex buffer.....

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!