Jump to content

  • Log In with Google      Sign In   
  • Create Account


fill pixel box


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Lyev   Members   -  Reputation: 118

Like
0Likes
Like

Posted 27 May 2012 - 01:11 PM

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

Sponsor:

#2 MJP   Moderators   -  Reputation: 11010

Like
0Likes
Like

Posted 27 May 2012 - 02:33 PM

Which API are you using?

#3 Lyev   Members   -  Reputation: 118

Like
0Likes
Like

Posted 27 May 2012 - 02:39 PM

DirectX 11 and I'm on PC with VC++ 2010

#4 Adam_42   Crossbones+   -  Reputation: 2465

Like
0Likes
Like

Posted 27 May 2012 - 05:13 PM

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/

#5 MJP   Moderators   -  Reputation: 11010

Like
1Likes
Like

Posted 27 May 2012 - 05:34 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS