So now whats the deal with openGL in linux?

greetings guru’s

I have been programming opengl for several months now in windoze but now I am ready to grow up and leave proprietary software in my past.

I have done a couple searches and the more i read the more confused I seem to become… so much information about mesa and X11 or SGI-SI and DRI and all sorta of things.

Does anyone know of a good web resource for opengl programming with CURRENT methods? All I really need is the basics to get a window up in X and I can pump my own gl code into that.

Cheers,
James

The book from MArk J Kilgard is pretty good and not so out of date as you can think.
The problem is that half of the book is on glut so if you don’t need that then you don’t need the book.

The Xlib programming manual is pretty useful. But it takes a LONG time to read and it definetly goes much beyond the need of an average GL programmer, while it still leaves some problems to be covered.

I’ll tell the truth. Many months ago, I tried to port to linux. I had roughly 1 month.
The whole thing still doesn’t port nicely. I did some hacks. Most components port ok but still something is not there.
What I mean to say is that linux (or unix in general) is not free at all. Instead of paying it with money (M$ approach) you pay it in time.

I don’t think there’s an accountable source on linux GL programming.

hello,

speaking about books, the third edition of the “OpenGL Superbible” has a whole chapter about Linux. (approximately 60 pages).
I have not read them jet, but from skipping through the pages it seems exactly what you are looking for.
-Roman.

Originally posted by <Roman>:
third edition of the “OpenGL Superbible” has a whole chapter about Linux.
Good to know. Too bad I have 2nd edition.
I don’t think I would find it too useful however.

just a small example…it’s always the same:

  1. open a display
  2. get root window id
  3. select a visual with special attributes (here, single-buffered rgba)
  4. create a glx context
  5. create a colormap
  6. create your window
  7. make glx context current
  8. start event loop

you’ll see that linux is in some ways very similar to windows. or windows to linux.

#include<X11/Xlib.h>
#include<GL/glx.h>
#include<GL/glu.h>

Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);
GLint att[] = {GLX_RGBA, None};
XVisualInfo *vi = glXChooseVisual(dpy, 0, att);
GLXContext glc = glXCreateContext(dpy, vi, NULL, False);
Visual *vis = DefaultVisual(dpy, 0);
Colormap cmap = XCreateColormap(dpy, root, vis, AllocNone);
unsigned int w = XDisplayWidth(dpy, 0) / 2;
unsigned int h = XDisplayHeight(dpy, 0) / 2;
int dep = DefaultDepth(dpy, 0);
int cmask = CWColormap | CWBorderPixel | CWEventMask;
int emask = ExposureMask;
XEvent xev;
XSetWindowAttributes swa;
XWindowAttributes gwa;
Window win;

int main(int argc, char *argv[]){

swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = emask;
win = XCreateWindow(dpy, root, 0, 0, 400, 400, 0, dep, InputOutput, vis, cmask, &swa);
XStoreName(dpy, win, “SIMPLE GL QUAD”);
XMapWindow(dpy, win);

glXMakeCurrent(dpy, win, glc);
glClearColor(0.00, 0.00, 0.60, 1.00);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1., 1., -1., 1., 1., 100.);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);

while(1) {
XNextEvent(dpy, &xev);

if(xev.type == Expose) {

	XGetWindowAttributes(dpy, win, &gwa);
	w = gwa.width;
	h = gwa.height;

	glViewport(0, 0, w, h);
	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_QUADS);
	 glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
	 glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
	 glColor3f(0., 0., 1.); glVertex3f( .75,  .75, 0.);
	 glColor3f(1., 1., 0.); glVertex3f(-.75,  .75, 0.);
	glEnd();

	glFlush(); } } }

//
// gcc -I/usr/X11R6/include/ -L/usr/X11R6/lib -o Quad Quad.cc -lX11 -lGL -lGLU
//

by the way: some poeple like books, but to me there is nothing as good as well-installed linux man pages. if you find all functions i used in the above example, you’re ready to go.