The problem is that SDL_GL_SwapWindows is only updating the screen intermittently . E.g. it may redraw 10 times very quickly, but only every 3 seconds second or so. More frustratingly it works on one computer of mine and not another.
The problem laptop has OpenGL 4.5 and I’m on Windows 10. Using latest SDL 2.0.12 and glew 2.1.0.
I’ve got the problem narrowed down to a smallish example where I’m only changing the clear color. I know rendering works because I have tested it with a simple textured cube, and that displays fine.
This sample application works on one computer (also Windows, but OpenGL 4.6) but not another.
My SDL setup code is more or less as follows:
SDL_Init(SDL_INIT_VIDEO);
*window = SDL_CreateWindow("OpenGL Test",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
g_width, g_height,
SDL_WINDOW_OPENGL);
{ // Setup GL
// Disable deprecated functions
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
// OpenGL 4.5
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
// Use double-buffering
enum {
SINGLE_BUFFER = 0,
DOUBLE_BUFFER = 1,
};
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, DOUBLE_BUFFER);
enum {
SOFTWARE_RENDERING = 0,
HARDWARE_RENDERING = 1,
};
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, HARDWARE_RENDERING);
// Sync buffer swap with monitor refresh rate
enum {
ADAPTIVE_VSYNC = -1,
IMMEDIATE = 0,
VSYNC = 1
};
SDL_GL_SetSwapInterval(VSYNC);
}
*context = SDL_GL_CreateContext(*window);
I’ve toyed with software rendering instead of hardware, all 3 swap intervals, and single buffering, as well as fullscreen mode; to no avail.
And my main loop contains the following:
r32 value = (ticks % 360) / 360.f;
glClearColor(value, value, value, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(window);
This loop runs 60 times a second (I verify this with print statements), and every iteration is always <2 ms.
The result is that I see colors grow closer to white every couple or 3 seconds with sudden jumps to a much brighter or darker shade.
If I print out the ticks counter I see those update 60/second so I know nothing is blocking or slowing down. I’ve also timed the whole loop and its always under 2 ms.
I’ve successfully run the OpenGL Extensions Viewer 6.0 benchmark on the laptop and it passes for all available versions of OpenGL. I’ve verified my graphics drivers are up to date.