Freeglut -> VSync Problem

Hello,

i switched from Android Studio/OpenGL (Java) to Windows Open GL.
(Eclipse IDE C++, MinGW, Freeglut)

The App is running good, except for the vsync trouble.
It seems to be an old problem, since i searched the net about it (for nearly two month).
I found a lot of discussion about this problem, but there was not a solution included.

In Windowed Mode, the Game runs perfect…but when going to Fullscreen Mode,
the vsync is not working.

i miss something like the wglSwapIntervalEXT (1)

did i have to add something to the project? (and where to get that)

or did freeglut / glutGameMode doing the vsync job?
(when calling, this is always crashing , cause no second screen configured message, and other mode problems)

i don’t need a lot of frames… even 40fps are more than enough for this project
but with this flickering i cannot show my project to anybody :wink:

greeting and much thanks


#define GLEW_STATIC
#include <GL/glew.h>
#pragma comment( lib, "glew32s.lib" )

#include <GL/glut.h>
#include <GL/glu.h>
...

.....................................................
if (glewIsSupported("GL_VERSION_3_0")) {
        cout << "GL_VERSION_3_0 : supported" << '
'; // Works
    } 

--------------------------------------
in Main Render Loop

glFinish(); //with or without its flickering
 glutSwapBuffers();
 .......................................................
alternate fullscreen code


if (IsWindowMode) {
        IsWindowMode = FALSE;
        GetWindowPlacement(hThisWnd, &wpc);
        if (HWNDStyle == 0)
            HWNDStyle = GetWindowLong(hThisWnd, GWL_STYLE);
        if (HWNDStyleEx == 0)
            HWNDStyleEx = GetWindowLong(hThisWnd, GWL_EXSTYLE);

        LONG NewHWNDStyle = HWNDStyle;
        NewHWNDStyle &= ~WS_BORDER;
        NewHWNDStyle &= ~WS_DLGFRAME;
        NewHWNDStyle &= ~WS_THICKFRAME;

        LONG NewHWNDStyleEx = HWNDStyleEx;
        NewHWNDStyleEx &= ~WS_EX_WINDOWEDGE;

        SetWindowLong(hThisWnd, GWL_STYLE, NewHWNDStyle);

        SetWindowLong(hThisWnd, GWL_EXSTYLE, NewHWNDStyleEx | WS_EX_TOPMOST);
        ShowWindow(hThisWnd, SW_SHOWMAXIMIZED);

    } else {
        IsWindowMode = TRUE;
        SetWindowLong(hThisWnd, GWL_STYLE, HWNDStyle);
        SetWindowLong(hThisWnd, GWL_EXSTYLE, HWNDStyleEx);
        ShowWindow(hThisWnd, SW_SHOWNORMAL);
        SetWindowPlacement(hThisWnd, &wpc);
    }





Are you using an Aero theme? If not, does using an Aero theme help? I see a lot of game developers recommend the use of an Aero theme in response to questions about vsync not working (but this may depend upon the specific API functions used).

Also: have you checked the control application for the graphics driver? There is usually a setting to force vsync on or off.

FreeGLUT doesn’t call wglSwapInterval(); in theory, this should result in vsync being enabled (the default value is 1, according to the WGL_EXT_swap_control specification).

[QUOTE=DerTherion;1293671]
i switched from Android Studio/OpenGL (Java) to Windows Open GL.
(Eclipse IDE C++, MinGW, Freeglut)

The App is running good, except for the vsync trouble.

In Windowed Mode, the Game runs perfect…but when going to Fullscreen Mode,
the vsync is not working.

i miss something like the wglSwapIntervalEXT (1)

with this flickering i cannot show my project to anybody[/QUOTE]

[ul]
[li]Do you see screen tearing? [/li][li]Are you calling glutInitDisplayMode with GLUT_DOUBLE before calling glutCreateWindow (creates a double-buffered render target; see glutInitDisplayMode). [/li][li]Which Windows version? [/li][li]Which GPU graphics driver? [/li][li]Are you calling wglSwapIntervalEXT (1) (or not calling wglSwapIntervalEXT at all)? [/li][li]Have you checked your driver control panel to ensure that you’re not overriding the application’s SwapInterval/VSync setting? [/li][li]If NVidia GL drivers, have you verified that you are not setting the __GL_SYNC_TO_VBLANK environment variable for your application? [/li][li]What’s your GL_VERSION and GL_RENDERER (printf( “GL_VERSION = %s[/li]”, glGetString( GL_VERSION) );)
[li]How are you creating and configuring your full-screen window (you’ve only shown a small part of it). [/li][li]Also, AFAIK you’re supposed to let GLUT create and manage the window, not monkey with it yourself using native Windows API calls (re your code snippet). That could be fouling it up. [/li][/ul]

or did freeglut / glutGameMode doing the vsync job?
(when calling, this is always crashing , cause no second screen configured message, and other mode problems)

[ul]
[li]Are you saying calling glutEnterGameMode() crashes? [/li][li]Are you calling if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) to see if it’s supported on your system with your config before trying to activate it? (see LINK and LINK) [/li][li]If you use debug GLUT libs, do you get any clues from the call stack? [/li][li]If GLUT game mode is crashing, how are you entering fullscreen mode above to see tearing (see “when going to Fullscreen Mode…” above; is this the “alternate fullscreen code” in the code snippet? Don’t do this.) ? [/li][li]You might try glutFullScreen() / glutLeaveFullScreen() instead of using game mode. [/li][/ul]

Hello and Thanks for your great answers,

i work on Win10Pro pc’s.

1.: i found in the AMD Radeon R9 380 (with latest GL Driver) , that the Global Settings APP was set to “off, when not configured from app” -> i turned to always on
->screen tearing still activ

  1. I changed to glutFullScreen() / glutLeaveFullScreen()
    ->screen tearing still activ

  2. glutCreateWindow <-> glutInitDisplayMode , i changed the order…
    ->screen tearing gone :slight_smile: that was it…:biggrin-new:


How can i tell AMD And Nvidia to use VSync for this Game?

  • i cannot call wglSwapIntervalEXT function because its not avaiable in freeglut

  • the if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) returns TRUE, so i have to learn more about calling it correctly

much much thanks for your help :slight_smile:

[QUOTE=DerTherion;1293684]1.: i found in the AMD Radeon R9 380 (with latest GL Driver) , that the Global Settings APP was set to “off, when not configured from app” -> i turned to always on
2. I changed to glutFullScreen() / glutLeaveFullScreen()
3. glutCreateWindow <-> glutInitDisplayMode , i changed the order…

->screen tearing gone :slight_smile: that was it…:biggrin-new:[/QUOTE]

Great!

How can i tell AMD And Nvidia to use VSync for this Game?

wglSwapIntervalEXT (1)

but that’s the default. As you found out though, the driver control panel can completely override what the application is requesting, so that has to be set properly as well.

i cannot call wglSwapIntervalEXT function because its not avaiable in freeglut

If you’re also using an extension loader library like GLEW, then you can just call it.

Otherwise, you’ll need to query the function pointer from the OpenGL library before you can call it.

Using GLEW is very easy. In your GLUT code, just add this:


#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
...
  // Init GLUT
  glutInit( &argc, argv );
  glutInitDisplayMode(  GLUT_RGBA | GLUT_DOUBLE  );
  glutCreateWindow( argv[0] );
  ...

  // Init GLEW
  GLenum err = glewInit();
  if ( err != GLEW_OK )
  {
    fprintf( stderr, "GLEW Init Error: %s
", glewGetErrorString(err) );
    exit(1);
  }

Then you can just use GL core and extension function pointers wherever, and write code like this that so that your code works as desired both with and without specific GL extensions:


  if ( !GLEW_KHR_debug )
  {
    // Execute this if KHR_debug is "not" supported
  }
  else
  {
    // Execute this if KHR_debug "is" supported
    // Here we can just call the KHR_debug extension function(s)
    ...
  }

much much thanks for your help

Sure thing!