SDL_GL_SWAP_CONTROL problem on linux

Hello, I’m having some problems turning on vsync on fedora 7. I wrote
the following test program:

#include <SDL/SDL.h>
#include
#include

int main()
{
assert(SDL_Init(SDL_INIT_VIDEO) == 0);

int retval = SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

if (retval == 0)
{
   std::cout << "Successfully requested swap control to be turned 

on." << std::endl;
}
else if (retval == -1)
{
std::cout << “SDL_GL_SetAttribute() failed.” << std::endl;
std::cout << "SDL_GetError() returns: " << SDL_GetError() <<
std::endl;
}
else
{
std::cout << “Unknown return value " << retval << " from
SDL_GL_SetAttribute().” << std::endl;
}

assert(SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) != NULL);

int check = 0;

retval = SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &check);

if (retval == 0)
{
   std::cout << "Status of SDL_GL_SWAP_CONTROL after calling 

SDL_SetVideoMode(): " << check << std::endl;
}
else if (retval == -1)
{
std::cout << “SDL_GL_GetAttribute() failed.” << std::endl;
std::cout << "SDL_GetError() returns: " << SDL_GetError() <<
std::endl;
}
else
{
std::cout << “Unknown return value " << retval << " from
SDL_GL_GetAttribute().” << std::endl;
}

SDL_Quit();

}

Under windows, the output is:
Successfully requested swap control to be turned on.
Status of SDL_GL_SWAP_CONTROL after calling SDL_SetVideoMode(): 1

Very good. Under fedora 7, however, the output is:
Successfully requested swap control to be turned on.
SDL_GL_GetAttribute() failed.
SDL_GetError() returns: Failed loading DPMSDisable:
/usr/lib/libX11.so.6: undefined symbol: DPMSDisable

It was not actually not until I wrote this test program that I noticed
that the call to SDL_GL_GetAttribute() fails under fedora 7. I did
notice that my sdl/opengl project was not vsynced under fedora and
that’s what prompted me to write the test program.

I thought that moving from Cygwin to fedora 7 would make things easier,
not harder, hehe. I really need to solve this one if I’m to continue
using fedora 7 for this developement project comfortably. Let me know of
any more information you need for you to help me. I’m a newbie with SDL
and especially a linux newbie.

I’m not sure if this belongs in a fedora forum or in a SDL forum, but I
thought I might try here first. I suspect several gurus are using linux
here and I don’t have the skillset to determine where the solution might
lie.

I have the same problem on both my laptop and my stationary computer,
the output from the test program is from the laptop. Going to run it now
on my main computer. Both have nvidia graphics cards with latest livna
drivers.

  • Eric

Eric Lilja wrote:

I have the same problem on both my laptop and my stationary computer,
the output from the test program is from the laptop. Going to run it now
on my main computer. Both have nvidia graphics cards with latest livna
drivers.

I just ran the test program on my main computer, exactly the same output
as when I ran it on my laptop. I’m dual-booting both machines and I’m
writing this from my main computer in windows and I have fedora 7
running on my laptop next to me.

  • Eric

Very good. Under fedora 7, however, the output is:
Successfully requested swap control to be turned on.
SDL_GL_GetAttribute() failed.
SDL_GetError() returns: Failed loading DPMSDisable:
/usr/lib/libX11.so.6: undefined symbol: DPMSDisable

That’s a bogus error message left over from SDL_Init() (and I think we
fixed this in 1.2.12 to blank that error out), and SDL_GL_SetAttribute()
isn’t setting a new error message when it fails.

SDL_GL_SetAttribute() is failing because most X11 systems don’t support
SWAP_CONTROL.

I’ve committed a patch in svn revision #3387 to clarify the error message.

–ryan.

Ryan C. Gordon wrote:

Very good. Under fedora 7, however, the output is:
Successfully requested swap control to be turned on.
SDL_GL_GetAttribute() failed.
SDL_GetError() returns: Failed loading DPMSDisable:
/usr/lib/libX11.so.6: undefined symbol: DPMSDisable

That’s a bogus error message left over from SDL_Init() (and I think we
fixed this in 1.2.12 to blank that error out), and SDL_GL_SetAttribute()
isn’t setting a new error message when it fails.

SDL_GL_SetAttribute() is failing because most X11 systems don’t support
SWAP_CONTROL.

I’ve committed a patch in svn revision #3387 to clarify the error message.

–ryan.

Thanks for your reply, Ryan. I’m using SDL 1.2.12 on Windows…not sure
about the version on fedora 7, I think it might be 1.2.11 because I
don’t recall seeing it downloaded when doing system updates.

It’s a bit annoying that I can’t use the same method as I did on windows
for vsync. Fortunately, I’ve found a work-around that works for me that
involves utilizing an nvidia extension (both my main computer and laptop
have nvidia graphic cards). So now my code looks like this:
#if defined CYGWIN
/* Turn on vsync, this works on Windows. /
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
#elif defined __linux
/
Fedora 7 doesn’t suuport SDL_GL_SWAP_CONTROL, but we use this
nvidia extension instead. */
SDL_putenv("__GL_SYNC_TO_VBLANK=1");
#endif

This gives me the desired effect on both fedora 7 and windows: synced to
vertical refresh. I know this is not portable.

  • Eric

Den Mon, 06 Aug 2007 14:37:52 -0400
skrev “Ryan C. Gordon” :

That’s a bogus error message left over from SDL_Init() (and I think
we fixed this in 1.2.12 to blank that error out), and
SDL_GL_SetAttribute() isn’t setting a new error message when it fails.

SDL_GL_SetAttribute() is failing because most X11 systems don’t
support SWAP_CONTROL.

It’s SDL_GL_GetAttribute that fails here though, SDL_GL_SetAttribute
returns success. The problem seems to be that while setting the swap
control attribute is supported, the drivers apparently doesn’t support
reading it. At least that’s the results I get here (nvidia binary
drivers, xorg 1.2); Eric’s test program fails in the same way, but
setting SDL_GL_SWAP_CONTROL to 1 works perfectly, enabling that smooth
vsync we all know and love. The SDL source reveals that this isn’t a
huge surprise, since it uses glXGetSwapIntervalMESA to get the value.
That’s a MESA function, not supported by the nvidia drivers.

I get a different bogus error message after SDL_GL_GetAttribute btw:
“no input method could be opened” (SDL 1.2.12). (Input works fine
though).

  • Gerry

It’s SDL_GL_GetAttribute that fails here though, SDL_GL_SetAttribute
returns success. The problem seems to be that while setting the swap
[…]
I get a different bogus error message after SDL_GL_GetAttribute btw:
“no input method could be opened” (SDL 1.2.12). (Input works fine
though).

Hmm. Bad day. :slight_smile:

I’ll take a look at these soon.

–ryan.