Archived

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

darkawakenings

Problem drawing Triangle Strips and with Materials

Recommended Posts

I have finally set up my directx program, and it seems to work ok exept for two major problems. I have 4 vertices in an IDirect3DVertexBuffer8 object that form a square. I have them in this order: bottem left, topleft, topright, and bottem right. When I try to draw them to the screen using a point list, (pD3DVB->DrawPrimitive(D3DPT_POINTLIST, 0, 4)), it comes out fine and all four vertex points are drawn, forming my square. When I try and draw it like a Line Strip, (pD3DVB->DrawPrimitive(D3DPT_LINESTRIP, 0, 3)), it comes out fine, with three lines forming the left, top, and right sides of my square. When i draw it as a triangle fan it comes out as a perfect square. But when I try to draw it as a triangle strip, the last vertex is completely ignored. I call it with (D3DPT_TRIANGLESTRIP, 0, 2). I know that even if that last call did work, it would not form a square, but there should still be a second triangle formed with the second, third, and fourth vertices. Instead it only draws one triangle. When I try to draw three triangles out of my vertex buffer, it draws a perfect square (oddly enough) and then another crazy triangle off the end of one side (probably just some random data in my comp. My second error is that my square has no color. I have set the render state for lighting to false, and then I set up this material: D3DMATERIAL8 d3dm; ZeroMemory(&d3dm, sizeof(d3dm)); d3dm.Diffuse.r = d3dm.Ambient.r = 1.0f; d3dm.Diffuse.g = d3dm.Ambient.g = 1.0f; d3dm.Diffuse.b = d3dm.Ambient.b = 0.0f; d3dm.Diffuse.a = d3dm.Ambient.a = 1.0f; pD3DDevice->SetMaterial(&d3dm); My vertexes do also not have a diffuse color variable, so that wont interfere. Any help would be appreciated.

Share this post


Link to post
Share on other sites
The problem with your triangle strip is that your verticies are out of order.

2--------->3
^
|
|
1

This is your first triagle, since it is draw in a ccw order, the triangle is displayed. The next triangle,

2-->3

____4
is also in a ccw order, and since every even primitive, the culling direction changes, it is not displayed. A correct order could be

1 2


3 4

Just as a test to see if this is your problem, try turning of culling off. g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ) I think.

As for you material, if Im not mistaken, I think you need a light source for materials to work.

Edit: space wont show up....

[edited by - StormArmageddon on July 27, 2003 2:38:17 AM]

Share this post


Link to post
Share on other sites
yes light is needed for materials and normals as well i believe i haven''t coded in ages though hopefully i can get my butt tryin to put some new content on nexe if i downlaod the dx9 sdk

Eric Wright o0Programmer0o




Share this post


Link to post
Share on other sites
About me needing a light source for the materials to show up, i used the following line of code which i was told would fix that:

pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

But all that did was change the color of my draw polygons to white instead of black, and the material color is yellow, (ive tried changin it to red, etc.)

Any more suggestions?


Share this post


Link to post
Share on other sites