Standard openGL program does not run on linux

I’m porting a code from IRIX-gl to openGL and used standard examples iobounce.c and zrgb.c from http://techpubs.sgi.com/library/tpl/cgi-…i_html/apf.html

I compiled using
gcc zrgb.c -lGL -lGLU -lX11 -lm -L/usr/X11R6/lib -o zrgb

To my surprise, zrgb.c is running fine on linux, but iobounce.c gives the error “could’nt get visual”, even though it did compile without error and it does run happily on SG-unix.

How can this be? What do I do to get iobounce running?

Cannot get visual occurs when the requested display attributes are not available. So for example asking for double buffered 8 bit rgb and 24 bit z and 8 bit stencil for example may not have an equivalent visual format on your X server.

In irisgl the calls are winopen() and gconfig() (ahh life used to be simple) with requested attributes in between. It looks like iobounce simply requests double buffering and relies on defaults for the rest. What attributes does that port to…?

Looking at the GLX code it generates you have:

static int attributeList[] = { GLX_DOUBLEBUFFER,
None };

vi = glXChooseVisual(dpy, DefaultScreen(dpy),
attributeList);

Asking for a double buffered nothing may be a problem :slight_smile:

So add a few attributes to that list. It’s best to rewrite this part of visual selection with fallbacks etc, because you need portability and visual config seems to be an unslayable bugbear. Tip requesting 1 bit of anything is a good way to wildcard stuff like zbuffer size (although it may not be the most efficient visual).

You can see that zrgb requests RGBA (i.e it asks for alpha) and has a fallback request to make sure it’s a bit more robust and asks for 1 bit of each attribute to maximize compatability, in addition to requesting color and zbuffer it falls back on single buffered rendering if the initial request fails. This is inherently more robust. I would suggest that you fall back to a visual with no destination alpha before defaulting to single buffered rendering.

static int attributeList[] = { GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 1,
None };
static int attributeList2[] = { GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 1,
None };

vi = glXChooseVisual(dpy, DefaultScreen(dpy),
attributeList);
if (vi == NULL) {
fprintf(stderr, "Unable to obtain visual
Doublebuffered visual
");
vi = glXChooseVisual(dpy, DefaultScreen(dpy),
attributeList2);
}

There are other ways to do this such as enumerating visuals and checking for suitability vs. your needs.

Either way this is your problem and the solution is obvious. Things will get much more interesting when you run your own code through this, alas tevbind we barely knew ye (and ofcourse they threw out the texbind baby with the bathwater on 1.0) …ancient history… irisgl was fun.

Thanks! This helps a lot, but it doesn’t yet solve the problem.

If I follow the suggestions, I get an X error “BadMatch (invalid parameter attributes)” on XCreateColormap, whether or not GLX_DOUBLEBUFFER is included in attributeList

In iobounce.c this is defined as

cmap = glXCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocAll)

but in zrbg.c it is

cmap = glXCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone)

The obvious try is thus to replace AllocAll in iobounce by AllocNone, but this creates problems with the color map (the yellow disk is white, and any value given in glIndexi() or glIndexf() gives white objects). When GLX_DOUBLEBUFFER is not included the program reacts very sluggish to mouse clicks and a flickering white disk jumps around very fast. Apparently the screen resolution is adapted by GLX_DOUBLEBUFFER.

Thus I removed GLX_RGBA from the attribute list. This gives a yellow sphere again, irrespective of AllocAll or AllocNone, but still if GLX_DOUBLEBUFFER is not included the program does not run properly.

So, how do I get around the double buffer sizes?

Well that’s a new problem you never mentioned before.

Just delete the color map calls and stick with RGB rendering. Color map is antiquated.

Forget about color index rendering, it will create problems with color index rendering but really you shouldn’t be worried about that. Focus on the app you are porting, these trivial examples are not the problems you should be worried about.

P.S. feel free to use glColor3f to set color instead of the index calls, you will be able to produce the appearance of the original rendering on an RGB visual.

Thanks a million!

I tried a few things along these lines and found out that the problem wasn’t in the double buffering but in the absence of GLX_RGBA in the attributeList. Including that, I changed all
glIndexf() commands into glColor3f().

This worked …
but then I ran into a font definition problem using
fontInfo = XLoadQueryFont(dpy, "-adobe-times-medium-r-normal–17-120-100-p-88-iso8859-1’);

Commenting out all string print commands the code now runs, but without text output in the visual.

… this I solved by typing in the command xlsfonts and thus reading off which fonts are installed on the machine.
Thanks for your help!

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