wait for output to be displayed on screen before continuing the execution

I want to force the program to wait for output to be displayed on screen before continuing the execution

Based on this link Swap Interval - OpenGL Wiki 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
	PFNWGLGETEXTENSIONSSTRINGEXTPROC _wglGetExtensionsStringEXT = NULL;

	// determine pointer to wglGetExtensionsStringEXT function
	_wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("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 

PFNWGLSWAPINTERVALEXTPROC       wglSwapIntervalEXT = NULL;
	PFNWGLGETSWAPINTERVALEXTPROC    wglGetSwapIntervalEXT = NULL;

	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");
	}

	wglSwapIntervalEXT(1);

// some code

init();
	glutDisplayFunc(displayAll);
    glutMainLoop();

}

but it’s not working. Why?

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. Specifically, use glFinish, but only after issuing your SwapBuffer command.

This is the display function

[
void displayAll(void)
{

double timeN = GetCounter();
drawObject();
glutSwapBuffers();
glFinish();
glutPostRedisplay();
printf("%f
", 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

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?

I think that the problem is on the auto swap buffers
Is there a method for disabling the auto swap buffer mode ?

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.