PDA

View Full Version : Prevent Automatic Flush



glCAD
01-29-2004, 01:37 PM
I am trying to draw an area using GL_QUAD_STRIP slices in a loop but the screen is updated after each run of loop even I am not using glFlush or SwapBuffer. I want to show the total are after loop exits. Not slice by slice. Does anyone know how I can prevent this problem?

nexusone
01-29-2004, 01:52 PM
Can you post the code? Can not tell from your discription.



Originally posted by glCAD:
I am trying to draw an area using GL_QUAD_STRIP slices in a loop but the screen is updated after each run of loop even I am not using glFlush or SwapBuffer. I want to show the total are after loop exits. Not slice by slice. Does anyone know how I can prevent this problem?

glCAD
01-29-2004, 02:05 PM
My code is as follows:

glRotated(-135,1,0,0);
SetGlColor(AreaColor);
glBegin(GL_QUAD_STRIP);
for(gg=0;gg<numXVal;gg++) {
glVertex3d(XVal[gg],0,0);
glVertex3d(XVal[gg],YVal[0][gg]/fact1,0);
}
glEnd();

SetGlColor(LabelColor);
for(gg=0;gg<numMax;gg++) {
STP.Format("%.3f",maxShown[1][gg]);
glPushMatrix(); {
glTranslatef(maxShown[0][gg],maxShown[1][gg]/fact2,0);
glScalef(1.0,100.00/DiagramMagFact,100.00/DiagramMagFact);
m_olf->DrawString(STP); /// this is a wgloutline text
} glPopMatrix();
}
glRotated(135,1,0,0);

Thank you


Originally posted by nexusone:
Can you post the code? Can not tell from your discription.

ZbuffeR
01-29-2004, 02:45 PM
I think you just need double buffering.

Request a double buffer at window creation time (using glut, native window bindings, whatever you use). Then draw whatever you need at once, this process will not be visible in the backbuffer. Then call SwapBuffers(hdc); (for Win32) to display at once what have been prepared. Then draw again if you need, swap, etc.

Hope it helps.

PS:Or maybe your DrawString routine calls Swapbuffers or glFlush ? Try commenting it.

[This message has been edited by ZbuffeR (edited 01-29-2004).]

glCAD
01-29-2004, 04:04 PM
I was using double buffering anyway. I also tried commenting DrawString function. Do not work. Any other recommendations?


Originally posted by ZbuffeR:
I think you just need double buffering.

PS:Or maybe your DrawString routine calls Swapbuffers or glFlush ? Try commenting it.

[This message has been edited by ZbuffeR (edited 01-29-2004).]

nexusone
01-29-2004, 05:37 PM
I had a little more code then that in mind, more like how you are calling your draw routine.

glCAD
01-29-2004, 05:48 PM
I could not get what you mean but my program works as follows:

DrawScene()
{
glClear()
glLoadIdentity()
DrawEtc()
DrawAreas()
DrawEtc()
SwapBuffer()
}

There is not any other glFlush() or SwapBuffer() anywhere else. I call DrawScene() when I need to update scene. However I have a rubberbanding function. In it I use
{
.
.
glDrawBuffer(GL_FRONT);
.
.
glFlush();
.
.
glDrawBuffer(GL_BACK);
.
.
}

But this rubberbanding function is not called from DrawScene() function. Any other suggestions?


Originally posted by nexusone:
I had a little more code then that in mind, more like how you are calling your draw routine.

Relic
01-30-2004, 06:26 AM
Really sounds like you don't draw into the back buffer. There's no way a window update can be visible if you only draw into the back buffer.
- Check your glDrawBuffer settings?
- Additional glCopyPixels from back to front in the code?
- Check the pixelformat if it really is double buffered.

glCAD
01-30-2004, 07:32 AM
Following is my PixelFormat. I checked again and I am sure I am drawing to GL_BACK then SwapingBuffer. I never used glCopyPixels in my code. Any other suggestions? Thanks.

BOOL CmyDlg::SetWindowPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pixelDesc;
pixelDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixelDesc.nVersion = 1;
pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_DRAW_TO_BITMAP |
PFD_SUPPORT_OPENGL |
PFD_SUPPORT_GDI |
PFD_STEREO_DONTCARE |
PFD_DOUBLEBUFFER;
pixelDesc.iPixelType = PFD_TYPE_RGBA;
pixelDesc.cColorBits = 32;
pixelDesc.cRedBits = 0;
pixelDesc.cRedShift = 0;
pixelDesc.cGreenBits = 0;
pixelDesc.cGreenShift = 0;
pixelDesc.cBlueBits = 0;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 0;
pixelDesc.cAccumRedBits = 0;
pixelDesc.cAccumGreenBits = 0;
pixelDesc.cAccumBlueBits = 0;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 16;
pixelDesc.cStencilBits = 0;
pixelDesc.cAuxBuffers = 0;
/* pixelDesc.cRedBits = 8;
pixelDesc.cRedShift = 16;
pixelDesc.cGreenBits = 8;
pixelDesc.cGreenShift = 8;
pixelDesc.cBlueBits = 8;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 64;
pixelDesc.cAccumRedBits = 16;
pixelDesc.cAccumGreenBits = 16;
pixelDesc.cAccumBlueBits = 16;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 32;
pixelDesc.cStencilBits = 8;
pixelDesc.cAuxBuffers = 0;
*/ pixelDesc.iLayerType = PFD_MAIN_PLANE;
pixelDesc.bReserved = 0;
pixelDesc.dwLayerMask = 0;
pixelDesc.dwVisibleMask = 0;
pixelDesc.dwDamageMask = 0;
m_GLPixelIndex = ChoosePixelFormat( hDC, &pixelDesc);
if (m_GLPixelIndex==0) // Let's choose a default index.
{
m_GLPixelIndex = 1;
if (DescribePixelFormat(hDC, m_GLPixelIndex,sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc)==0)
{
return FALSE;
}
}
if (SetPixelFormat( hDC, m_GLPixelIndex, &pixelDesc)==FALSE)
{
return FALSE;
}
return TRUE;
}



Originally posted by Relic:
Really sounds like you don't draw into
the back buffer. There's no way a window update can be visible if you only draw into the back buffer.
- Check your glDrawBuffer settings?
- Additional glCopyPixels from back to front in the code?
- Check the pixelformat if it really is double buffered.

kansler
01-30-2004, 11:29 AM
Originally posted by glCAD:
pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_DRAW_TO_BITMAP |
PFD_SUPPORT_OPENGL |
PFD_SUPPORT_GDI |
PFD_STEREO_DONTCARE |
PFD_DOUBLEBUFFER;

Change the code above with this:

pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_STEREO_DONTCARE |
PFD_DOUBLEBUFFER;

PFD_DRAW_TO_BITMAP forces software rendering and PFD_SUPPORT_GDI / PFD_DOUBLEBUFFER are mutually exclusive.

glCAD
01-30-2004, 01:32 PM
Thank you so much. It is working now. I prevented some other problems like flickering and paint problems too with this change. I still have some little problem. It does not show the scene initially when I sawpbuffer. But it works correctly after I resize my window. I am using Visual C++. I will check my code again. Thanks.


Originally posted by kansler:

Originally posted by glCAD:
pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_DRAW_TO_BITMAP |
PFD_SUPPORT_OPENGL |
PFD_SUPPORT_GDI |
PFD_STEREO_DONTCARE |
PFD_DOUBLEBUFFER;

Change the code above with this:

pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_STEREO_DONTCARE |
PFD_DOUBLEBUFFER;

PFD_DRAW_TO_BITMAP forces software rendering and PFD_SUPPORT_GDI / PFD_DOUBLEBUFFER are mutually exclusive.