fill pixel box

Started by
3 comments, last by MJP 11 years, 11 months ago
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();
Advertisement
Which API are you using?
DirectX 11 and I'm on PC with VC++ 2010
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/
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.

This topic is closed to new replies.

Advertisement