Jump to content
  • Advertisement
Sign in to follow this  

[Solved] - Colored rectangle

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

Sorry, this is a kind of basic question. I just want to draw a colored rectangle to the screen and am kind of confused of what vertex format I need. Here is what I got so far..
[source = "csharp"]
    public struct Rectangle
    {   // I figure all I would need is a vector and a color right?
        public Vector3 v;
        public int c;

r[0].v = new Vector3(0, 0, 5); 
background[0].c = Color.Turquoise.ToArgb();
r[1].v = new Vector3(0, 100, 5); 
background[1].c = Color.Tomato.ToArgb();
r[2].v = new Vector3(100, 100, 5); 
background[2].c = Color.YellowGreen.ToArgb();
r[3].v = new Vector3(100, 0, 5); 
background[3].c = Color.Yellow.ToArgb();

Graphics.device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse; 
Graphics.device.DrawUserPrimitives<Rectangle>(PrimitiveType.TriangleStrip, 2, r);

I check in PIX and the vector and color is filled with correct information and it appears to be drawing correctly but I do not see it. I think I am using wrong format. Edit - Sorry, i dunno why but I see it now [Edited by - Meowza on February 22, 2010 11:55:13 AM]

Share this post

Link to post
Share on other sites
Could be that your rectangle is viewed from behind and is culled away. Also make sure it's actually in front of the camera. PIX should be able to tell you this too, look at the post-VS values.
GraphicsDevice.RenderState.CullMode = CullMode.None;

EDIT: I thought of XNA, which you don't seem to be using, but it's probably named the same.
However you're probably right about the vertex format, try PositionW instead of just Position if you're trying to draw in screen coordinates.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!