View Full Version : Window with GLX

04-10-2006, 07:50 AM

I am now busy getting the GLX and Xlib working together. Somehow I get a strange error. The window is properly created and mapped, the visual is properly selected and the valid rc is also being created (I tested it). Hovewer, I get a "zero division exception" on the line where I bind the context to the window. Basically, I followed glxgears code (and glxgears runs). What am I doing wrong? I use nvidia glx module for Xorg

// choose the visual
a[0] := GLX_RGBA;
a[1] := GLX_RED_SIZE;
a[2] := 8;
a[4] := 8;
a[5] := GLX_BLUE_SIZE;
a[6] := 8;
a[8] := None;

vinfo := glXChooseVisual(dpy, 0, @a[0]);
context := glXCreateContext(dpy, vinfo, nil, true);

// Create the window
swa.background_pixel := 0;
swa.border_pixel := 0;
swa.colormap := XCreateColormap( dpy, RootWindow(dpy, vinfo^.screen), vinfo^.visual, AllocNone);
swa.event_mask := StructureNotifyMask or ExposureMask or KeyPressMask;
mask := CWBackPixel or CWBorderPixel or CWColormap or CWEventMask;

w := XCreateWindow(dpy, RootWindow(dpy, vinfo^.screen), 0, 0, 100, 100, 0, vinfo^.depth,
InputOutput, vinfo^.visual, mask, @swa);

XMapWindow(dpy, w);

// bind the context
glXMakeContextCurrent(dpy, w, w, context); // <- EXCEPTION HERE!

glClearColor(1, 1, 1, 0);
glXSwapBuffers(dpy, w);

04-10-2006, 08:13 AM
...i think it's just some kind of punishment for using an exotic programming language :D

it seems a bit strange to me you that have to pass the window twice to glXMakeContextCurrent. why is the pascal function different from the C function? is it possible that it is an error that your compiler ignores?

04-10-2006, 09:13 AM
The second drawable parameter is for the read window.

glXMakeContextCurrent is the glx 1.3 version of glXMakeCurrent. Did you tried the other version ?

Also, as far as I know, glx 1.3 is only supported on nVidia hardwares and glx initialization is different on this version. Try to go back to full glx 1.2, it works well everywhere.

04-10-2006, 09:55 AM
Usually I work with .NET and Boo, that's an exotic language :-) Pascal is still older then C

Now to the topic: using the usual glxMakeCurrent has the same effect (the same exception) - I just wanted to try the other version it out. As you can see, I actually use teh old plain glx 1.1 (no fbuffer configurations etc.)

RigidBody, maybe you are right and that is an compiler issue. I'll try to write it using C and look if it will work.

04-10-2006, 10:12 AM
oh...well, i turned 34 last week- eyes getting dull, brain getting slow, i just didn't see the Context in glXMakeContextCurrent :rolleyes:

anyway, if you have some time, try this (http://www.opengl.org/wiki/index.php/Programming_OpenGL_in_Linux:_GLX_and_Xlib)

i'd like to know if it works on hardware other than mine...

04-10-2006, 02:01 PM
RigidBody, it worked! I ported your code to pascal and it magically worked :-o I dont see a difference between our setup though.

04-10-2006, 02:28 PM
at first sight, the differences seem to be:

2. you use glXMakeContextCurrent, not glXMakeCurrent

ad 1) : the more restrictions you enforce, the higher is the probability that a visual with that restrictions does not exist on your system. but as you said, you checked the visual and the gl context? so the problem doesn't seem to be there.

ad 2) : don't know, i never use glXMakeContextCurrent ;-) have you tried glXMakeCurrent in your code?

and finally, maybe you could register for the wiki... i don't think there are so many people who have knowledge about pascal and opengl ;-)

04-10-2006, 03:29 PM
glXMakeCurrent throwed exacly the same exception. I bet it is implemented as a glXMakeContextCurrent call

The exception arised when I tried to bind the context to the window, so maybe it didn't like the window. Probably it was the border color or stuffs... anyway, thank you, now I have a working sample.

I will probably contribute to the wiki, I was looking to this for long time already :-)