Sign in to follow this  

[Solved] - Colored rectangle

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this