home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / porting / glXIntro.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  1.3 KB  |  54 lines

  1. #include <GL/glx.h>
  2. #include <GL/gl.h>
  3.  
  4. static int attributeList[] = { GLX_RGBA, None };
  5.  
  6. static Bool WaitForNotify(Display *d, XEvent *e, char *arg) {
  7.     return (e->type == MapNotify) && (e->xmap.window ==    (Window)arg);
  8. }
  9.  
  10. int main(int argc, char    **argv)    {
  11.     Display *dpy;
  12.     XVisualInfo    *vi;
  13.     Colormap cmap;
  14.     XSetWindowAttributes swa;
  15.     Window win;
  16.     GLXContext cx;
  17.     XEvent event;
  18.  
  19.     /* get a connection    */
  20.     dpy    = XOpenDisplay(0);
  21.  
  22.     /* get an appropriate visual */
  23.     vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
  24.  
  25.     /* create a    GLX context */
  26.     cx = glXCreateContext(dpy, vi, 0, GL_FALSE);
  27.  
  28.     /* create a    colormap */
  29.     cmap = XCreateColormap(dpy,    RootWindow(dpy,    vi->screen),
  30.                vi->visual, AllocNone);
  31.  
  32.     /* create a    window */
  33.     swa.colormap = cmap;
  34.     swa.border_pixel = 0;
  35.     swa.event_mask = StructureNotifyMask;
  36.     win    = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,    100, 100,
  37.             0, vi->depth, InputOutput, vi->visual,
  38.             CWBorderPixel|CWColormap|CWEventMask, &swa);
  39.     XMapWindow(dpy, win);
  40.     XIfEvent(dpy, &event, WaitForNotify, (char*)win);
  41.  
  42.     /* connect the context to the window */
  43.     glXMakeCurrent(dpy,    win, cx);
  44.  
  45.     /* clear the buffer    */
  46.     glClearColor(1,1,0,1);
  47.     glClear(GL_COLOR_BUFFER_BIT);
  48.     glFlush();
  49.  
  50.     /* wait a while */
  51.     sleep(100);
  52. }
  53.  
  54.