View Full Version : wait for output to be displayed on screen before continuing the execution

04-10-2015, 11:24 AM
I want to force the program to wait for output to be displayed on screen before continuing the execution

Based on this link https://www.opengl.org/wiki/Swap_Interval I need to set the swap interval to 1.

bool WGLExtensionSupported(const char *extension_name)
// this is pointer to function which returns pointer to string with list of all wgl extensions

// determine pointer to wglGetExtensionsStringEXT function
_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddres s("wglGetExtensionsStringEXT");

if (strstr(_wglGetExtensionsStringEXT(), extension_name) == NULL)
// string was not found
return false;

// extension is supported
return true;

void main(int argc, char **argv){

//some code


if (WGLExtensionSupported("WGL_EXT_swap_control"))
// Extension is supported, init pointers.
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
// this is another function from WGL_EXT_swap_control extension
wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT");


// some code



but it's not working. Why?

Alfonse Reinheart
04-10-2015, 11:28 AM
Because that's not what swap interval is for. Swap interval is for preventing tearing by forcing the rendering system to wait to display the image until the vblank. It has nothing to do with what your CPU process does.

If you want to wait for the process of rendering and displaying to complete, you need to use synchronization (https://www.opengl.org/wiki/Synchronization). Specifically, use glFinish, but only after issuing your SwapBuffer command.

04-10-2015, 11:46 AM
This is the display function

void displayAll(void)

double timeN = GetCounter();
printf("%f \n", GetCounter() - timeN);


I’m using QueryPerformanceCounter to calculate time. The values displayed on the screen are of about 0.000005 instead of 0.0166666
What is the error?
Thank you

Alfonse Reinheart
04-10-2015, 12:13 PM
OK, I should have made that more clear. You still need swap interval (to force the rendering system to wait for a vblank before swapping), but you also need glFinish (to force the CPU to wait on the rendering system before continuing).

And if that doesn't work for you, then I'm not really sure what more you can do. Perhaps there is some control panel setting you may need to enable on your GPU driver?

04-10-2015, 02:50 PM
I think that the problem is on the auto swap buffers
Is there a method for disabling the auto swap buffer mode ?

carsten neumann
04-10-2015, 04:15 PM
I'm not sure I understand what you mean with "auto swap buffer mode". Buffers are not swapped automatically, it happens in response to you calling glutSwapBuffers(). Of course it only works when you have a double buffered system framebuffer, in the single buffered case there is nothing to swap and drawing has to happen in the front buffer.