Jump to content
  • Advertisement
Sign in to follow this  
Lyev

OpenGL fill pixel box

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

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();

Share this post


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

Share this post


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

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!