trouble with GLX exmple code

  • Follow


I'm trying to make sense how OpenGL works on X Window System.
Compiling example program I got error at glXChooseVisual() call.
This error persists on different Unix clones and hardware configurations.
glxinfo program prints the following table where required mode is present.
   visual  x  bf lv rg d st colorbuffer ax dp st accumbuffer  ms  cav
 id dep cl sp sz l  ci b ro  r  g  b  a bf th cl  r  g  b  a ns b eat
----------------------------------------------------------------------
0x22 24 tc  0 24  0 r  y  .  8  8  8  0  0 16  0  0  0  0  0  0 0 None
0x23 24 tc  0 24  0 r  y  .  8  8  8  0  0 16  8 16 16 16  0  0 0 None
0x24 24 tc  0 32  0 r  y  .  8  8  8  8  0 16  8 16 16 16 16  0 0 None
0x25 24 tc  0 32  0 r  .  .  8  8  8  8  0 16  8 16 16 16 16  0 0 None

Can you explain what's wrong with following code:

/*
 * Example of an X Window System OpenGL program.
 * OpenGL code is taken from auxdemo.c in the Win32 SDK
 */
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>

/* X globals, defines, and prototypes */
Display *dpy;
Window glwin;
static int attributes[] = {GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};

.....

int
main(int argc, char **argv)
{
    XVisualInfo    *vi;
    Colormap        cmap;
    XSetWindowAttributes swa;
    GLXContext      cx;
    XEvent          event;
    GLboolean       needRedraw = GL_FALSE, recalcModelView = GL_TRUE;
    int             dummy;


    dpy = XOpenDisplay(NULL);
    if (dpy == NULL){
        fprintf(stderr, "could not open display\n");
        return 1;
    }

    if(!glXQueryExtension(dpy, &dummy, &dummy)){
        fprintf(stderr, "could not open display");
        return 1;
    }

    /* find an OpenGL-capable Color Index visual with depth buffer */
    vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributes);
    if (vi == NULL) {
        fprintf(stderr, "could not get visual\n");

        return 1;
    }

    .......
}


0
Reply chupeev 8/9/2006 3:53:47 PM

chupeev alexander wrote:

> I'm trying to make sense how OpenGL works on X Window System.
> Compiling example program I got error at glXChooseVisual() call.
> This error persists on different Unix clones and hardware configurations.
> glxinfo program prints the following table where required mode is present.
>    visual  x  bf lv rg d st colorbuffer ax dp st accumbuffer  ms  cav
>  id dep cl sp sz l  ci b ro  r  g  b  a bf th cl  r  g  b  a ns b eat
> ----------------------------------------------------------------------
> 0x22 24 tc  0 24  0 r  y  .  8  8  8  0  0 16  0  0  0  0  0  0 0 None
> 0x23 24 tc  0 24  0 r  y  .  8  8  8  0  0 16  8 16 16 16  0  0 0 None
> 0x24 24 tc  0 32  0 r  y  .  8  8  8  8  0 16  8 16 16 16 16  0 0 None
> 0x25 24 tc  0 32  0 r  .  .  8  8  8  8  0 16  8 16 16 16 16  0 0 None
> 
> Can you explain what's wrong with following code:
<snip snip snip>
> static int attributes[] = {GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
> 
<snip snip snip>
> 
>     /* find an OpenGL-capable Color Index visual with depth buffer */
>     vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributes);
<snip snip snip>

By default, if GLX_RGBA is not part of the attribute list, then 
glXChooseVisual will only return color-indexed visuals that fulfull your 
requirements.   Since there are no color-index visuals in your 
configuration, you get nothing back.

Jim Lahue
0
Reply Jim 8/9/2006 6:02:59 PM


Jim Lahue wrote in message
> By default, if GLX_RGBA is not part of the attribute list, then
> glXChooseVisual will only return color-indexed visuals that fulfull your
> requirements.   Since there are no color-index visuals in your
> configuration, you get nothing back.

The example program works for now. Thank you very much, Jim.


0
Reply chupeev 8/9/2006 11:54:17 PM

2 Replies
144 Views

(page loaded in 0.043 seconds)

3/16/2013 8:36:43 AM


Reply: