SDL dynamic OpenGL

Blame me for my ignorance, but looking at the OpenUT code didn’t really help me in
understanding the way SDL_GL_LoadLibrary/SDL_GL_GetProcAddress should be used.

What are the basics steps to getting e.g. glViewport’s address registered ?

I could use LD_PRELOAD with xmms to make SDL use libGL, but since I’m only writing
a plugin, requiring changes to the way xmms get’s loaded would not be appropriate.

I tried linking libGL using -lGL on gcc’s command line when creating libfx.so (the xmms
plugin) which should work as far as I know, but SDL doesn’t cope. (see previous post ->
SDL 1.1. OpenGL problem?)

This is what the Makefile looked like:

LIBS = -lGL gtk-config --libs libglade-config --libs sdl-config --libs
CFLAGS = gtk-config --cflags libglade-config --cflags sdl-config --cflags
DEFS = -DHAVE_OPENGL

all: libfx.so

.c.o:
gcc -O2 -Wall -c -o $@ $< $(DEFS) $(CFLAGS)

libfx.so: fx.o config.o fx.h
gcc -O2 -Wall -shared -o $@ fx.o config.o $(DEFS) $(CFLAGS) $(LIBS)--------------------------------------------------------------
Christian Zander ** N?ckersberg 76 ** 45257 Essen ** Germany
email: mbox at minion.de ** www: www.minion.de ** icq#: 5322926

In article <38C123BF.EA042CD8 at grafzahl.de>, Daniel Vogel <666 at grafzahl.de> wrote:

Daniel Vogel wrote:

Well, UT does it by only using OpenGL in one class so it simply shadows
the global declaration. You could create a static class and then do
something like OpenGL::glVertex3f if you need it globally. I wonder
which glVertex3f would get called if you use namespace OpenGL… hmmm…

I should think before I write…

:wink:

you can do something like

namespace OpenGL
{
//declare it here
}

and then do OpenGL::glVertex3f. Usually the compiler will bug because of
ambigouity (spelling?) if you do “using namespace OpenGL” and have
included gl.h.

Yeah, except i’m coding this thing in c. I don’t like loading the libs dynamically, anyway.
Loading each of the functions for a plugin that size seems like overkill and portability goes
down the drain (at least for some platforms).

What i don’t understand is why the rest of the plugin seems to find the gl symbols alright,
just not sdl??--------------------------------------------------------------
Christian Zander ** N?ckersberg 76 ** 45257 Essen ** Germany
email: mbox at minion.de ** www: www.minion.de ** icq#: 5322926

phoenix at minion.de wrote:

LIBS = -lGL gtk-config --libs libglade-config --libs sdl-config --libs

guessing, but maybe try

LIBS = -lGL gtk-config --libs libglade-config --libs sdl-config --libs -lGL–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

phoenix at minion.de wrote:

In article <38C10C22.5B3AD609 at grafzahl.de>, Daniel Vogel <@Daniel_Vogel> wrote:

guessing, but maybe try

LIBS = -lGL gtk-config --libs libglade-config --libs sdl-config --libs -lGL

That didn’t do anything :wink:

I didn’t quite understand what your problem is exactly :slight_smile: Basically I
suggested the above because linking order is important and this way you
can be sure that all GL symbols get resolved. Basically you want to
place -lGL at the end and not in the beginning in general. But if that
had been the cause the linker would have complained I guess - at least
under Linux.

in a function and it worked. Using the declaration globally fails, though, since that
results in a conflict with the declaration in gl.h.

How do I get by this?

Well, UT does it by only using OpenGL in one class so it simply shadows
the global declaration. You could create a static class and then do
something like OpenGL::glVertex3f if you need it globally. I wonder
which glVertex3f would get called if you use namespace OpenGL… hmmm…–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

In article <38C10C22.5B3AD609 at grafzahl.de>, Daniel Vogel <666 at grafzahl.de> wrote:

guessing, but maybe try

LIBS = -lGL gtk-config --libs libglade-config --libs sdl-config --libs -lGL

That didn’t do anything :wink:

Anyway, how do i use SDL_GL_GetProcAddress ?

I did something like

void (glViewport) ( GLint x, GLint y, GLsizei width, GLsizei height );
glViewport = (void
) SDL_GL_GetProcAddress (“glViewport”);

in a function and it worked. Using the declaration globally fails, though, since that
results in a conflict with the declaration in gl.h.

How do I get by this?--------------------------------------------------------------
Christian Zander ** N?ckersberg 76 ** 45257 Essen ** Germany
email: mbox at minion.de ** www: www.minion.de ** icq#: 5322926

Daniel Vogel wrote:

Well, UT does it by only using OpenGL in one class so it simply shadows
the global declaration. You could create a static class and then do
something like OpenGL::glVertex3f if you need it globally. I wonder
which glVertex3f would get called if you use namespace OpenGL… hmmm…

I should think before I write…

you can do something like

namespace OpenGL
{
//declare it here
}

and then do OpenGL::glVertex3f. Usually the compiler will bug because of
ambigouity (spelling?) if you do “using namespace OpenGL” and have
included gl.h.–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

phoenix at minion.de wrote:

In article <38C123BF.EA042CD8 at grafzahl.de>, Daniel Vogel <666 at grafzahl.de> wrote:

Daniel Vogel wrote:

Well, UT does it by only using OpenGL in one class so it simply shadows
the global declaration. You could create a static class and then do
something like OpenGL::glVertex3f if you need it globally. I wonder
which glVertex3f would get called if you use namespace OpenGL… hmmm…

I should think before I write…

:wink:

you can do something like

namespace OpenGL
{
//declare it here
}

and then do OpenGL::glVertex3f. Usually the compiler will bug because of
ambigouity (spelling?) if you do “using namespace OpenGL” and have
included gl.h.

Yeah, except i’m coding this thing in c. I don’t like loading the libs dynamically, anyway.
Loading each of the functions for a plugin that size seems like overkill and portability goes
down the drain (at least for some platforms).

What i don’t understand is why the rest of the plugin seems to find the gl symbols alright,
just not sdl??


Christian Zander ** N?ckersberg 76 ** 45257 Essen ** Germany
email: mbox at minion.de ** www: www.minion.de ** icq#: 5322926

SDL is doing dlopen on the running program to find the OpenGL symbols. It works fine here, I
don’t know why it wouldn’t work for you. Are you actually making any GL calls from your
program?

–Sam Lantinga

What i don’t understand is why the rest of the plugin seems to find the gl symbols alright,
just not sdl??

Can you give detailed information about your system and library setup?
It works on all the systems I’ve had a chance to try.

-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:

phoenix at minion.de wrote:

In article <38C123BF.EA042CD8 at grafzahl.de>, Daniel Vogel <666 at grafzahl.de> wrote:

Daniel Vogel wrote:

Well, UT does it by only using OpenGL in one class so it simply shadows
the global declaration. You could create a static class and then do
something like OpenGL::glVertex3f if you need it globally. I wonder
which glVertex3f would get called if you use namespace OpenGL… hmmm…

I should think before I write…

:wink:

you can do something like

namespace OpenGL
{
//declare it here
}

and then do OpenGL::glVertex3f. Usually the compiler will bug because of
ambigouity (spelling?) if you do “using namespace OpenGL” and have
included gl.h.

Yeah, except i’m coding this thing in c. I don’t like loading the libs dynamically, anyway.
Loading each of the functions for a plugin that size seems like overkill and portability goes
down the drain (at least for some platforms).

What i don’t understand is why the rest of the plugin seems to find the gl symbols alright,
just not sdl??


Christian Zander ** N?ckersberg 76 ** 45257 Essen ** Germany
email: mbox at minion.de ** www: www.minion.de ** icq#: 5322926

SDL is doing dlopen on the running program to find the OpenGL symbols. It works fine here, I
don’t know why it wouldn’t work for you. Are you actually making any GL calls from your
program?

–Sam Lantinga

im not sure if im right as ive only skimmed the posts but i think i think i might know the answer.

he is writing a plugin for a program not a program, when his plugin uses SDL for opengl SDL
dlopens the program(xmms) to look for the symbols and not the plugin so the opengl symbols arent
there.

Jess