OpenGL and Xwindows

Started by
14 comments, last by Disgruntled Gamer 18 years ago
I want to write a simple OpenGL app in Xwindows and so I haven't been able to find any examples on how to do it. I can do this in windows using just the winapi so I was hoping to find a similar way to do it under X with out using something like GTK+. Any input would be appreciated, thanks
Advertisement
There is a nice techpubs article on Sgi.com that is a good way to get started.

OpenGl on SGI

Chapter 3. OpenGL and X: Examples - has some sample code for using xt widgets or just using straight xlib to create an OpenGL Context.
Xlib is quite painfull. You might want to consider using SDL or GTK to set up the window. These are crossplatform, so you also avoid platform specific code. If you still want to do it with only Xlib, PM me and I will send you the code I use to set up windows for use with OGL (it isn't ready for public release yet :)
Do a google search for a sample app called glxsimple.c. It's from the book OpenGL Programming for the X Window System by Mark J. Kilgard (the green book). It just sets up a simple opengl window using xlib which isn't too bad if you've worked with the winapi, and it's pretty straight forward.

Hope this helps.
If you check out NeHe, you might see the NeHeGL GLX basecode on the left side, under the heading 'OpenGL Basecode'. If you want something cross-platform, and you don't mind not being able to do fullscreen toggling in Windows, or changing the current display properties (colour depth, refresh rate, etc.), then you might as well use SDL, but if you're like me, and want a fairly flexible window setup, then that code should help you on your way (I still haven't figured out fullscreen toggling using Xlib, but everything else seems to be working fairly well at the moment).
Quote:Disgruntled Gamer:
It just sets up a simple opengl window using xlib which isn't too bad if you've worked with the winapi, and it's pretty straight forward.


yes, the simple examples are straight forward but things like fullscreen are tricky to get right. Unfortunately the Xlib documentation isn't clear about which functions can be called in which window state, it took me lots of trial and error to find out. Sad thing that good documentation, like the OpenGL one, is rare.
Quote:Original post by Gorax
(I still haven't figured out fullscreen toggling using Xlib, but everything else seems to be working fairly well at the moment).


I think I'm gonna clean up my rewrite of the glx basecode and release it. The fullscreen toggling in the nehe glx code is a dirty hack that leaks memory :-/

But if you are interested here is what I do:
1. unmap the window
2. change screen resolution with the XF86VidMode extention
3. set the viewport and window location/size to match the resolution
4. grab mouse and keybopard
5. set the redirect_override property of the window*
6. map the window

* this is considered bad practice, but I find it ok. The "right way" to do it is window manager hints.
Hi nefthy,

I've been wondering myself how you setup a full screen window in xwindows. I would be very interested in seeing your code on how to do it. I have a lot more experience with win32 programming than I do with xwindow programming so the steps you listed aren't that familiar to me. Any further explanation would be greatly appreciated. Also is there an easy way to turn off your mouse pointer in xwindows, like an xwindows version of ShowCursor or something?

DG

[Edited by - Disgruntled Gamer on April 21, 2006 6:20:47 PM]
As I said I will clean the code up and upload it. As for hiding the mouse pointer, I havent found it yet, but I will hopefully.
Cool thanks guys, this information is great. Hopfully I can post some progress later tonight.

This topic is closed to new replies.

Advertisement