Window with GLX

Hello

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[3] := GLX_GREEN_SIZE;
   a[4] := 8;
   a[5] := GLX_BLUE_SIZE;
   a[6] := 8;
   a[7] := GLX_DOUBLEBUFFER;
   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);
   glClear(GL_COLOR_BUFFER_BIT);
   glXSwapBuffers(dpy, w);

 

…i think it’s just some kind of punishment for using an exotic programming language :smiley:

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?

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.

Usually I work with .NET and Boo, that’s an exotic language :slight_smile: 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.

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

i’d like to know if it works on hardware other than mine…

RigidBody, it worked! I ported your code to pascal and it magically worked :-o I dont see a difference between our setup though.
Hmm…

at first sight, the differences seem to be:

  1. you use GLX_{RED|GREEN|BLUE}_SIZE
  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 :wink: 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 :wink:

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

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.