Jump to content
  • Advertisement
Sign in to follow this  
daviddoria

Draw a small square directly to the color buffer

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

I just want to draw a small square so that I can easily see where the middle of the window is. I tried this: glRasterPos2i(Width/2, Height/2); #define num 20 unsigned char pixels[num][num]; for(int i = 0; i < num; i++) { for(int j = 0; j < num; j++) { pixels[j] = 200; } } glDrawPixels(num,num, GL_RGBA, GL_UNSIGNED_BYTE, pixels); But nothing is drawn. Is there anyway to do this - ie. draw to a specific window coordinate instead of having to deal with the projection/modelview matrix and making an actual 3d object and hoping it gets projected to the right place? Thanks, Dave

Share this post


Link to post
Share on other sites
Advertisement
Not exactly what I wanted because then I have to do more keeping track of the projection/modelview matrix, but this gets the job done.

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0f,Width,0.0f,Height,-10,100);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glRasterPos2i(Width/2, Height/2);
glDrawPixels(num,num, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

Is there a way to say "no matter the state of the projection/modelview matrices, draw to these pixels in window coordinates"?

Dave

Share this post


Link to post
Share on other sites
Use glWindowPos rather then glRasterPos, as it is not translated by matrices. Also you're setting the format and type as GL_RGBA/GL_USIGNED_BYTE, that is 4 bytes for each pixel(R,G,B,A), while your 'pixels' are only 1 byte for each pixel. If you want to keep the data like that and use the same value for R,G,B, you can pass GL_LUMINANCE as format, instead of GL_RGBA.

Share this post


Link to post
Share on other sites
great - glwindowpos looks like what I was looking for. I did realize that I was not passing good (full) values to the RGBA parameter, but that didn't particularly matter for my application, but thanks for pointing out GL_LUMINANCE.

Thanks again!

Dave

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!