Sign in to follow this  
daviddoria

Draw a small square directly to the color buffer

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[i][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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this