know how draw a triangle, but not a square

Hi,

I follow a directX tutorial to draw a triangle

http://www.riemers.net/eng/Tutorials/DirectX/C++/Series1/tut5.php

(The bottom of the webpage)

I modified the code
OURCUSTOMVERTEX cv_Vertices[3]; ==> OURCUSTOMVERTEX cv_Vertices[4];


and added
1
2
3
4
5
	 cv_Vertices[3].x = 350;
     cv_Vertices[3].y = 300;
     cv_Vertices[3].z = 0;
     cv_Vertices[3].weight = 1;
     cv_Vertices[3].color = 0xff00ffff;

I understand that is not square coordinate
However, I could not see any change. I still see a triangle after run
In DrawScene(), it is written ..->DrawPrimitive(D3DPT_TRIANGLELIST,.. this means that for every 3 vertices directx will draw a triangle, so can either add 2 more points, and have two separate triangles, or change this to D3DPT_TRIANGLESTRIP. This way dx will draw one triangle with vertices 1, 2 and 3 and the other with vertices 2, 3 and 4. Note that this way vertices should be positioned like this:
1----2
|   /|
|  / |
| /  |
|/   |
3----4


Hope this helps
Last edited on
Is there any D3DPT_SQUARELIST instead of D3DPT_TRIANGLELIST
I changed the following code, but error comes out. What mistake I made?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
          OURCUSTOMVERTEX cv_Vertices[4];
     LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer;
 
     cv_Vertices[0].x = 150;
     cv_Vertices[0].y = 100;
     cv_Vertices[0].z = 0;
     cv_Vertices[0].weight = 1;
     cv_Vertices[0].color = 0xffff0000;
 
     cv_Vertices[1].x = 350;
     cv_Vertices[1].y = 100;
     cv_Vertices[1].z = 0;
     cv_Vertices[1].weight = 1;
     cv_Vertices[1].color = 0xff00ff00;
 
     cv_Vertices[2].x = 250;
     cv_Vertices[2].y = 300;
     cv_Vertices[2].z = 0;
     cv_Vertices[2].weight = 1;
     cv_Vertices[2].color = 0xff00ffff;

     cv_Vertices[3].x = 270;
     cv_Vertices[3].y = 210;
     cv_Vertices[3].z = 0;
     cv_Vertices[3].weight = 1;
     cv_Vertices[3].color = 0xff00ffff;


p_dx_Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);
1. There is no D3DPT_SQUARELIST as far as I know, though there is something like that in OpenGL. Overall I prfer how drawing stuff works in gl. Just glBegin(), name the vertices and glEnd(). Way cleaner.
2. What error?
3. HRESULT DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount); You primitive count should be 2, since you're drawing 2 triangles.
DirectX only works with triangles because they are the simplest possible polygon to work with. You are guaranteed that any given triangle, no matter how it's defined, will reside in a single plane.

It is, however, possible to incorrectly define a quad that does not fully reside within a single plane (and by single plane, I'm not referring to the X, Y, or Z planes, but any arbitrary plane). You'll find many 3D rendering application that can work with quads, but the applications themselves generate the quads, and prevent the user from creating invalid quads. converting all these quads to pairs of triangles is one of the things that typically occurs when a 3D model is 'imported' into a format to be used by DirectX.

Looking at your point list, it's most definitely not a proper quad, and looks like it is probably an invalid triangle strip. Your last point resides inside the triangle created by your first three points. I'm not sure how DirectX handles that situation, but it is invalid and, at the very least, won't render properly.
Topic archived. No new replies allowed.