#### Archived

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

# DX8 VBuffer...only one object can be drawn...

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

## Recommended Posts

I know this is kinda vague. Has anyone ever had troubles where, they fill the vertex buffer with objects, and then make calls to DrawPrimitive() for several items, providing the correct starting vertex, and number of primitives, but have only the first object in the buffer be drawn *several* times? This is happening to me and I have no clue why. for each object I run through: D3DDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); D3DDevice->SetStreamSource(0, subVertexBuffer, VertexSize); D3DDevice->SetVertexShader(FVF); D3DDevice->DrawPrimitive(PrimitiveType, StartVertex, PrimitiveCount); StartVertex, and PrimitiveCount are correct (I''ve tried just entering numbers manually). Yet, the first object in the buffer is the only one drawn and it''s drawn several times (once for each object) (rotated correctly for that object). Does anyone know what I''m doing wrong. This is driving me crazy... Thanks in advance. --Ben d e e p s k y . s 5 . c o m "If builders made buildings the way programmers write programs, then the first woodpecker to come along would destroy civilization." -Weinberg''s Law

##### Share on other sites
There is only two possibilities, either the value of StartVertex is wrong, in other words it's not being increased after each DrawPrimitive call, or the contents of your VB are not what you intended, which is extrememly unlikely.

Which means almost definitely the problem is with StartVertex. Use the debugger and manually check your values for StartVertex at each DrawPrimitive call.

EDIT: Why is the VB pointer called subVertexBuffer? Have you set up pointers to sub-sections of your VB or something? Maybe this is the problem, you think subVertexBuffer points to a particular part of the VB when actually it still points to vertex 0. Just a thought...

Edited by - simon_brown75 on April 22, 2001 11:13:07 PM

##### Share on other sites
That''s why this problem seems so messed up. I''m manually put in numbers in place of StartVertex for each object without any luck. The problem still persists.

subVertexBuffer is a LPDIRECT3DVERTEXBUFFER8. It''s stored within an individual object class and points to the actual vertex buffer. This just allows the object to render itself.

I also thought the problem could be VB contents, and I changed a few things here and there without any success. Here''s my InitGeometry code though if it clarifies things:

  CUSTOMVERTEX *vertices;WGE.CreateVertexBuffer(20000, sizeof(CUSTOMVERTEX), D3DFVF_CUSTOMVERTEX, &VertexBuffer);WGE.LockVBuffer(&VertexBuffer, (BYTE**)&vertices);//WGE is my d3d class LockBuffer is this://void GameFrame::LockVBuffer(const LPDIRECT3DVERTEXBUFFER8 *vbuffer, BYTE **vertices)//{// /*Confirm is just an assert macro I use*/// Confirm( D3D_OK == (*vbuffer)->Lock(0, 0, vertices, 0) );//}int count = 0;for(int i=0; i<362; i+=2){ vertices[i].position.x = 2 * COS360(i); vertices[i].position.y = SIN360(i); vertices[i].position.z = 4.0f; vertices[i+1].position.x = 2 * COS360(i); vertices[i+1].position.y = SIN360(i); vertices[i+1].position.z = -4.0f; if(count <= 8) { vertices[i].diffuse = D3DCOLOR_ARGB(0, 0, 140, 0); vertices[i+1].diffuse = D3DCOLOR_ARGB(0, 200, 0, 0); } else { vertices[i].diffuse = D3DCOLOR_ARGB(0, 40, 0, 100); vertices[i+1].diffuse = D3DCOLOR_ARGB(0, 100, 0, 100); } count++; if(count > 16) count = 0;}WGE.UnlockVBuffer(&VertexBuffer);Cylinder.InitObject(VertexBuffer, sizeof(CUSTOMVERTEX), D3DFVF_CUSTOMVERTEX, 0, 360, D3DPT_TRIANGLEFAN);

This creates an elliptical cylinder. if I add another shape into the vertices following the cylinder and try to render it, the cylinder (or a portion of it) is drawn instead.

Whenever stuff like this happens It''s usually something stupid I did, but after staring at my code for way too long, I''m starting to go nuts.

Thanks a lot.
--Ben

d e e p s k y . s 5 . c o m

"If builders made buildings the way programmers write
programs, then the first woodpecker to come along would
destroy civilization." -Weinberg''s Law

##### Share on other sites
I can''t see anything wrong with that code.

Check your CreateVertexBuffer function (I presume this is your own function) and when adding a new object to the VB, check you''re adding it at the right place.

Actually, thinking about it, I don''t think errors in those areas would lead to the problems you describe. If you were adding your new objects at the wrong place, it''d overwrite the cylinder, and if you were drawing from a part of the VB filled with garbage, most likely you wouldn''t be getting anything drawn.

Obviously when you add a new object to the VB, you are storing how many vertices are in it, maybe you are accidentally storing the primitive count instead?

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002324
×