glReadPixels

Hi all -

What I need to do is make a thumbnail of an opengl window image for when the window is not the foregroud window. I have it being rendered to the back buffer because if I do a SwapBuffers the image I want is there and in the bottom left corner and in the size I need. But glReadPixels just does not seem to work.

I am not concerned about performance issues at this time. When the window is not the foreground window the image will be fairly static. I just need to put a thumbnail up in a different window.

Thanks.

  • Brian

What’s not working when you try using glReadPixels? Can you post some code?

It just comes out gray. I can post the source code tomorrow. Sorry about the cross post.

Heres the relevant code snippets …

void C3DRender::RenderToBitmap(void *bits)
{
// without FBO
// render to the backbuffer and copy the backbuffer to a texture

// clear buffer
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT); // for GL_DRAW_BUFFER and GL_READ_BUFFER
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);

// draw a rotating teapot at the origin
glPushMatrix();

// Draw here
SetSize(280, 210);
oglDrawScene();
glFlush();
// copy the frame buffer pixels to our bitmap
glReadPixels(0, 0, 280, 210, GL_RGBA, GL_UNSIGNED_BYTE, bits);
GLenum error = glGetError();
SetSize(m_cx, m_cy);

glPopMatrix();

// copy the framebuffer pixels to a texture

glPopAttrib(); // GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT

//SwapBuffers(hScreendc);
}

It gets called from this code snippet …

HBITMAP small_bitmap;
void *bits = malloc(280 * 210 * 4);
pRender->RenderToBitmap(bits);
small_bitmap = CreateBitmap(280, 210, 1, 24, bits);
m_wndDro.m_VideoWindow.SetBitmap(small_bitmap);
//free(bits);

here the code

void C3DRender::RenderToBitmap(void *bits)
{
// without FBO
// render to the backbuffer and copy the backbuffer to a texture

// clear buffer
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT); // for GL_DRAW_BUFFER and GL_READ_BUFFER
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);

// draw a rotating teapot at the origin
glPushMatrix();

// Draw here
SetSize(280, 210);
oglDrawScene();
glFlush();
// copy the frame buffer pixels to our bitmap
glReadPixels(0, 0, 280, 210, GL_RGBA, GL_UNSIGNED_BYTE, bits);
GLenum error = glGetError();
SetSize(m_cx, m_cy);

 glPopMatrix();

// copy the framebuffer pixels to a texture

glPopAttrib(); // GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
//SwapBuffers(hScreendc);

}

It gets called from here …
HBITMAP small_bitmap;
void *bits = malloc(280 * 210 * 4);
pRender->RenderToBitmap(bits);
small_bitmap = CreateBitmap(282, 210, 1, 24, bits);
m_wndDro.m_VideoWindow.SetBitmap(small_bitmap);
//free(bits);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.