Reputation: 31
I have a problem when trying to display two images on OpenGL (Stereo Enabled with PFD_STEREO). When I try to display 2 images in the same time but, only one(last) image that's displayed and another image only shows black-color(image not shown).
Here's the code:
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
GLuint leftImage,rightImage;
// register window class
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass( &wc );
// create main window
hWnd = CreateWindow( "GLSample", "OpenGL Texture Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 800, 600,
NULL, NULL, hInstance, NULL );
// enable OpenGL for the window
EnableOpenGL( hWnd, &hDC, &hRC );
// load our texture
leftImage = LoadTexture( "left0000.bmp", TRUE );
rightImage= LoadTexture( "right0000.bmp", TRUE );
// program main loop
while ( !bQuit ) {
// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
// handle or dispatch messages
if ( msg.message == WM_QUIT )
{
bQuit = TRUE;
}
else
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT);
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT);
// setup texture mapping
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, leftImage );
glPushMatrix();
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glBindTexture( GL_TEXTURE_2D, rightImage );
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glPopMatrix();
glDisable( GL_TEXTURE_2D );
SwapBuffers( hDC );
}
}
// free the texture
FreeTexture( leftImage );
FreeTexture( rightImage );
// shutdown OpenGL
DisableOpenGL( hWnd, hDC, hRC );
// destroy the window explicitly
DestroyWindow( hWnd );
return msg.wParam;
As long i've tried, i'm sure the code doesn't work well at here:
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT);
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT);
// setup texture mapping
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, leftImage );
glPushMatrix();
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glBindTexture( GL_TEXTURE_2D, rightImage );
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glPopMatrix();
glDisable( GL_TEXTURE_2D );
SwapBuffers( hDC );
Upvotes: 0
Views: 696
Reputation: 162317
Did you check that the pixelformat actually chosen does support stereo? Unfortunately, due to political/marketing and not technical reasons, consumer grade GPUs from both NVidia and AMD don't support quadbuffer stereo. So it's likely that the pixelformat you got back doesn't support it as well. Hence the right eye framebuffer won't be available in that case.
In addition to that: Where do you set in which framebuffer you want to actually render?
It should look something like this:
glDrawBuffer(GL_BACK); // <<<< enable both back buffers for clearing
glClear(GL_COLOR_BUFFER_BIT);
// setup texture mapping
glEnable( GL_TEXTURE_2D );
glPushMatrix();
glBindTexture( GL_TEXTURE_2D, leftImage );
glDrawBuffer(GL_BACK_LEFT); // <<<< enable left back buffer to draw left image to
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glBindTexture( GL_TEXTURE_2D, rightImage );
glDrawBuffer(GL_BACK_RIGHT); // <<<< enable left back buffer to draw right image to
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glPopMatrix();
glDisable( GL_TEXTURE_2D );
SwapBuffers( hDC );
Upvotes: 3