Results 1 to 6 of 6

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

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    4

    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 https://www.opengl.org/wiki/Swap_Interval I need to set the swap interval to 1.

    Code :
    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?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,677
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    4
    This is the display function
    [
    void displayAll(void)
    {

    double timeN = GetCounter();
    drawObject();
    glutSwapBuffers();
    glFinish();
    glutPostRedisplay();
    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

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,677
    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?

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    4
    I think that the problem is on the auto swap buffers
    Is there a method for disabling the auto swap buffer mode ?

  6. #6
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    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.

Similar Threads

  1. Picture is displayed to big on the screen
    By danielspengler99 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-14-2017, 06:37 AM
  2. Only half screen displayed on OS X
    By imported_Alemarius Nexus in forum OpenGL: macOS
    Replies: 3
    Last Post: 05-26-2011, 09:43 AM
  3. Replies: 0
    Last Post: 07-29-2009, 12:54 PM
  4. Screen refreshes when another window is displayed above it
    By rickp101 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-18-2002, 05:09 AM
  5. Replies: 4
    Last Post: 06-06-2002, 10:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean