PDA

View Full Version : Accumulation buffer and double-buffering



cndg
09-21-2004, 01:49 PM
Hi,

When I call glAccum(GL_RETURN, 1.0) in single buffer mode I get the desired result. Instead I'd like to use double-buffering to avoid flickering. But glAccum(GL_RETURN, 1.0) seems to be producing incorrect results when writing to the back buffer instead of writing to the the front buffer. After swapping the buffers (calling SwapBuffers(hDC)) the result becomes visible: The content of the accumulation buffer is drawn, but displaced. The displacement depends on the current window position. :confused:

Please help me!

Thanks in advance
cndg

idr
09-22-2004, 07:35 AM
Do you have a small example program? That sounds wrong in several ways. I'll have to check, but I'm pretty sure that Accum operations shouldn't be affected by the current raster position.

cndg
09-22-2004, 12:58 PM
Hello idr,

Screenshot #1: single buffering (http://www.8ung.at/chni/opengl/glaccums.jpg)
Screenshot #2: double buffering (http://www.8ung.at/chni/opengl/glaccumd.jpg)

Initialization (I'm working with Borland C++ Builder - Panel1 is simply a child of the main window, hDC and hRC are Global), calling SetPixelFormatDescriptor:

hDC = GetDC(Panel1->Handle);
SetPixelFormatDescriptor();
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);

int Dim = min(Panel1->Width, Panel1->Height);
glViewport((Panel1->Width - Dim) / 2, (Panel1->Height - Dim) / 2, Dim, Dim);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, 1.0, 1.0, 25.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClearColor(0.0, 0.0, 0.0, 0.0);
glClearAccum(0.0, 0.0, 0.0, 0.0);

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);Might anything be wrong in my pixel format procedure?

void TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
32, // accumulation buffer
0, 0, 0, 0, // accum bits
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int PixelFormat;
PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, PixelFormat, &pfd);
}And, finally, the accumulation functions (in a test procedure that, as I mentioned, worked correctly in single buffer mode). Two spheres with different sizes but the same origin are painted and accumulated:

glClear(GL_ACCUM_BUFFER_BIT);

glPushMatrix();

glTranslatef(0.0, 0.0, -25.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere(3.0, 20, 20);
glAccum(GL_ACCUM, 0.5);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere(4.0, 20, 20);
glAccum(GL_ACCUM, 0.5);


glAccum(GL_RETURN, 1.0);
glFlush();

glPopMatrix();

SwapBuffers(hDC);