Draw a small square directly to the color buffer

Started by
2 comments, last by daviddoria 15 years, 5 months ago
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
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
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.
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

This topic is closed to new replies.

Advertisement