PDA

View Full Version : Back right buffer problem?



Darren Taylor
05-01-2007, 08:50 AM
Hi,

I'm trying to draw something to the GL_BACK_RIGHT buffer, but for some reason it keeps going to my GL_BACK buffer instead - is this right?

I'm drawing a black square to GL_BACK_RIGHT, and an orange one to GL_BACK, but when I call SwapBuffers(), I see *both* of my squares on the screen. I thought the back right one would still be hidden as it has been drawn to a different buffer...?

Here's my code:

// use GL_BACK_RIGHT buffer
glDrawBuffer(GL_BACK_RIGHT);

glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

glLoadIdentity();
glTranslatef(0.0f,0.0f,-10.0f);

// draw a black square
glColor3b(0,0,0);
glBegin(GL_POLYGON);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);
glVertex3f(-1,-1,1);
glVertex3f(1,-1,1);
glEnd();

// now switch to GL_BACK buffer
glDrawBuffer(GL_BACK);

glLoadIdentity();
glTranslatef(0.0f,0.0f,-10.0f);

// draw an orange square
glColor3b(100,50,0);
glBegin(GL_POLYGON);
glVertex3f(2,2,1);
glVertex3f(0,2,1);
glVertex3f(0,0,1);
glVertex3f(2,0,1);
glEnd();

// swap back buffer to front
SwapBuffers(hDC);


Many thanks for any help in advance.

Daz.

Bob
05-01-2007, 08:59 AM
Are you sure you have a stereoscopic rendering context? If not, only the left buffer exists, and activating the right one is an error. Since it's an error, the command is ignored and the active buffer is not changed. That would explain why they both end up in the same buffer.

Darren Taylor
05-01-2007, 09:43 AM
I'm not sure. But I've tried rendering to the following buffers: GL_FRONT_LEFT,
GL_FRONT_RIGHT, GL_BACK_LEFT, GL_BACK_RIGHT, GL_FRONT,
GL_BACK, GL_LEFT, GL_RIGHT

And I get the same results, no matter which buffer I draw to. I always get both squares showing. Even if I render to GL_NONE!! o_0

Seems like it always defaults to GL_BACK, and nothing else...

Daz

Darren Taylor
05-01-2007, 09:57 AM
BTW I'm using NeHe's Tutorial 2 to test this.

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02

All I did was replace the DrawGLScene function with my code above, and I always get both squares showing. :-/

Many thanks for your help.

Daz

arekkusu
05-01-2007, 10:59 AM
GLint isStereo;
glGetIntegerv(GL_STEREO, &isStereo);
if (!isStereo) printf("Your pixel format wasn't created with stereo attributes, or your hardware doesn't support stereo.");

Darren Taylor
05-02-2007, 02:14 AM
OK,

Thanks for that. It seems that neither my laptop nor my pc at work have either stereo or auxilliary buffer support!! Which is real disappointing since I can't do what I want to do now.

I take it these buffers are very rarely used, if they are not supported that well?? Neither of my machines is more than 2 years old. :-(

Thanks anyways,

Daz.

Bob
05-02-2007, 03:18 AM
What is it you want to do then? Asking for a specific solution it not always the best idea. By doing so, you assume that solution is the best solution for the problem you have.

If you instead tell us what your ultimate goal really is, maybe we can provide a solution you never thought about, which is even better than using the stereoscopic rendering mechanism.

But then again, for stereoscopic rendering, there aren't many option. However, I do get the impression you don't really know what stereoscopic rendering is about, and you try to get it to do something it can't do.

Darren Taylor
05-02-2007, 03:38 AM
OK, after a bit more research, it seems the problem's because I'm using the 'generic' implementation of OpenGL on Windows - which does not support either stereo or auxiliary buffers.

So I'm wondering, how do I go about using a hardware implementation instead - and is this a wise thing to do?

Thanks,

Daz.

Darren Taylor
05-02-2007, 03:50 AM
Bob, thanks for your reply. I didn't see it until after I posted my last message.

I'm using the 'color picking' method. All I want to do is draw a scene to some back buffer that I can read the pixels from using glReadPixels. Every time the user moves the mouse I want it to find out what object the mouse is over.

Now I could simply draw the scene to GL_BACK every time the use moves the mouse, read the values, then clear the buffer and draw my main scene over it. But that would be very costly and probably halve my frame rate.

I just want my color picking scene to be stored in a separate buffer so I only need to redraw it when one of the objects in it actually changes position. This is why I was looking at using one of the stereo or auxiliary buffers to store my scene.

Thanks for your help.

Daz

ZbuffeR
05-02-2007, 05:03 AM
The fast way would be to use FBO for your offscreen rendering :
http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt

I don't really know if AUX buffers are actually available nowadays ?

Darren Taylor
05-02-2007, 08:43 AM
OK, thanks for that. I think it might be the way to go. I'll give it a shot!!

Cheers

Daz.

V-man
05-02-2007, 07:17 PM
Stereo buffers are supported on pro level cards like the nVidia Quadro.


Now I could simply draw the scene to GL_BACK every time the use moves the mouse, read the values, then clear the buffer and draw my main scene over it. But that would be very costly and probably halve my frame rate. Nah.
You lose some performance but it's not that big.

WITH 2 BUFFERS
backbuffer:
glClear
RenderEverything

offscreen buffer:
glClear
RenderEverythingVersion2
glReadPixels


With only back buffer
glClear
RenderEverythingVersion2
glReadPixels
glClear
RenderEverything