Archived

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

Drawing squares in DirectX 8

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites