Hi, I am having a problem statically linking SDL with openGL support,
and wonder if someone can throw some light on this.
Well first of all AFAIK one should never statically link OpenGL to
anything. libGL.so (or opengl32.dll, or whatever it’s called) is
implementation-specific.
Using Linux, Ubuntu Breezy, the debian packaging for 1.2.8,
sdl-config reports
skaller at rosella:/work/felix/flx$ sdl-config --cflags
-I/usr/include/SDL -D_REENTRANT
skaller at rosella:/work/felix/flx$ sdl-config --libs
-L/usr/lib -lSDL -lpthread
skaller at rosella:/work/felix/flx$ sdl-config --static-libs
-L/usr/lib -lSDL -lpthread -lm -ldl -L/usr/lib -lasound -lm -ldl
-lpthread -L/usr/lib -ldl -lartsc -lpthread -lgmodule-2.0 -ldl
-lgthread-2.0 -lglib-2.0 -L/usr/lib -lesd -laudiofile -lm -laudio -lXt
-lX11 -lXext -laa
No openGL libs are mentioned. Yet, 1.2.9 CVS ./configure --help
reports
–enable-video-opengl include OpenGL context creation default=yes
That’s normal. SDL does not link to libGL. It only abstracts the
OpenGL contexts (ie. GLX, WGL, AGL, etc.), so you can create an OpenGL
context in a platform-independent matter. It knows nothing about
OpenGL itself. Not that it should anyway. OpenGL is fully
platform-independent once you take care of the context.
Despite that:
skaller at rosella:/work/sdl/SDL-1.2$ sh sdl-config --cflags
-I/usr/local/include/SDL -D_REENTRANT -D_GNU_SOURCE
skaller at rosella:/work/sdl/SDL-1.2$ sh sdl-config --libs
-L/usr/local/lib -Wl,-rpath,/usr/local/lib -lSDL -lpthread
skaller at rosella:/work/sdl/SDL-1.2$ sh sdl-config --static-libs
-L/usr/local/lib -Wl,-rpath,/usr/local/lib -lSDL -lpthread -lm -ldl
-L/usr/X11R6/lib
again seems to fail to support openGL. Spec file says:
%ifos linux
CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{prefix}
–disable-video-svga --disable-video-ggi --disable-video-aalib
–disable-debug --enable-dlopen
–enable-esd-shared --enable-arts-shared
%else
%configure --disable-debug --enable-dlopen
%endif
which indicates openGL should be supported. Can anyone explain
what’s going on?
Stuff runs, if one adds -lGL -lGLU to dynamic link.
Is something misconfigured, or do I misunderstand something?
It’s not a bug, it’s a feature
It is not included in sdl-config
because linking libGL to every SDL application would add an unneeded
dependency, since not every SDL app would need one.
We’re trying to figure out what switches to give linkers
etc in a platform independent way. SDL_opengl already
contains opengl definitions it seems. Does the user still
have to supply an actual openGL library at link time?
So … SDL provides its own headers but the client must
supply an implementation. Deliberate?
SDL provides nothing else than context management. The OpenGL
implementation should provide both headers (GL/gl.h, GL/glext.h, etc)
for the developer to use, and a libGL library to run the resulting
program.
The best way to handle OpenGL in a fully portable manner is to do
run-time dynamic loading, which requires no compile-time linking to
libGL whatsoever. Luckily SDL is great for that.
First off call SDL_GL_LoadLibrary(NULL) to load the GL library. You
can substitute NULL for a string containing the full path to a GL
library, but leaving it to NULL indicates SDL to find the default one
on the system, which usually works out perfectly. Then use the
SDL_GL_GetProcAddress() function to load OpenGL function symbols. This
is a bit trickier to explain in an email, so look at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fGL_5fGetProcAddress for a
quick 'n dirty example. If you want a more complete example, I’ve
wrote a small (< 300 lines) app a few months ago that does all of the
above and should not be not too hard to understand. Mail me off-list
if you want me to send it to you.
There are also free libraries available to do the ugly symbol loading
stuff mentionned above, but I’ve never used one myself so I can’t give
my opinion on any of them. The most popular of them appears to be the
one called “glew”.On 2/24/06, skaller wrote: