PDA

View Full Version : Clipping?



Menne
06-18-2002, 01:52 AM
I'm using OpenGL for a 2D game which supports maps up to 3200x2400 pixels. Now I wanted to create a overview bitmap of each map. I tryed it this way:

int w = pMap->GetWidth();
int h = pMap->GetHeight();

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);

pMap->Draw(); //Draw map

// Read the pixels into mem
mem = new BYTE [w * h * 3];
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, mem);

It's working but it just draw the area onto the bitmap which fits in the window. So if the window is 640x480 pixels only the botttom left of the map is drawn the rest is a dull gray. I think that OpenGL is clipping against the window (dc) boundarys, so is it possible to disable this clipping?

Sincerely,
Michael Menne

Relic
06-18-2002, 03:17 AM
The glViewport is just a transformation instruction combined into a matrix, you see this is working in the part visible in the window.
BUT, the clipping cannot be set bigger than the window you're drawing into (talking about visible onscreen area with HW accel.)
AND the "glReadPixels result of unexposed window areas is undefined" (one of my favorite spec sentences. http://www.opengl.org/discussion_boards/ubb/smile.gif).
That means you cannot read from window areas you cannot see and expect valid data (e.g. from areas overlapped by other windows, or outside the viewable desktop region.)

There are at least two solutions:
Render the overview map in multiple steps. (I've seen a "tiled rendering" source file tr.c from Bian Paul in one of the GLUT-3.7 demo folders.)

Or use a memory DC and render into a bitmap with MS software OpenGL (probably slow and features missing, and I don't know the max. supported size.)

Depending on what you're going to do with the image, you might also put it in a texture (glCopyTexSubImage2D from the tiles) and only display it?

[This message has been edited by Relic (edited 06-18-2002).]