View Full Version : Create OpenGL window on X11

Ñuño Martínez
13-05-2009, 10:28 AM
System: GNU/Linux (Ubuntu)
Compiler/IDE: Free Pascal
Libraries/API: OpenGL

I'm trying to add OpenGL support to my Allegro.pas project. To do that I must create an OpenGL window and tell to Allegro the handler/function of that window.

I can do it on MS-Windows but I have no idea about how to do it on X systems because I have almost no experience on X. I've looked on the Internet and everything I found is GLUT, GLX and SDL related, but I can't use that because Allegro must access to the window to intercept messages (keyboard, etc.). As I've seen in Allegro's sources it uses the lowest X11 level.

I've read some C code about how to add OpenGL support to the original Allegro but I see it too much complex to translate it directly to Pascal.

Can somebody help me?

13-05-2009, 10:41 AM
Send me the source code and I'll look at it... see if I can translate it.

Ñuño Martínez
13-05-2009, 11:12 AM
Thanks really. I'll send it to you as soon as I can. :)

13-05-2009, 04:17 PM
maybe this is of use also http://www.delphigl.com/do_download.php?f=9000

its a basic opengl with x example.

14-05-2009, 09:47 AM

I've not received the mail... I've been checking my spam filter and it's not been dumped in there. Can you send it to 'athena at outer hyphen reaches dot com'.


Ñuño Martínez
14-05-2009, 01:09 PM
Thanks both.

@Athena: I did send it to your MSN account. :baby:

By the way, I've asked on other forums and mailing lists and it seems there's a problem with GLX. I mean Free Pascal doesn't links it and I don't know why. I did add "-klglx" to the compilation command but it says "/usr/bin/ld: lglx: No such file: No such file or directory". May be if I fix this then I can do the other.

Which package is the GLX dev one? I can't find it on Synaptic. :no:

14-05-2009, 01:54 PM
Try -k-lglx

Ñuño Martínez
14-05-2009, 02:44 PM
Try -k-lglx

It results in "/usr/bin/ld: cannot find -lglx"

14-05-2009, 07:43 PM
I could take a stab at a straight translation to Pascal, as I'm sure you can, but it depends on a whole bunch of stuff which is clearly defined in other headers/includes... without them, it really would be a stab in the dark.

From what you've said in your mail, you may well be able to get better assistance from others.

Was there a particular part of that function that was causing you problems or was it the whole thing?

Ñuño Martínez
17-05-2009, 11:27 PM
Was there a particular part of that function that was causing you problems or was it the whole thing?
I have this run-time error:

./exbasic: symbol lookup error: /usr/local/lib/libagl.so: undefined symbol: glXQueryExtension

"libagl.so" is an add-on for the original Allegro that adds OpenGL support.

I did ask both Allegro developers and FPC developers and no one gives me an answer. They said it should work if I add "-l-kglx" option or similar but then I get a compilation-time error.

If I can fix this then I can finish it by myself.

18-05-2009, 12:39 AM
Try to add {$L glx.so} somewhere in the code and remove the compiler option -k-lglx

Ñuño Martínez
18-05-2009, 05:51 PM
Try to add {$L glx.so} somewhere in the code and remove the compiler option -k-lglx

/usr/bin/ld: cannot find glx.so

And the same if I add {$L libglx.so}. The weird thing is that if I do use "locate" I get:

$ locate glx.so

I tried to load libglx.so by hand (LoadLibrary) then look for the "glXQueryExtension" function (GetProcedureAddress) and I success. I looked for a "dev" package for GLX and I've find only "libglitz-glx1-dev" but it forces "libglitz-glx1" and I'm using "libgl1-mesa-glx" library instead so should I install it?

On the other hand, I've test the C example programs from the original Allegro library (that uses the same libs) and they worked.

I'm very confused. xx(

19-05-2009, 07:15 AM
Try {$linklib glx}. Otherwise, pass -Cn to the compiler and check link.res to see how libglx is linked to your executable (paths, lib names, etc.)

19-05-2009, 09:49 AM
Try adding "-k-lGL". See my mail on fpc-pascal: there's no libglx that you should link with on Linux, glX functions are inisde libGL.so.

Ñuño Martínez
20-05-2009, 05:49 PM
Ok. I've created a link map accidentally (I mean I don't remember which options I used but the "exbasic.map" file was created) and it has these lines inside:

Allocating common symbols
Common symbol size file

0x4 /usr/lib/fpc/2.2.2/units/i386-linux/opengl/glx.o

Linker script and memory map

LOAD /usr/lib/fpc/2.2.2/units/i386-linux/opengl/gl.o
LOAD lib/allegro.o
LOAD lib/algl.o
LOAD /usr/lib/fpc/2.2.2/units/i386-linux/opengl/glu.o
LOAD /usr/lib/fpc/2.2.2/units/i386-linux/opengl/glx.o
LOAD /usr/lib/fpc/2.2.2/units/i386-linux/x11/x.o
LOAD /usr/local/lib/liballeg-4.4.0.so
LOAD /usr/lib/libdl.so
LOAD /usr/lib/libm.so
LOAD /usr/lib/libX11.so
LOAD /usr/lib/libc.so
LOAD /lib/libc.so.6
LOAD /usr/lib/libc_nonshared.a
LOAD /lib/ld-linux.so.2
COMMON 0x000000000809dd10 0x1a4 /usr/lib/fpc/2.2.2/units/i386-linux/opengl/glx.o
0x000000000809dd50 U_GLX_GLXQUERYEXTENSION
.debug_frame 0x0000000000000064 0x0 /usr/lib/fpc/2.2.2/units/i386-linux/opengl/gl.o
.debug_frame 0x0000000000000064 0x1234 lib/allegro.o
.debug_frame 0x0000000000001298 0x1a4 lib/algl.o
.debug_frame 0x0000000000001694 0x0 /usr/lib/fpc/2.2.2/units/i386-linux/opengl/glu.o
.debug_frame 0x0000000000001694 0x0 /usr/lib/fpc/2.2.2/units/i386-linux/opengl/glx.o

I'm not sure if I've listed all related lines, but if I've understood it links the GLX library and has information about the "glXQueryExtension", but for some reason the "libagl.so" can't link it. At the the Allegro forums (http://I'm wondering whether linking order could possibly make a difference.) a developer suggested that "(...) whether linking order could possibly make a difference. ".

This is getting weirder every day...