Drawing squares in DirectX 8

Started by
3 comments, last by emulti 20 years, 10 months ago
Complete beginner here. I have been able to create triangles using vertices and would now like to move on to creating squares and apply a texture to it to display a 2d image. So far I have a transformed lit vertex to work with and attempting to use DrawPrimitive with this to display a square. The image I get is a triangle, not surprisingly, with two sides using two of the vertices in the square I have described. The other sides go off to the second vertex of a triangle I had already drawn next to it. So questions: 1. Should I be using DrawPrimitive or DrawPrimitiveUP? 2. Should I specifying more triangles to be drawn? 3. Does it sound like I have my square vertices in the wrong order? 4. Is there a common method for drawing squares from vertices? Any advice on this would be much appreciated.
"What do you make of it Spock?""It's programming Jim but not as we know it."
Advertisement
a square = two triangles

You can always make a class to make it simpler, though. Although I am a relatively new to directX, I know that you cannot render a square per say. You need to render 2 triangles.

-Unsuspected
-Unsuspected
This is certainly true.

I have just realized that I am a simpleton. I rechecked my y co-ordinates and they were out by 200 pixels. I now have a white square where there was just a black void before.

I am using DrawPrimitive with D3DPT_TRIANGLEFAN and 4 for PrimitiveCount. Can anybody tell me why TRIANGLEFAN only gives me the original triangle and one mirror image. I read in the help that it should fan mirror images on all sides of the original triangle. Perhaps I have mis-understood this. I guess I would have to supply more vertices to get this effect. But a square is good enough for me right now.

"What do you make of it Spock?""It's programming Jim but not as we know it."
Just found out I only need 2 for PrimitiveCount because I am only drawing two triangles with TRIANGLEFAN.
"What do you make of it Spock?""It's programming Jim but not as we know it."
There are much more effective ways to draw a cube w/o using triangle fan.
I suggest "The Zen of Direct3D Game Programming."
It does a great job explaining DirectX and 3D programming!

-Unsuspected
-Unsuspected

This topic is closed to new replies.

Advertisement