Jump to content
  • Advertisement
Sign in to follow this  
javasirc

Triangle instead of Rectangle C#XNA

This topic is 3763 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

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.

Share this post


Link to post
Share on other sites
Advertisement
No. SpriteBatch can only draw rectangular textures. Only way to draw something specific is to use standard drawing pipeline.

Share this post


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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!