Skip to main content
gamedev.net
🔒 Locked

Render rectangle problem

Started by cbichis 2 replies 450+ views
Original Post
cbichis
cbichis
Hello! I want to draw a rectangle (with fill) using DirectX 9c and I have a stupid problem... If I am using TriangleStrips or Triangles Fans it's rendered only one triangle, not two. The code is below. Do you have any suggestions ? struct VERTEX_FLAT { float x,y,z; float rhw; D3DCOLOR color; }; #define D3DFVF_FLAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE ) // define three corner vertices VERTEX_FLAT v[4]; v[0].x = 0; v[0].y = 0; v[0].color = 0xFF0000FF; // the blue corner v[1].x = 300; v[1].y = 0; v[1].color = 0xFFFF0000; // the red corner v[2].x = 300; v[2].y = 300.0; v[2].color = 0xFF00FF00; // the green corner v[3].x = 0; v[3].y = 300.0; v[3].color = 0xAA00FF00; // the green corner v[0].z = v[1].z = v[2].z = v[3].z = 0.0; // z buffer - paint over everything v[0].rhw = v[1].rhw = v[2].rhw = v[3].z = 1.0; // no perspective pd3ddev->BeginScene(); // set some render and stage states (you have to set some more, normally) pd3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE); pd3ddev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE); pd3ddev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2); // now draw the triangle pd3ddev->SetFVF(D3DFVF_FLAT); pd3ddev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,(LPVOID)v,sizeof(VERTEX_FLAT)); pd3ddev->EndScene();
Staffan E
Staffan E
You need to reorganize the vertices for them to be facing the right way and to be connected with the right neighbours.
With triangle strips you should use the sequence v0, v3, v1, v2 , and with triangle fans you should use v0, v3, v2, v1 , using the coordinates you have set for your vertices.

Regards
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Staffan E
Staffan E
Also, I saw now that when setting the rhw-values to 1.0f, you set the v[3].z to 1.0f instead of v[3].rhw. Is this the intent? Just a note.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
cbichis
cbichis
Thanks, Staff

Was a stupid mistake... My mistake was indeed "Also, I saw now that when setting the rhw-values to 1.0f, you set the v[3].z to 1.0f instead of v[3].rhw."...

Thanx again,

Best regards,
Cristian

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.