PDA

View Full Version : pbuffer glDrawPixels gl_Bend errors



Ian2004
04-19-2007, 10:56 AM
Hi

I'm trying to use a pBuffer to render some 2000x2000 pixel images off screen as to save them to file. I'm trying to use pBuffer to create some composite images containing two overlaid images and some OpenGL geometric primitives.

I have two registered images overlaid, I draw the first image into the pbuffer, then the second with 50% transparency.

The problem is when I read the result of glReadPixels back from file I only ever see the first image which was rendered. Even if the second image has no transparency, it sill doesn't show.


Any ideas?

Many Thanks



void CreatePBuffer()
{
int pf_attr[] =
{
WGL_SUPPORT_OPENGL_ARB, TRUE, WGL_DRAW_TO_PBUFFER_ARB, TRUE,
WGL_RED_BITS_ARB, 8, WGL_GREEN_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24, WGL_DOUBLE_BUFFER_ARB, FALSE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_TRANSPARENT_ARB, TRUE,
0
};

unsigned int count = 0;
int pixelFormat;

wglChoosePixelFormatARB( *g_hDC,(const int*)pf_attr, NULL, 1, &pixelFormat, &count);



g_pbuffer.hPBuffer = wglCreatePbufferARB( *g_hDC, pixelFormat, g_pbuffer.nWidth, g_pbuffer.nHeight, NULL );
g_pbuffer.hDC = wglGetPbufferDCARB( g_pbuffer.hPBuffer );
g_pbuffer.hRC = wglCreateContext( g_pbuffer.hDC );



glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); //draw alpha info to screen

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho(0.0f,width - 1.0,0.0,height -1.0,10,-10);


}


void Rende()
{

glPixelZoom(1.0,1.0);
glRasterPos2i(0,0);
currentImage->drawPixelImage(); //calls glDrawPixels twice
glFlush();

glReadPixels( 0, 0, image->GetWidth(),image->GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image->pixels );
SaveImage((char*)filename.c_str(),image,FIF_JPEG,J PEG_QUALITYSUPERB)
}

Relic
04-19-2007, 11:10 AM
This should be the culprit: glEnable(GL_DEPTH_TEST);
glDrawPixels uses the current glRasterPos values to generate colors or depth data depending on what pixel vector component you draw.
glRasterPos2i(0,0); // Both glDrawPixels at z == 0 and default depth func is GL_LESS.
And without glClear on the depth buffer the result is undefined.
Just switch depth test off during the two glDrawPixels.

The glFlush is not needed, glReadPixels must have an implicit finish anyway.

Ian2004
04-19-2007, 01:34 PM
Works perfectly now

Many Thanks