Triangle instead of Rectangle C#XNA

Started by
2 comments, last by remigius 15 years, 9 months ago
Is there a way to get a triangle source from a texture and display it to a triangular destination, instead of using rectangles like the SpriteBatch class uses (in C# XNA)? Heres the parameters for the 3rd option on SpriteBatch.Draw(): SpriteBatch.Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color Color) But how can i use triangles instead of rectangles? PS: I dont want to do 3D.
Advertisement
No. SpriteBatch can only draw rectangular textures. Only way to draw something specific is to use standard drawing pipeline.
You're just going to have to get your hands dirty on this one and use the standard DrawPrimitive functions. It's really not as scary as it looks. Just use BasicEffect, and set the world and view transforms to Matrix.Identity. Set the projection to an orthographic projection whose width and height are equal to the width and height of the screen. Then if you don't want to user vertex buffers, you can just use DrawUserPrimitives and send an array of vertices. Your vertices can each be a struct containing a Vector3 (position) and a Vector2 (texture coordinate). Your positions will basically just be in screen space, except with y=0 being at the bottom of the screen. Oh and don't forget to create a vertex declaration for your vertex type, and set it before drawing.

If you really don't want delve deeper into this, can't you fake whatever you're trying to do by using an appropriate texture with everything but the triangle you want made transparent?
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!

This topic is closed to new replies.

Advertisement