Skip to main content
GameDev.net gamedev.net
🔒 Locked

fill pixel box

Started by Lyev May 27, 2012 at 7:11 PM 3 replies 1.3k views
Original Post
Lyev
Lyev
How would I go about filling a box with a given x and y and width and height up with pixels of a certain color?

I'm guessing it would involve making a new vertex buffer, but I don't know how to just fill it with a color

in opengl this could be done like:

glBegin(GL_QUADS);
glVertex2f(x,y);
glVertex2f(x,y+h);
glVertex2f(x+w,y+h);
glVertex2f(x+w,y);
glEnd();
MJP
MJP
Which API are you using?
Lyev
Lyev
DirectX 11 and I'm on PC with VC++ 2010
Adam_42
Adam_42
D3D11 makes a lot of the setup required to draw a simple box quite complicated. You need to set up the device and device context, make a vertex buffer, and compile a pixel and vertex shader.

There's some basic example code that does almost all of that in an old thread here - you just need to add a second triangle to the vertex buffer to get a rectangle instead of a triangle: http://www.gamedev.net/topic/559367-dx11-how-do-you-draw-a-triangle/
MJP
MJP
Yeah there's no immediate mode API like OpenGL...in fact OpenGL no longer has an immediate mode in the later versions. Instead you have to use shaders and/or vertex buffers and constant buffers to achieve this.

As an alternative, you can consider downloading the SpriteBatch class created by Shawn Hargreaves. Using that you could draw colored rectangle by drawing a sprite with a white texture, and specifying a tint color.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.