How to render OpenGL via glx with SDL?

Hi all !

In the SDL-demos/OpenGL there’s a simple create/set context pair that
seems to
work ( I really don’t know that about MESA ). It would be nice if one
could use glX instead of MESA, since it’s hardware accelerated ( not
so much in Linux, yet ). Anyone ( probably with a lot more X
knowledge than me ) know how to do this? The prototypes to glX
require a display pointer and in the source code to glX indicates
that it won’t accept NULL as an argument … :frowning:

Cheers,

Jim Tilander

Jim Tilander
System Administrator at Djungeldata, Chalmers University of Technology
phone: +46 31 772 3390 fax: +46 31 7723202

Hi all !

In the SDL-demos/OpenGL there’s a simple create/set context pair that
seems to
work ( I really don’t know that about MESA ). It would be nice if one
could use glX instead of MESA, since it’s hardware accelerated ( not
so much in Linux, yet ). Anyone ( probably with a lot more X
knowledge than me ) know how to do this? The prototypes to glX
require a display pointer and in the source code to glX indicates
that it won’t accept NULL as an argument … :frowning:

You can get at the X display pointer by using the SDL_GetWMInfo API.

Here’s some sample code, taken from the SDL scrap demo:

int init_scrap(void)
{
SDL_SysWMinfo info;
int retval;

/* Grab the window manager specific information /
retval = -1;
SDL_VERSION(&info.version);
if ( SDL_GetWMInfo(&info) )
{
/
Save the information for later use /
#if defined(X11_SCRAP)
/
* */
if ( info.subsystem == SDL_SYSWM_X11 )
{
SDL_Display = info.info.x11.display;
SDL_Window = info.info.x11.window;
Lock_Display = info.info.x11.lock_func;
Unlock_Display = info.info.x11.unlock_func;

      /* Enable the special window hook events */
      SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
      SDL_SetEventFilter(clipboard_filter);

      retval = 0;
    }
  else
    {
      SDL_SetError("SDL is not running on X11");
    }

#elif defined(WIN_SCRAP)
/* * */
SDL_Window = info.window;
retval = 0;

#endif /* scrap type */
}
return(retval);
}

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Sam Lantinga wrote:

You can get at the X display pointer by using the SDL_GetWMInfo API.

It is indeed possible to create a GLX context with the window handle
and display name from SDL_GetWMInfo. However, there are two drawbacks:

  • Rendering into a Window (instead of a GLXWindow) is no longer
    recommended since GLX version 1.3.

  • GLX and SDL_GetWMInfo are platform dependent.

OpenGL is multi-platform, like SDL, but creating an OpenGL context is not.
It would be a natural extension for SDL to be able to create an
OpenGL context, maybe by adding a SDL_INIT_OPENGL flag for SDL_Init.

Any opinions?

  • Markus

Markus Enzenberger wrote:

Sam Lantinga wrote:

You can get at the X display pointer by using the SDL_GetWMInfo API.

It is indeed possible to create a GLX context with the window handle
and display name from SDL_GetWMInfo. However, there are two drawbacks:

  • Rendering into a Window (instead of a GLXWindow) is no longer
    recommended since GLX version 1.3.

  • GLX and SDL_GetWMInfo are platform dependent.

OpenGL is multi-platform, like SDL, but creating an OpenGL context is not.
It would be a natural extension for SDL to be able to create an
OpenGL context, maybe by adding a SDL_INIT_OPENGL flag for SDL_Init.

Yeah, SDL could take on the role of a better GLUT - yay, I can use more than
three keys at once in my game :slight_smile:
Sounds cool, anyone want to do it?

You could quite possibly just pinch the GL initialisation code from GLUT on
various platforms. (not sure about all the legal crap though, not sure what
license GLUT falls under)

:slight_smile:
Peter>

Any opinions?

  • Markus

Peter Hawkins
peterh at isa.net.au
Internet Solutions Australia (ACN 077 685 011)
Ph: 1300 369 990 - Fax: 02 6230 4455