glXGetCurrentContext seems to be broken


Subject: glXGetCurrentContext seems to be broken
From: Stephen Lewis (lewis@napanet.net)
Date: Sun Sep 02 2001 - 17:19:45 MDT


Using stock YDL 2.0 after creating a valid OpenGL context
'glXGetCurrentContext' stubbornly insists on returning NULL.
This seems to be a problem in the Mesa OpenGL code maybe in
XFree86-4.0.2/xc/lib/GL/glx/glxext.c
To whom should this be directed? and is there a fix?
thx,
Stephen Lewis
attached is a short program with the problem

/* Copyright (c) 2001 Stephen Lewis */
/* modified 02-Sep-2001 */
/*

  Illustrates a problem with OpenGL context
  comments please to 'lewis@napanet.net'

gcc -O2 -Wall -c -o glxtest.o ./glxtest.c
gcc -O2 -Wall -lGL -lm -o glxtest ./glxtest.o
./glxtest

*/

/*
 * took parts from glx demo sources by
 * Brian Paul
 */

#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glx.h>

static void redraw( Display *dpy, Window w )
{
   glClear( GL_COLOR_BUFFER_BIT );
   glXSwapBuffers( dpy, w );
}

static void resize( unsigned int width, unsigned int height )
{
   glViewport( 0, 0, width, height );
}

static Window make_rgb_db_window( Display *dpy,
                                  unsigned int width, unsigned int height )
{
   int attrib[] = { GLX_RGBA,
                    GLX_RED_SIZE, 1,
                    GLX_GREEN_SIZE, 1,
                    GLX_BLUE_SIZE, 1,
                    GLX_DOUBLEBUFFER,
                    None };
   int scrnum;
   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   Window win;
   GLXContext ctx;
   XVisualInfo *visinfo;

   scrnum = DefaultScreen( dpy );
   root = RootWindow( dpy, scrnum );

   visinfo = glXChooseVisual( dpy, scrnum, attrib );
   if (!visinfo) {
      printf("SL_Test: couldn't get an RGB, Double-buffered visual\n");
      exit(1);
   }

   /* window attributes */
   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;

   win = XCreateWindow( dpy, root, 0, 0, width, height,
                        0, visinfo->depth, InputOutput,
                        visinfo->visual, mask, &attr );

   if (!win) {
      printf("SL_Test: XCreateWindow failed\n");
      exit(1);
   }

   ctx = glXCreateContext( dpy, visinfo, NULL, True );

   if (!ctx) {
      printf("SL_Test: glXCreateContext failed\n");
      exit(1);
   }

  if (!glXGetCurrentContext()) {
        printf("SL_Test: glXGetCurrentContext returns NULL\n");
        printf("SL_Test: This is incorrect\n");
  };

   if (!glXMakeCurrent( dpy, win, ctx )) {
      printf("SL_Test: glXMakeCurrent failed\n");
      exit(1);
   }

  if (!glXGetCurrentContext()) {
        printf("SL_Test: glXGetCurrentContext returns NULL\n");
        printf("SL_Test: This is incorrect\n");
  };

   return win;
}

static void event_loop( Display *dpy )
{
   XEvent event;

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

      switch (event.type) {
         case Expose:
            redraw( dpy, event.xany.window );
            break;
         case ConfigureNotify:
            resize( event.xconfigure.width, event.xconfigure.height );
            break;
         case KeyPress:
            exit(0); /* any key quits */
      }
   }
}

int main( int argc, char *argv[] )
{
   Display *dpy;
   Window win;

   dpy = XOpenDisplay(NULL);

   win = make_rgb_db_window( dpy, 300, 300 );

   glShadeModel( GL_FLAT );
   glClearColor( 1.0, 0.5, 0.0, 1.0 );

   XMapWindow( dpy, win );

   event_loop( dpy );
   return 0;
}



This archive was generated by hypermail 2a24 : Sun Sep 02 2001 - 17:19:53 MDT