summaryrefslogtreecommitdiff
path: root/xc/extras/Mesa/xdemos
diff options
context:
space:
mode:
authordawes <dawes>2000-12-05 16:38:22 +0000
committerdawes <dawes>2000-12-05 16:38:22 +0000
commited6396cf921b6df825b582dab9df4a3f67418ed0 (patch)
tree4279867dc272b68dc53fc080b737541d3912dfbf /xc/extras/Mesa/xdemos
parent58103d5a6899a2af151b35ea4dcf05edab6b31d0 (diff)
Initial revision
Diffstat (limited to 'xc/extras/Mesa/xdemos')
-rw-r--r--xc/extras/Mesa/xdemos/.cvsignore18
-rw-r--r--xc/extras/Mesa/xdemos/Makefile.X1167
-rw-r--r--xc/extras/Mesa/xdemos/Makefile.am27
-rw-r--r--xc/extras/Mesa/xdemos/descrip.mms79
-rw-r--r--xc/extras/Mesa/xdemos/glthreads.c420
-rw-r--r--xc/extras/Mesa/xdemos/glxdemo.c139
-rw-r--r--xc/extras/Mesa/xdemos/glxheads.c286
-rw-r--r--xc/extras/Mesa/xdemos/glxinfo.c532
-rw-r--r--xc/extras/Mesa/xdemos/glxpixmap.c186
-rw-r--r--xc/extras/Mesa/xdemos/manywin.c289
-rw-r--r--xc/extras/Mesa/xdemos/offset.c323
-rw-r--r--xc/extras/Mesa/xdemos/shape.c384
-rw-r--r--xc/extras/Mesa/xdemos/vgears.c282
-rw-r--r--xc/extras/Mesa/xdemos/vindex.c66
-rw-r--r--xc/extras/Mesa/xdemos/vtest.c83
-rw-r--r--xc/extras/Mesa/xdemos/wincopy.c270
-rw-r--r--xc/extras/Mesa/xdemos/xdemo.c355
-rw-r--r--xc/extras/Mesa/xdemos/xfont.c207
18 files changed, 4013 insertions, 0 deletions
diff --git a/xc/extras/Mesa/xdemos/.cvsignore b/xc/extras/Mesa/xdemos/.cvsignore
new file mode 100644
index 000000000..a745dcd65
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/.cvsignore
@@ -0,0 +1,18 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.lo
+*.o
+glthreads
+glxdemo
+glxdpyinfo
+glxheads
+glxinfo
+glxpixmap
+manywin
+offset
+shape
+wincopy
+xdemo
+xfont
diff --git a/xc/extras/Mesa/xdemos/Makefile.X11 b/xc/extras/Mesa/xdemos/Makefile.X11
new file mode 100644
index 000000000..a5137dbd7
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/Makefile.X11
@@ -0,0 +1,67 @@
+# $Id: Makefile.X11,v 1.1 2000/12/05 16:38:37 dawes Exp $
+
+# Mesa 3-D graphics library
+# Version: 3.3
+# Copyright (C) 1995-2000 Brian Paul
+
+# Makefile for non-GLUT (X11, SVGA, etc) demo programs
+
+
+##### MACROS #####
+
+INCDIR = ../include
+LIBDIR = ../lib
+
+GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL $(APP_LIB_DEPS)
+
+LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
+
+PROGS = glthreads \
+ glxdemo \
+ glxheads \
+ glxinfo \
+ glxpixmap \
+ manywin \
+ offset \
+ wincopy \
+ xdemo \
+ xfont
+
+
+
+##### RULES #####
+
+.SUFFIXES:
+.SUFFIXES: .c
+
+.c: $(LIB_DEP)
+ $(CC) -I$(INCDIR) $(CFLAGS) $< $(GL_LIBS) -o $@
+
+
+
+##### TARGETS #####
+
+default:
+ @echo "Specify a target configuration"
+
+clean:
+ -rm *.o *~
+
+realclean:
+ -rm $(PROGS)
+ -rm *.o *~
+
+targets: $(PROGS)
+
+# execute all programs
+exec: $(PROGS)
+ @for prog in $(PROGS) ; \
+ do \
+ echo -n "Running $$prog ..." ; \
+ $$prog ; \
+ echo ; \
+ done
+
+
+include ../Make-config
+
diff --git a/xc/extras/Mesa/xdemos/Makefile.am b/xc/extras/Mesa/xdemos/Makefile.am
new file mode 100644
index 000000000..dcdfa1bc6
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/Makefile.am
@@ -0,0 +1,27 @@
+## Process this file with automake to produce Makefile.in
+
+#AUTOMAKE_OPTIONS = no-dependencies
+
+INCLUDES = -I$(top_srcdir)/include $(GLUT_CFLAGS) $(X_CFLAGS) $(SVGA_CFLAGS)
+
+if HAVE_SVGA
+SVGA_PROG = vgears vindex vtest
+endif
+
+EXTRA_PROGRAMS = shape xfont
+
+check_PROGRAMS = glthreads glxdemo glxheads glxinfo glxpixmap manywin offset \
+ xdemo wincopy $(SVGA_PROG)
+
+LDADD = $(GLUT_LIBS) $(top_builddir)/src-glu/libGLU.la \
+ $(top_builddir)/src/libGL.la -lm
+LDFLAGS = -no-install
+
+# execute all programs
+exec: $(check_PROGRAMS)
+ @for prog in $(check_PROGRAMS); \
+ do \
+ echo -n "Running $$prog ..." ; \
+ ./$$prog ; \
+ echo ; \
+ done
diff --git a/xc/extras/Mesa/xdemos/descrip.mms b/xc/extras/Mesa/xdemos/descrip.mms
new file mode 100644
index 000000000..aa56c1cec
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/descrip.mms
@@ -0,0 +1,79 @@
+# Makefile for demo programs for VMS
+# contributed by Jouk Jansen joukj@crys.chem.uva.nl
+
+
+.first
+ define gl [-.include.gl]
+
+.include [-]mms-config.
+
+##### MACROS #####
+
+INCDIR = [-.include]
+CFLAGS = /include=$(INCDIR)/define=(FBIND=1)
+
+GL_LIBS = [-.lib]libMesaaux/l,libMesatk/l,libMesaGLU/l,libMesaGL/l,$(XLIBS)
+
+LIB_DEP = [-.lib]$(GL_LIB) [-.lib]$(GLU_LIB) [-.lib]$(TK_LIB) [-.lib]$(AUX_LIB)
+
+PROGS = bounce.exe;,gamma.exe;,gears.exe;,glxdemo.exe;,glxpixmap.exe;,\
+ isosurf.exe;,offset.exe;,osdemo.exe;,spin.exe;,test0.exe;,\
+ texobj.exe;,xdemo.exe;,reflect.exe;,winpos.exe;
+
+
+
+##### RULES #####
+
+
+##### TARGETS #####
+default :
+ mms $(PROGS)
+
+clean :
+ delete *.obj;*
+
+realclean :
+ delete $(PROGS)
+ delete *.obj;*
+
+bounce.exe; : bounce.obj $(LIB_DEP)
+ link bounce,$(GL_LIBS)
+
+gamma.exe; : gamma.obj $(LIB_DEP)
+ link gamma,$(GL_LIBS)
+
+gears.exe; : gears.obj $(LIB_DEP)
+ link gears,$(GL_LIBS)
+
+glxdemo.exe; : glxdemo.obj $(LIB_DEP)
+ link glxdemo,$(GL_LIBS)
+
+glxpixmap.exe; : glxpixmap.obj $(LIB_DEP)
+ link glxpixmap,$(GL_LIBS)
+
+isosurf.exe; : isosurf.obj $(LIB_DEP)
+ link isosurf,$(GL_LIBS)
+
+offset.exe; : offset.obj $(LIB_DEP)
+ link offset,$(GL_LIBS)
+
+osdemo.exe; : osdemo.obj $(LIB_DEP)
+ link osdemo,$(GL_LIBS)
+
+spin.exe; : spin.obj $(LIB_DEP)
+ link spin,$(GL_LIBS)
+
+test0.exe; : test0.obj $(LIB_DEP)
+ link test0,$(GL_LIBS)
+
+texobj.exe; : texobj.obj $(LIB_DEP)
+ link texobj,$(GL_LIBS)
+
+xdemo.exe; : xdemo.obj $(LIB_DEP)
+ link xdemo,$(GL_LIBS)
+
+reflect.exe; : reflect.obj $(LIB_DEP)
+ link reflect,$(GL_LIBS)
+
+winpos.exe; : winpos.obj $(LIB_DEP)
+ link winpos,$(GL_LIBS)
diff --git a/xc/extras/Mesa/xdemos/glthreads.c b/xc/extras/Mesa/xdemos/glthreads.c
new file mode 100644
index 000000000..c22cd8dda
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/glthreads.c
@@ -0,0 +1,420 @@
+/* $Id: glthreads.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Copyright (C) 2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * This program tests GLX thread safety.
+ * Command line options:
+ * -n <num threads> Number of threads to create (default is 2)
+ * -display <display name> Specify X display (default is :0.0)
+ *
+ * Brian Paul 20 July 2000
+ */
+
+
+#if defined(PTHREADS) /* defined by Mesa on Linux and other platforms */
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthread.h>
+
+
+/*
+ * Each window/thread/context:
+ */
+struct winthread {
+ Display *Dpy;
+ int Index;
+ pthread_t Thread;
+ Window Win;
+ GLXContext Context;
+ float Angle;
+ int WinWidth, WinHeight;
+ GLboolean NewSize;
+};
+
+
+#define MAX_WINTHREADS 100
+static struct winthread WinThreads[MAX_WINTHREADS];
+static int NumWinThreads = 0;
+static GLboolean ExitFlag = GL_FALSE;
+
+
+
+static void
+Error(const char *msg)
+{
+ fprintf(stderr, "Error: %s\n", msg);
+ exit(1);
+}
+
+
+/* draw a colored cube */
+static void
+draw_object(void)
+{
+ glPushMatrix();
+ glScalef(0.75, 0.75, 0.75);
+
+ glColor3f(1, 0, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(1, -1, -1);
+ glVertex3f(1, 1, -1);
+ glVertex3f(1, 1, 1);
+ glVertex3f(1, -1, 1);
+ glEnd();
+
+ glColor3f(0, 1, 1);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, -1);
+ glVertex3f(-1, 1, -1);
+ glVertex3f(-1, 1, 1);
+ glVertex3f(-1, -1, 1);
+ glEnd();
+
+ glColor3f(0, 1, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, 1, -1);
+ glVertex3f( 1, 1, -1);
+ glVertex3f( 1, 1, 1);
+ glVertex3f(-1, 1, 1);
+ glEnd();
+
+ glColor3f(1, 0, 1);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, -1);
+ glVertex3f( 1, -1, -1);
+ glVertex3f( 1, -1, 1);
+ glVertex3f(-1, -1, 1);
+ glEnd();
+
+ glColor3f(0, 0, 1);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, 1);
+ glVertex3f( 1, -1, 1);
+ glVertex3f( 1, 1, 1);
+ glVertex3f(-1, 1, 1);
+ glEnd();
+
+ glColor3f(1, 1, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, -1);
+ glVertex3f( 1, -1, -1);
+ glVertex3f( 1, 1, -1);
+ glVertex3f(-1, 1, -1);
+ glEnd();
+ glPopMatrix();
+}
+
+
+/* signal resize of given window */
+static void
+resize(struct winthread *wt, int w, int h)
+{
+ wt->NewSize = GL_TRUE;
+ wt->WinWidth = w;
+ wt->WinHeight = h;
+}
+
+
+/*
+ * We have an instance of this for each thread.
+ */
+static void
+draw_loop(struct winthread *wt)
+{
+ while (!ExitFlag) {
+
+ glXMakeCurrent(wt->Dpy, wt->Win, wt->Context);
+
+ glEnable(GL_DEPTH_TEST);
+
+ if (wt->NewSize) {
+ GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight;
+ glViewport(0, 0, wt->WinWidth, wt->WinHeight);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-w, w, -1.0, 1.0, 1.5, 10);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0, 0, -2.5);
+ wt->NewSize = GL_FALSE;
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(wt->Angle, 0, 0, 1);
+ glRotatef(wt->Angle, 1, 0, 0);
+ glScalef(0.7, 0.7, 0.7);
+ draw_object();
+ glPopMatrix();
+
+ glXSwapBuffers(wt->Dpy, wt->Win);
+
+ wt->Angle += 1.0;
+ }
+}
+
+
+/*
+ * The main process thread runs this loop.
+ */
+static void
+event_loop(Display *dpy)
+{
+ while (!ExitFlag) {
+ static long mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ XEvent event;
+ int i;
+
+ for (i = 0; i < NumWinThreads; i++) {
+ struct winthread *wt = &WinThreads[i];
+ while (XCheckWindowEvent(dpy, wt->Win, mask, &event)) {
+ if (event.xany.window == wt->Win) {
+ switch (event.type) {
+ case ConfigureNotify:
+ resize(wt, event.xconfigure.width,
+ event.xconfigure.height);
+ break;
+ case KeyPress:
+ /* tell all threads to exit */
+ ExitFlag = GL_TRUE;
+ /*printf("exit draw_loop %d\n", wt->Index);*/
+ return;
+ default:
+ /*no-op*/ ;
+ }
+ }
+ else {
+ printf("window mismatch\n");
+ }
+ }
+ }
+ }
+}
+
+
+/*
+ * we'll call this once for each thread, before the threads are created.
+ */
+static void
+create_window(struct winthread *wt)
+{
+ Window win;
+ GLXContext ctx;
+ int attrib[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DEPTH_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None };
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ XVisualInfo *visinfo;
+ int width = 80, height = 80;
+ int xpos = (wt->Index % 10) * 90;
+ int ypos = (wt->Index / 10) * 100;
+
+ scrnum = DefaultScreen(wt->Dpy);
+ root = RootWindow(wt->Dpy, scrnum);
+
+ visinfo = glXChooseVisual(wt->Dpy, scrnum, attrib);
+ if (!visinfo) {
+ Error("Unable to find RGB, Z, double-buffered visual");
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(wt->Dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow(wt->Dpy, root, xpos, ypos, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr);
+ if (!win) {
+ Error("Couldn't create window");
+ }
+
+ {
+ XSizeHints sizehints;
+ sizehints.x = xpos;
+ sizehints.y = ypos;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(wt->Dpy, win, &sizehints);
+ XSetStandardProperties(wt->Dpy, win, "glthreads", "glthreads",
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+
+ ctx = glXCreateContext(wt->Dpy, visinfo, NULL, True);
+ if (!ctx) {
+ Error("Couldn't create GLX context");
+ }
+
+ XMapWindow(wt->Dpy, win);
+ XSync(wt->Dpy, 0);
+
+ /* save the info for this window/context */
+ wt->Win = win;
+ wt->Context = ctx;
+ wt->Angle = 0.0;
+ wt->WinWidth = width;
+ wt->WinHeight = height;
+ wt->NewSize = GL_TRUE;
+}
+
+
+/*
+ * Called by pthread_create()
+ */
+static void *
+thread_function(void *p)
+{
+ struct winthread *wt = (struct winthread *) p;
+ draw_loop(wt);
+ return NULL;
+}
+
+
+/*
+ * called before exit to wait for all threads to finish
+ */
+static void
+clean_up(void)
+{
+ int i;
+
+ /* wait for threads to finish */
+ for (i = 0; i < NumWinThreads; i++) {
+ pthread_join(WinThreads[i].Thread, NULL);
+ }
+
+ for (i = 0; i < NumWinThreads; i++) {
+ glXDestroyContext(WinThreads[i].Dpy, WinThreads[i].Context);
+ XDestroyWindow(WinThreads[i].Dpy, WinThreads[i].Win);
+ }
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+ char *displayName = ":0.0";
+ int numThreads = 2;
+ Display *dpy;
+ int i;
+ Status threadStat;
+
+ if (argc == 1) {
+ printf("threadgl: test of GL thread safety (any key = exit)\n");
+ printf("Usage:\n");
+ printf(" threadgl [-display dpyName] [-n numthreads]\n");
+ }
+ else {
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
+ displayName = argv[i + 1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) {
+ numThreads = atoi(argv[i + 1]);
+ if (numThreads < 1)
+ numThreads = 1;
+ else if (numThreads > MAX_WINTHREADS)
+ numThreads = MAX_WINTHREADS;
+ i++;
+ }
+ }
+ }
+
+ /*
+ * VERY IMPORTANT: call XInitThreads() before any other Xlib functions.
+ */
+ threadStat = XInitThreads();
+ if (threadStat) {
+ printf("XInitThreads() returned %d (success)\n", (int) threadStat);
+ }
+ else {
+ printf("XInitThreads() returned 0 (failure- this program may fail)\n");
+ }
+
+
+ dpy = XOpenDisplay(displayName);
+ if (!dpy) {
+ fprintf(stderr, "Unable to open display %s\n", displayName);
+ return -1;
+ }
+
+ NumWinThreads = numThreads;
+
+ /* Create the GLX windows and contexts */
+ for (i = 0; i < numThreads; i++) {
+ WinThreads[i].Dpy = dpy;
+ WinThreads[i].Index = i;
+ create_window(&WinThreads[i]);
+ }
+
+ /* Create the threads */
+ for (i = 0; i < numThreads; i++) {
+ pthread_create(&WinThreads[i].Thread, NULL, thread_function,
+ (void*) &WinThreads[i]);
+ printf("Created Thread %p\n", WinThreads[i].Thread);
+ }
+
+ event_loop(dpy);
+
+ clean_up();
+
+ XCloseDisplay(dpy);
+
+ return 0;
+}
+
+
+#else /* PTHREADS */
+
+
+#include <stdio.h>
+
+int
+main(int argc, char *argv[])
+{
+ printf("Sorry, this program wasn't compiled with PTHREADS defined.\n");
+ return 0;
+}
+
+
+#endif /* PTHREADS */
diff --git a/xc/extras/Mesa/xdemos/glxdemo.c b/xc/extras/Mesa/xdemos/glxdemo.c
new file mode 100644
index 000000000..8c0a764fb
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/glxdemo.c
@@ -0,0 +1,139 @@
+/* $Id: glxdemo.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+
+/*
+ * A demonstration of using the GLX functions. This program is in the
+ * public domain.
+ *
+ * Brian Paul
+ */
+
+
+/*
+ * $Log: glxdemo.c,v $
+ * Revision 1.1 2000/12/05 16:38:37 dawes
+ * Initial revision
+ *
+ * Revision 1.1.1.1 1999/08/19 00:55:43 jtg
+ * Imported sources
+ *
+ * Revision 3.0 1998/02/21 02:16:54 brianp
+ * initial rev
+ *
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+static void redraw( Display *dpy, Window w )
+{
+ printf("Redraw event\n");
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ glColor3f( 1.0, 1.0, 0.0 );
+ glRectf( -0.8, -0.8, 0.8, 0.8 );
+
+ glXSwapBuffers( dpy, w );
+}
+
+
+
+static void resize( unsigned int width, unsigned int height )
+{
+ printf("Resize event\n");
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
+}
+
+
+
+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("Error: 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;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( dpy, root, 0, 0, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr );
+
+ ctx = glXCreateContext( dpy, visinfo, NULL, True );
+
+ glXMakeCurrent( dpy, win, ctx );
+
+ 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;
+ }
+ }
+}
+
+
+
+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( 0.5, 0.5, 0.5, 1.0 );
+
+ XMapWindow( dpy, win );
+
+ event_loop( dpy );
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/glxheads.c b/xc/extras/Mesa/xdemos/glxheads.c
new file mode 100644
index 000000000..883e5ec7d
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/glxheads.c
@@ -0,0 +1,286 @@
+/* $Id: glxheads.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Exercise multiple GLX connections on multiple X displays.
+ * Direct GLX contexts are attempted first, then indirect.
+ * Each window will display a spinning green triangle.
+ *
+ * Copyright (C) 2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+
+/*
+ * Each display/window/context:
+ */
+struct head {
+ char DisplayName[1000];
+ Display *Dpy;
+ Window Win;
+ GLXContext Context;
+ float Angle;
+ char Renderer[1000];
+ char Vendor[1000];
+ char Version[1000];
+};
+
+
+#define MAX_HEADS 20
+static struct head Heads[MAX_HEADS];
+static int NumHeads = 0;
+
+
+static void
+Error(const char *display, const char *msg)
+{
+ fprintf(stderr, "Error on display %s - %s\n", display, msg);
+ exit(1);
+}
+
+
+static struct head *
+AddHead(const char *displayName)
+{
+ Display *dpy;
+ Window win;
+ GLXContext ctx;
+ 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;
+ XVisualInfo *visinfo;
+ int width = 300, height = 300;
+ int xpos = 10, ypos = 10;
+
+ if (NumHeads >= MAX_HEADS)
+ return NULL;
+
+ dpy = XOpenDisplay(displayName);
+ if (!dpy) {
+ Error(displayName, "Unable to open display");
+ return NULL;
+ }
+
+ scrnum = DefaultScreen(dpy);
+ root = RootWindow(dpy, scrnum);
+
+ visinfo = glXChooseVisual(dpy, scrnum, attrib);
+ if (!visinfo) {
+ Error(displayName, "Unable to find RGB, double-buffered visual");
+ return NULL;
+ }
+
+ /* 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) {
+ Error(displayName, "Couldn't create window");
+ return NULL;
+ }
+
+ {
+ XSizeHints sizehints;
+ sizehints.x = xpos;
+ sizehints.y = ypos;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, displayName, displayName,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+
+ ctx = glXCreateContext(dpy, visinfo, NULL, True);
+ if (!ctx) {
+ Error(displayName, "Couldn't create GLX context");
+ return NULL;
+ }
+
+ XMapWindow(dpy, win);
+
+ if (!glXMakeCurrent(dpy, win, ctx)) {
+ Error(displayName, "glXMakeCurrent failed");
+ printf("glXMakeCurrent failed in Redraw()\n");
+ return NULL;
+ }
+
+ /* save the info for this head */
+ {
+ struct head *h = &Heads[NumHeads];
+ strcpy(h->DisplayName, displayName);
+ h->Dpy = dpy;
+ h->Win = win;
+ h->Context = ctx;
+ h->Angle = 0.0;
+ strcpy(h->Version, (char *) glGetString(GL_VERSION));
+ strcpy(h->Vendor, (char *) glGetString(GL_VENDOR));
+ strcpy(h->Renderer, (char *) glGetString(GL_RENDERER));
+ NumHeads++;
+ return &Heads[NumHeads-1];
+ }
+
+}
+
+
+static void
+Redraw(struct head *h)
+{
+ if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
+ Error(h->DisplayName, "glXMakeCurrent failed");
+ printf("glXMakeCurrent failed in Redraw()\n");
+ return;
+ }
+
+ h->Angle += 1.0;
+
+ glShadeModel(GL_FLAT);
+ glClearColor(0.5, 0.5, 0.5, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* draw green triangle */
+ glColor3f(0.0, 1.0, 0.0);
+ glPushMatrix();
+ glRotatef(h->Angle, 0, 0, 1);
+ glBegin(GL_TRIANGLES);
+ glVertex2f(0, 0.8);
+ glVertex2f(-0.8, -0.7);
+ glVertex2f(0.8, -0.7);
+ glEnd();
+ glPopMatrix();
+
+ glXSwapBuffers(h->Dpy, h->Win);
+}
+
+
+
+static void
+Resize(const struct head *h, unsigned int width, unsigned int height)
+{
+ if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
+ Error(h->DisplayName, "glXMakeCurrent failed in Resize()");
+ return;
+ }
+ glFlush();
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+}
+
+
+
+static void
+EventLoop(void)
+{
+ while (1) {
+ int i;
+ for (i = 0; i < NumHeads; i++) {
+ struct head *h = &Heads[i];
+ while (XPending(h->Dpy) > 0) {
+ XEvent event;
+ XNextEvent(h->Dpy, &event);
+ if (event.xany.window == h->Win) {
+ switch (event.type) {
+ case Expose:
+ Redraw(h);
+ break;
+ case ConfigureNotify:
+ Resize(h, event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ return;
+ default:
+ /*no-op*/ ;
+ }
+ }
+ else {
+ printf("window mismatch\n");
+ }
+ }
+ Redraw(h);
+ }
+ usleep(1);
+ }
+}
+
+
+
+static void
+PrintInfo(const struct head *h)
+{
+ printf("Name: %s\n", h->DisplayName);
+ printf(" Display: 0x%x\n", h->Dpy);
+ printf(" Window: 0x%x\n", h->Win);
+ printf(" Context: 0x%x\n", h->Context);
+ printf(" GL_VERSION: %s\n", h->Version);
+ printf(" GL_VENDOR: %s\n", h->Vendor);
+ printf(" GL_RENDERER: %s\n", h->Renderer);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+ if (argc == 1) {
+ struct head *h;
+ printf("glxheads: exercise multiple GLX connections (any key = exit)\n");
+ printf("Usage:\n");
+ printf(" glxheads xdisplayname ...\n");
+ printf("Example:\n");
+ printf(" glxheads :0 mars:0 venus:1\n");
+ h = AddHead(":0");
+ if (h)
+ PrintInfo(h);
+ }
+ else {
+ for (i = 1; i < argc; i++) {
+ const char *name = argv[i];
+ struct head *h = AddHead(name);
+ if (h) {
+ PrintInfo(h);
+ }
+ }
+ }
+
+ EventLoop();
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/glxinfo.c b/xc/extras/Mesa/xdemos/glxinfo.c
new file mode 100644
index 000000000..3b827a214
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/glxinfo.c
@@ -0,0 +1,532 @@
+/* $Id: glxinfo.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * This program is a work-alike of the IRIX glxinfo program.
+ * Command line options:
+ * -t print wide table
+ * -v print verbose information
+ * -display DisplayName specify the X display to interogate
+ *
+ * Brian Paul 26 January 2000
+ */
+
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <string.h>
+
+
+typedef enum
+{
+ Normal,
+ Wide,
+ Verbose
+} InfoMode;
+
+
+struct visual_attribs
+{
+ /* X visual attribs */
+ int id;
+ int klass;
+ int depth;
+ int redMask, greenMask, blueMask;
+ int colormapSize;
+ int bitsPerRGB;
+
+ /* GL visual attribs */
+ int supportsGL;
+ int transparent;
+ int bufferSize;
+ int level;
+ int rgba;
+ int doubleBuffer;
+ int stereo;
+ int auxBuffers;
+ int redSize, greenSize, blueSize, alphaSize;
+ int depthSize;
+ int stencilSize;
+ int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
+ int numSamples, numMultisample;
+ int visualCaveat;
+};
+
+
+/*
+ * Print a list of extensions, with word-wrapping.
+ */
+static void
+print_extension_list(const char *ext)
+{
+ const char *indentString = " ";
+ const int indent = 4;
+ const int max = 79;
+ int width, i, j;
+
+ if (!ext || !ext[0])
+ return;
+
+ width = indent;
+ printf(indentString);
+ i = j = 0;
+ while (1) {
+ if (ext[j] == ' ' || ext[j] == 0) {
+ /* found end of an extension name */
+ const int len = j - i;
+ if (width + len > max) {
+ /* start a new line */
+ printf("\n");
+ width = indent;
+ printf(indentString);
+ }
+ /* print the extension name between ext[i] and ext[j] */
+ while (i < j) {
+ printf("%c", ext[i]);
+ i++;
+ }
+ /* either we're all done, or we'll continue with next extension */
+ width += len + 1;
+ if (ext[j] == 0) {
+ break;
+ }
+ else {
+ i++;
+ j++;
+ if (ext[j] == 0)
+ break;
+ printf(", ");
+ width += 2;
+ }
+ }
+ j++;
+ }
+ printf("\n");
+}
+
+
+static void
+print_screen_info(Display *dpy, int scrnum)
+{
+ Window win;
+ int attribSingle[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ None };
+ int attribDouble[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None };
+
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ GLXContext ctx;
+ XVisualInfo *visinfo;
+ int width = 100, height = 100;
+
+ root = RootWindow(dpy, scrnum);
+
+ visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
+ if (!visinfo) {
+ visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
+ if (!visinfo) {
+ fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
+ return;
+ }
+ }
+
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+ win = XCreateWindow(dpy, root, 0, 0, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr);
+
+ ctx = glXCreateContext( dpy, visinfo, NULL, True );
+ if (!ctx) {
+ fprintf(stderr, "Error: glXCreateContext failed\n");
+ XDestroyWindow(dpy, win);
+ return;
+ }
+
+ if (glXMakeCurrent(dpy, win, ctx)) {
+ const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
+ const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
+ const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
+ const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
+ const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
+ const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
+ const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
+ const char *glVendor = (const char *) glGetString(GL_VENDOR);
+ const char *glRenderer = (const char *) glGetString(GL_RENDERER);
+ const char *glVersion = (const char *) glGetString(GL_VERSION);
+ const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
+ const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
+ const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
+ printf("display: %s screen:%d\n", DisplayString(dpy), scrnum);
+ printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
+ printf("server glx vendor string: %s\n", serverVendor);
+ printf("server glx version string: %s\n", serverVersion);
+ printf("server glx extensions:\n");
+ print_extension_list(serverExtensions);
+ printf("client glx vendor string: %s\n", clientVendor);
+ printf("client glx version string: %s\n", clientVersion);
+ printf("client glx extensions:\n");
+ print_extension_list(clientExtensions);
+ printf("GLX extensions:\n");
+ print_extension_list(glxExtensions);
+ printf("OpenGL vendor string: %s\n", glVendor);
+ printf("OpenGL renderer string: %s\n", glRenderer);
+ printf("OpenGL version string: %s\n", glVersion);
+ printf("OpenGL extensions:\n");
+ print_extension_list(glExtensions);
+ printf("glu version: %s\n", gluVersion);
+ printf("glu extensions:\n");
+ print_extension_list(gluExtensions);
+ }
+ else {
+ fprintf(stderr, "Error: glXMakeCurrent failed\n");
+ }
+
+ glXDestroyContext(dpy, ctx);
+ XDestroyWindow(dpy, win);
+}
+
+
+static const char *
+visual_class_name(int cls)
+{
+ switch (cls) {
+ case StaticColor:
+ return "StaticColor";
+ case PseudoColor:
+ return "PseudoColor";
+ case StaticGray:
+ return "StaticGray";
+ case GrayScale:
+ return "GrayScale";
+ case TrueColor:
+ return "TrueColor";
+ case DirectColor:
+ return "DirectColor";
+ default:
+ return "";
+ }
+}
+
+
+static const char *
+visual_class_abbrev(int cls)
+{
+ switch (cls) {
+ case StaticColor:
+ return "sc";
+ case PseudoColor:
+ return "pc";
+ case StaticGray:
+ return "sg";
+ case GrayScale:
+ return "gs";
+ case TrueColor:
+ return "tc";
+ case DirectColor:
+ return "dc";
+ default:
+ return "";
+ }
+}
+
+
+static void
+get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
+ struct visual_attribs *attribs)
+{
+ const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
+
+ memset(attribs, 0, sizeof(struct visual_attribs));
+
+ attribs->id = vInfo->visualid;
+#if defined(__cplusplus) || defined(c_plusplus)
+ attribs->klass = vInfo->c_class;
+#else
+ attribs->klass = vInfo->class;
+#endif
+ attribs->depth = vInfo->depth;
+ attribs->redMask = vInfo->red_mask;
+ attribs->greenMask = vInfo->green_mask;
+ attribs->blueMask = vInfo->blue_mask;
+ attribs->colormapSize = vInfo->colormap_size;
+ attribs->bitsPerRGB = vInfo->bits_per_rgb;
+
+ if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
+ return;
+ glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
+ glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
+ glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
+ glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
+ glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
+ glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
+ glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
+ glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
+ glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
+ glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
+ glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
+ glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
+ glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
+ glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
+ glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
+ glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
+
+ /* transparent pixel value not implemented yet */
+ attribs->transparent = 0;
+
+ /* multisample tests not implemented yet */
+ attribs->numSamples = 0;
+ attribs->numMultisample = 0;
+
+#if defined(GLX_EXT_visual_rating)
+ if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
+ glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
+ }
+ else {
+ attribs->visualCaveat = GLX_NONE_EXT;
+ }
+#else
+ attribs->visualCaveat = 0;
+#endif
+}
+
+
+static void
+print_visual_attribs_verbose(const struct visual_attribs *attribs)
+{
+ printf("Visual ID: %x depth=%d class=%s\n",
+ attribs->id, attribs->depth, visual_class_name(attribs->klass));
+ printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
+ attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
+ attribs->doubleBuffer, attribs->stereo);
+ printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
+ attribs->redSize, attribs->greenSize,
+ attribs->blueSize, attribs->alphaSize);
+ printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
+ attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
+ printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
+ attribs->accumRedSize, attribs->accumGreenSize,
+ attribs->accumBlueSize, attribs->accumAlphaSize);
+ printf(" multiSample=%d multiSampleBuffers=%d\n",
+ attribs->numSamples, attribs->numMultisample);
+#ifdef GLX_EXT_visual_rating
+ if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
+ printf(" visualCaveat=None\n");
+ else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
+ printf(" visualCaveat=Slow\n");
+ else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
+ printf(" visualCaveat=Nonconformant\n");
+#endif
+ printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
+}
+
+
+static void
+print_visual_attribs_short_header(void)
+{
+ printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
+ printf(" id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n");
+ printf("----------------------------------------------------------------------\n");
+}
+
+
+static void
+print_visual_attribs_short(const struct visual_attribs *attribs)
+{
+ char *caveat;
+#ifdef GLX_EXT_visual_rating
+ if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
+ caveat = "None";
+ else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
+ caveat = "Slow";
+ else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
+ caveat = "Ncon";
+#else
+ caveat = "None";
+#endif
+
+ printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
+ attribs->id,
+ attribs->depth,
+ visual_class_abbrev(attribs->klass),
+ attribs->transparent,
+ attribs->bufferSize,
+ attribs->level,
+ attribs->rgba ? "r" : "c",
+ attribs->doubleBuffer ? "y" : ".",
+ attribs->stereo ? "y" : ".",
+ attribs->redSize, attribs->greenSize,
+ attribs->blueSize, attribs->alphaSize,
+ attribs->auxBuffers,
+ attribs->depthSize,
+ attribs->stencilSize
+ );
+
+ printf(" %2d %2d %2d %2d %2d %1d %s\n",
+ attribs->accumRedSize, attribs->accumGreenSize,
+ attribs->accumBlueSize, attribs->accumAlphaSize,
+ attribs->numSamples, attribs->numMultisample,
+ caveat
+ );
+}
+
+
+static void
+print_visual_attribs_long_header(void)
+{
+ printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
+ printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
+ printf("----------------------------------------------------------------------------------------------------\n");
+}
+
+
+static void
+print_visual_attribs_long(const struct visual_attribs *attribs)
+{
+ printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
+ attribs->id,
+ attribs->depth,
+ visual_class_name(attribs->klass),
+ attribs->transparent,
+ attribs->bufferSize,
+ attribs->level,
+ attribs->rgba ? "rgba" : "ci ",
+ attribs->doubleBuffer,
+ attribs->stereo,
+ attribs->redSize, attribs->greenSize,
+ attribs->blueSize, attribs->alphaSize
+ );
+
+ printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
+ attribs->auxBuffers,
+ attribs->depthSize,
+ attribs->stencilSize,
+ attribs->accumRedSize, attribs->accumGreenSize,
+ attribs->accumBlueSize, attribs->accumAlphaSize,
+ attribs->numSamples, attribs->numMultisample
+ );
+}
+
+
+static void
+print_visual_info(Display *dpy, int scrnum, InfoMode mode)
+{
+ XVisualInfo template;
+ XVisualInfo *visuals;
+ int numVisuals;
+ long mask;
+ int i;
+
+ /* get list of all visuals on this screen */
+ template.screen = scrnum;
+ mask = VisualScreenMask;
+ visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
+
+ if (mode == Verbose) {
+ for (i = 0; i < numVisuals; i++) {
+ struct visual_attribs attribs;
+ get_visual_attribs(dpy, &visuals[i], &attribs);
+ print_visual_attribs_verbose(&attribs);
+ }
+ }
+ else if (mode == Normal) {
+ print_visual_attribs_short_header();
+ for (i = 0; i < numVisuals; i++) {
+ struct visual_attribs attribs;
+ get_visual_attribs(dpy, &visuals[i], &attribs);
+ print_visual_attribs_short(&attribs);
+ }
+ }
+ else if (mode == Wide) {
+ print_visual_attribs_long_header();
+ for (i = 0; i < numVisuals; i++) {
+ struct visual_attribs attribs;
+ get_visual_attribs(dpy, &visuals[i], &attribs);
+ print_visual_attribs_long(&attribs);
+ }
+ }
+
+ XFree(visuals);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ char *displayName = ":0";
+ Display *dpy;
+ int numScreens, scrnum;
+ InfoMode mode = Normal;
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
+ displayName = argv[i + 1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-t") == 0) {
+ mode = Wide;
+ }
+ else if (strcmp(argv[i], "-v") == 0) {
+ mode = Verbose;
+ }
+ }
+
+ dpy = XOpenDisplay(displayName);
+ if (!dpy) {
+ fprintf(stderr, "Error: unable to open display %s\n", displayName);
+ return -1;
+ }
+
+ numScreens = ScreenCount(dpy);
+ for (scrnum = 0; scrnum < numScreens; scrnum++) {
+ print_screen_info(dpy, scrnum);
+ printf("\n");
+ print_visual_info(dpy, scrnum, mode);
+ if (scrnum + 1 < numScreens)
+ printf("\n\n");
+ }
+
+ XCloseDisplay(dpy);
+
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/glxpixmap.c b/xc/extras/Mesa/xdemos/glxpixmap.c
new file mode 100644
index 000000000..fac8beb10
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/glxpixmap.c
@@ -0,0 +1,186 @@
+/* $Id: glxpixmap.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+
+/*
+ * A demonstration of using the GLXPixmap functions. This program is in
+ * the public domain.
+ *
+ * Brian Paul
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+static GLXContext ctx;
+static XVisualInfo *visinfo;
+static GC gc;
+
+
+
+static Window make_rgb_window( Display *dpy,
+ unsigned int width, unsigned int height )
+{
+ const int sbAttrib[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ None };
+ const int dbAttrib[] = { 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;
+
+ scrnum = DefaultScreen( dpy );
+ root = RootWindow( dpy, scrnum );
+
+ visinfo = glXChooseVisual( dpy, scrnum, (int *) sbAttrib );
+ if (!visinfo) {
+ visinfo = glXChooseVisual( dpy, scrnum, (int *) dbAttrib );
+ if (!visinfo) {
+ printf("Error: couldn't get an RGB visual\n");
+ exit(1);
+ }
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ /* TODO: share root colormap if possible */
+ attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow( dpy, root, 0, 0, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr );
+
+ /* make an X GC so we can do XCopyArea later */
+ gc = XCreateGC( dpy, win, 0, NULL );
+
+ /* need indirect context */
+ ctx = glXCreateContext( dpy, visinfo, NULL, False );
+ if (!ctx) {
+ printf("Error: glXCreateContext failed\n");
+ exit(-1);
+ }
+
+ printf("Direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
+
+ return win;
+}
+
+
+static GLXPixmap make_pixmap( Display *dpy, Window win,
+ unsigned int width, unsigned int height,
+ Pixmap *pixmap)
+{
+ Pixmap pm;
+ GLXPixmap glxpm;
+ XWindowAttributes attr;
+
+ pm = XCreatePixmap( dpy, win, width, height, visinfo->depth );
+ if (!pm) {
+ printf("Error: XCreatePixmap failed\n");
+ exit(-1);
+ }
+
+ XGetWindowAttributes( dpy, win, &attr );
+
+ /*
+ * IMPORTANT:
+ * Use the glXCreateGLXPixmapMESA funtion when using Mesa because
+ * Mesa needs to know the colormap associated with a pixmap in order
+ * to render correctly. This is because Mesa allows RGB rendering
+ * into any kind of visual, not just TrueColor or DirectColor.
+ */
+#ifdef GLX_MESA_pixmap_colormap
+ if (strstr(glXQueryExtensionsString(dpy, 0), "GLX_MESA_pixmap_colormap")) {
+ /* stand-alone Mesa, specify the colormap */
+ glxpm = glXCreateGLXPixmapMESA( dpy, visinfo, pm, attr.colormap );
+ }
+ else {
+ glxpm = glXCreateGLXPixmap( dpy, visinfo, pm );
+ }
+#else
+ /* This will work with Mesa too if the visual is TrueColor or DirectColor */
+ glxpm = glXCreateGLXPixmap( dpy, visinfo, pm );
+#endif
+
+ if (!glxpm) {
+ printf("Error: GLXCreateGLXPixmap failed\n");
+ exit(-1);
+ }
+
+ *pixmap = pm;
+
+ return glxpm;
+}
+
+
+
+static void event_loop( Display *dpy, GLXPixmap pm )
+{
+ XEvent event;
+
+ while (1) {
+ XNextEvent( dpy, &event );
+
+ switch (event.type) {
+ case Expose:
+ printf("Redraw\n");
+ /* copy the image from GLXPixmap to window */
+ XCopyArea( dpy, pm, event.xany.window, /* src, dest */
+ gc, 0, 0, 300, 300, /* gc, src pos, size */
+ 0, 0 ); /* dest pos */
+ break;
+ case ConfigureNotify:
+ /* nothing */
+ break;
+ }
+ }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+ Display *dpy;
+ Window win;
+ Pixmap pm;
+ GLXPixmap glxpm;
+
+ dpy = XOpenDisplay(NULL);
+
+ win = make_rgb_window( dpy, 300, 300 );
+ glxpm = make_pixmap( dpy, win, 300, 300, &pm );
+
+ glXMakeCurrent( dpy, glxpm, ctx );
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+
+ /* Render an image into the pixmap */
+ glShadeModel( GL_FLAT );
+ glClearColor( 0.5, 0.5, 0.5, 1.0 );
+ glClear( GL_COLOR_BUFFER_BIT );
+ glViewport( 0, 0, 300, 300 );
+ glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
+ glColor3f( 0.0, 1.0, 1.0 );
+ glRectf( -0.75, -0.75, 0.75, 0.75 );
+ glFlush();
+
+ XMapWindow( dpy, win );
+
+ event_loop( dpy, pm );
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/manywin.c b/xc/extras/Mesa/xdemos/manywin.c
new file mode 100644
index 000000000..b81975760
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/manywin.c
@@ -0,0 +1,289 @@
+/* $Id: manywin.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Create N GLX windows/contexts and render to them in round-robin
+ * order.
+ *
+ * Copyright (C) 2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+/*
+ * Each display/window/context:
+ */
+struct head {
+ char DisplayName[1000];
+ Display *Dpy;
+ Window Win;
+ GLXContext Context;
+ float Angle;
+ char Renderer[1000];
+ char Vendor[1000];
+ char Version[1000];
+};
+
+
+#define MAX_HEADS 200
+static struct head Heads[MAX_HEADS];
+static int NumHeads = 0;
+
+
+static void
+Error(const char *display, const char *msg)
+{
+ fprintf(stderr, "Error on display %s - %s\n", display, msg);
+ exit(1);
+}
+
+
+static struct head *
+AddHead(const char *displayName, const char *name)
+{
+ Display *dpy;
+ Window win;
+ GLXContext ctx;
+ 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;
+ XVisualInfo *visinfo;
+ int width = 90, height = 90;
+ int xpos = 0, ypos = 0;
+
+ if (NumHeads >= MAX_HEADS)
+ return NULL;
+
+ dpy = XOpenDisplay(displayName);
+ if (!dpy) {
+ Error(displayName, "Unable to open display");
+ return NULL;
+ }
+
+ scrnum = DefaultScreen(dpy);
+ root = RootWindow(dpy, scrnum);
+
+ visinfo = glXChooseVisual(dpy, scrnum, attrib);
+ if (!visinfo) {
+ Error(displayName, "Unable to find RGB, double-buffered visual");
+ return NULL;
+ }
+
+ /* window attributes */
+ xpos = (NumHeads % 10) * 100;
+ ypos = (NumHeads / 10) * 100;
+ printf("%d, %d\n", xpos, ypos);
+ 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, xpos, ypos, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr);
+ if (!win) {
+ Error(displayName, "Couldn't create window");
+ return NULL;
+ }
+
+ {
+ XSizeHints sizehints;
+ sizehints.x = xpos;
+ sizehints.y = ypos;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+
+ ctx = glXCreateContext(dpy, visinfo, NULL, True);
+ if (!ctx) {
+ Error(displayName, "Couldn't create GLX context");
+ return NULL;
+ }
+
+ XMapWindow(dpy, win);
+
+ if (!glXMakeCurrent(dpy, win, ctx)) {
+ Error(displayName, "glXMakeCurrent failed");
+ printf("glXMakeCurrent failed in Redraw()\n");
+ return;
+ }
+
+ /* save the info for this head */
+ {
+ struct head *h = &Heads[NumHeads];
+ strcpy(h->DisplayName, name);
+ h->Dpy = dpy;
+ h->Win = win;
+ h->Context = ctx;
+ h->Angle = 0.0;
+ strcpy(h->Version, (char *) glGetString(GL_VERSION));
+ strcpy(h->Vendor, (char *) glGetString(GL_VENDOR));
+ strcpy(h->Renderer, (char *) glGetString(GL_RENDERER));
+ NumHeads++;
+ return &Heads[NumHeads-1];
+ }
+
+}
+
+
+static void
+Redraw(struct head *h)
+{
+ if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
+ Error(h->DisplayName, "glXMakeCurrent failed");
+ printf("glXMakeCurrent failed in Redraw()\n");
+ return;
+ }
+
+ h->Angle += 1.0;
+
+ glShadeModel(GL_FLAT);
+ glClearColor(0.5, 0.5, 0.5, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* draw green triangle */
+ glColor3f(0.0, 1.0, 0.0);
+ glPushMatrix();
+ glRotatef(h->Angle, 0, 0, 1);
+ glBegin(GL_TRIANGLES);
+ glVertex2f(0, 0.8);
+ glVertex2f(-0.8, -0.7);
+ glVertex2f(0.8, -0.7);
+ glEnd();
+ glPopMatrix();
+
+ glXSwapBuffers(h->Dpy, h->Win);
+}
+
+
+
+static void
+Resize(const struct head *h, unsigned int width, unsigned int height)
+{
+ if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) {
+ Error(h->DisplayName, "glXMakeCurrent failed in Resize()");
+ return;
+ }
+ glFlush();
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+}
+
+
+
+static void
+EventLoop(void)
+{
+ while (1) {
+ int i;
+ for (i = 0; i < NumHeads; i++) {
+ struct head *h = &Heads[i];
+ while (XPending(h->Dpy) > 0) {
+ XEvent event;
+ XNextEvent(h->Dpy, &event);
+ if (event.xany.window == h->Win) {
+ switch (event.type) {
+ case Expose:
+ Redraw(h);
+ break;
+ case ConfigureNotify:
+ Resize(h, event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ return;
+ default:
+ /*no-op*/ ;
+ }
+ }
+ else {
+ printf("window mismatch\n");
+ }
+ }
+ Redraw(h);
+ }
+ usleep(1);
+ }
+}
+
+
+
+static void
+PrintInfo(const struct head *h)
+{
+ printf("Name: %s\n", h->DisplayName);
+ printf(" Display: 0x%x\n", h->Dpy);
+ printf(" Window: 0x%x\n", h->Win);
+ printf(" Context: 0x%x\n", h->Context);
+ printf(" GL_VERSION: %s\n", h->Version);
+ printf(" GL_VENDOR: %s\n", h->Vendor);
+ printf(" GL_RENDERER: %s\n", h->Renderer);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+ if (argc == 1) {
+ struct head *h;
+ printf("manywin: open N simultaneous glx windows\n");
+ printf("Usage:\n");
+ printf(" manywin numWindows\n");
+ printf("Example:\n");
+ printf(" manywin 10\n");
+ return 0;
+ }
+ else {
+ int n = atoi(argv[1]);
+ printf("%d windows\n", n);
+ for (i = 0; i < n; i++) {
+ char name[100];
+ struct head *h;
+ sprintf(name, "%d", i);
+ h = AddHead(":0", name);
+ if (h) {
+ PrintInfo(h);
+ }
+ }
+ }
+
+ EventLoop();
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/offset.c b/xc/extras/Mesa/xdemos/offset.c
new file mode 100644
index 000000000..3e92e68da
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/offset.c
@@ -0,0 +1,323 @@
+/****************************************************************************
+Copyright 1995 by Silicon Graphics Incorporated, Mountain View, California.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Silicon Graphics not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+****************************************************************************/
+
+/*
+ * Derived from code written by Kurt Akeley, November 1992
+ *
+ * Uses PolygonOffset to draw hidden-line images. PolygonOffset
+ * shifts the z values of polygons an amount that is
+ * proportional to their slope in screen z. This keeps
+ * the lines, which are drawn without displacement, from
+ * interacting with their respective polygons, and
+ * thus eliminates line dropouts.
+ *
+ * The left image shows an ordinary antialiased wireframe image.
+ * The center image shows an antialiased hidden-line image without
+ * PolygonOffset.
+ * The right image shows an antialiased hidden-line image using
+ * PolygonOffset to reduce artifacts.
+ *
+ * Drag with a mouse button pressed to rotate the models.
+ * Press the escape key to exit.
+ */
+
+/*
+ * Modified for OpenGL 1.1 glPolygonOffset() conventions
+ */
+
+
+#include <GL/glx.h>
+#include <GL/glu.h>
+#include <X11/keysym.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#undef GL_EXT_polygon_offset /* use GL 1.1 version instead of extension */
+
+
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+#ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+#endif
+
+#define MAXQUAD 6
+
+typedef float Vertex[3];
+
+typedef Vertex Quad[4];
+
+/* data to define the six faces of a unit cube */
+Quad quads[MAXQUAD] = {
+ { {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0} },
+ { {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1} },
+ { {0,0,0}, {1,0,0}, {1,0,1}, {0,0,1} },
+ { {0,1,0}, {1,1,0}, {1,1,1}, {0,1,1} },
+ { {0,0,0}, {0,0,1}, {0,1,1}, {0,1,0} },
+ { {1,0,0}, {1,0,1}, {1,1,1}, {1,1,0} }
+};
+
+#define WIREFRAME 0
+#define HIDDEN_LINE 1
+
+static void error(const char* prog, const char* msg);
+static void cubes(int mx, int my, int mode);
+static void fill(Quad quad);
+static void outline(Quad quad);
+static void draw_hidden(Quad quad, int mode);
+static void process_input(Display *dpy, Window win);
+static int query_extension(char* extName);
+
+static int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None };
+
+static int dimension = 3;
+
+int main(int argc, char** argv) {
+ Display *dpy;
+ XVisualInfo *vi;
+ XSetWindowAttributes swa;
+ Window win;
+ GLXContext cx;
+
+ dpy = XOpenDisplay(0);
+ if (!dpy) error(argv[0], "can't open display");
+
+ vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
+ if (!vi) error(argv[0], "no suitable visual");
+
+ cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
+
+ swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
+ vi->visual, AllocNone);
+
+ swa.border_pixel = 0;
+ swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask |
+ ButtonPressMask | ButtonMotionMask;
+ win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 900, 300,
+ 0, vi->depth, InputOutput, vi->visual,
+ CWBorderPixel|CWColormap|CWEventMask, &swa);
+ XStoreName(dpy, win, "hiddenline");
+ XMapWindow(dpy, win);
+
+ glXMakeCurrent(dpy, win, cx);
+
+ /* check for the polygon offset extension */
+#ifndef GL_VERSION_1_1
+ if (!query_extension("GL_EXT_polygon_offset"))
+ error(argv[0], "polygon_offset extension is not available");
+#else
+ (void) query_extension;
+#endif
+
+ /* set up viewing parameters */
+ glMatrixMode(GL_PROJECTION);
+ gluPerspective(20, 1, 0.1, 20);
+ glMatrixMode(GL_MODELVIEW);
+ glTranslatef(0, 0, -15);
+
+ /* set other relevant state information */
+ glEnable(GL_DEPTH_TEST);
+
+#ifdef GL_EXT_polygon_offset
+ printf("using 1.0 offset extension\n");
+ glPolygonOffsetEXT( 1.0, 0.00001 );
+#else
+ printf("using 1.1 offset\n");
+ glPolygonOffset( 1.0, 0.5 );
+#endif
+
+ glShadeModel( GL_FLAT );
+ glDisable( GL_DITHER );
+
+ /* process events until the user presses ESC */
+ while (1) process_input(dpy, win);
+
+ return 0;
+}
+
+static void
+draw_scene(int mx, int my) {
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glTranslatef(-1.7, 0.0, 0.0);
+ cubes(mx, my, WIREFRAME);
+ glPopMatrix();
+
+ glPushMatrix();
+ cubes(mx, my, HIDDEN_LINE);
+ glPopMatrix();
+
+ glPushMatrix();
+ glTranslatef(1.7, 0.0, 0.0);
+#ifdef GL_EXT_polygon_offset
+ glEnable(GL_POLYGON_OFFSET_EXT);
+#else
+ glEnable(GL_POLYGON_OFFSET_FILL);
+#endif
+ cubes(mx, my, HIDDEN_LINE);
+#ifdef GL_EXT_polygon_offset
+ glDisable(GL_POLYGON_OFFSET_EXT);
+#else
+ glDisable(GL_POLYGON_OFFSET_FILL);
+#endif
+ glPopMatrix();
+}
+
+
+static void
+cubes(int mx, int my, int mode) {
+ int x, y, z, i;
+
+ /* track the mouse */
+ glRotatef(mx / 2.0, 0, 1, 0);
+ glRotatef(my / 2.0, 1, 0, 0);
+
+ /* draw the lines as hidden polygons */
+ glTranslatef(-0.5, -0.5, -0.5);
+ glScalef(1.0/dimension, 1.0/dimension, 1.0/dimension);
+ for (z = 0; z < dimension; z++) {
+ for (y = 0; y < dimension; y++) {
+ for (x = 0; x < dimension; x++) {
+ glPushMatrix();
+ glTranslatef(x, y, z);
+ glScalef(0.8, 0.8, 0.8);
+ for (i = 0; i < MAXQUAD; i++)
+ draw_hidden(quads[i], mode);
+ glPopMatrix();
+ }
+ }
+ }
+}
+
+static void
+fill(Quad quad) {
+ /* draw a filled polygon */
+ glBegin(GL_QUADS);
+ glVertex3fv(quad[0]);
+ glVertex3fv(quad[1]);
+ glVertex3fv(quad[2]);
+ glVertex3fv(quad[3]);
+ glEnd();
+}
+
+static void
+outline(Quad quad) {
+ /* draw an outlined polygon */
+ glBegin(GL_LINE_LOOP);
+ glVertex3fv(quad[0]);
+ glVertex3fv(quad[1]);
+ glVertex3fv(quad[2]);
+ glVertex3fv(quad[3]);
+ glEnd();
+}
+
+static void
+draw_hidden(Quad quad, int mode) {
+ if (mode == HIDDEN_LINE) {
+ glColor3f(0, 0, 0);
+ fill(quad);
+ }
+
+ /* draw the outline using white, optionally fill the interior with black */
+ glColor3f(1, 1, 1);
+ outline(quad);
+}
+
+static void
+process_input(Display *dpy, Window win) {
+ XEvent event;
+ static int prevx, prevy;
+ static int deltax = 90, deltay = 40;
+
+ do {
+ char buf[31];
+ KeySym keysym;
+
+ XNextEvent(dpy, &event);
+ switch(event.type) {
+ case Expose:
+ break;
+ case ConfigureNotify: {
+ /* this approach preserves a 1:1 viewport aspect ratio */
+ int vX, vY, vW, vH;
+ int eW = event.xconfigure.width, eH = event.xconfigure.height;
+ if (eW >= eH) {
+ vX = 0;
+ vY = (eH - eW) >> 1;
+ vW = vH = eW;
+ } else {
+ vX = (eW - eH) >> 1;
+ vY = 0;
+ vW = vH = eH;
+ }
+ glViewport(vX, vY, vW, vH);
+ }
+ break;
+ case KeyPress:
+ (void) XLookupString(&event.xkey, buf, sizeof(buf), &keysym, NULL);
+ switch (keysym) {
+ case XK_Escape:
+ exit(EXIT_SUCCESS);
+ default:
+ break;
+ }
+ case ButtonPress:
+ prevx = event.xbutton.x;
+ prevy = event.xbutton.y;
+ break;
+ case MotionNotify:
+ deltax += (event.xbutton.x - prevx); prevx = event.xbutton.x;
+ deltay += (event.xbutton.y - prevy); prevy = event.xbutton.y;
+ break;
+ default:
+ break;
+ }
+ } while (XPending(dpy));
+
+ draw_scene(deltax, deltay);
+ glXSwapBuffers(dpy, win);
+}
+
+static void
+error(const char *prog, const char *msg) {
+ fprintf(stderr, "%s: %s\n", prog, msg);
+ exit(EXIT_FAILURE);
+}
+
+static int
+query_extension(char* extName) {
+ char *p = (char *) glGetString(GL_EXTENSIONS);
+ char *end = p + strlen(p);
+ while (p < end) {
+ int n = strcspn(p, " ");
+ if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0))
+ return GL_TRUE;
+ p += (n + 1);
+ }
+ return GL_FALSE;
+}
+
diff --git a/xc/extras/Mesa/xdemos/shape.c b/xc/extras/Mesa/xdemos/shape.c
new file mode 100644
index 000000000..9e0885e5d
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/shape.c
@@ -0,0 +1,384 @@
+/* $Id: shape.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Example of using the X "shape" extension with OpenGL: render a spinning
+ * cube inside of a non-rectangular window.
+ *
+ * Press ESC to exit. Press up/down to change window shape.
+ *
+ * To compile add "shape" to the PROGS list in Makefile.
+ *
+ * Brian Paul
+ * June 16, 1997
+ *
+ * This program is in the public domain.
+ */
+
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+#include <X11/extensions/shape.h>
+#include <GL/glx.h>
+
+#ifndef PI
+#define PI 3.1415926
+#endif
+
+
+static int Width=500, Height=500;
+
+static float Xangle = 0.0, Yangle = 0.0;
+static int Redraw = 0;
+static int Sides = 5;
+static int MinSides = 3;
+static int MaxSides = 20;
+
+
+/*
+ * Draw the OpenGL stuff and do a SwapBuffers.
+ */
+static void display(Display *dpy, Window win)
+{
+ float scale = 1.7;
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+
+ glScalef(scale, scale, scale);
+ glRotatef(Xangle, 1.0, 0.0, 0.0);
+ glRotatef(Yangle, 0.0, 1.0, 0.0);
+
+ /*
+ * wireframe box
+ */
+ glColor3f(1.0, 1.0, 1.0);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(-1.0, -1.0, -1.0);
+ glVertex3f( 1.0, -1.0, -1.0);
+ glVertex3f( 1.0, 1.0, -1.0);
+ glVertex3f(-1.0, 1.0, -1.0);
+ glEnd();
+
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(-1.0, -1.0, 1.0);
+ glVertex3f( 1.0, -1.0, 1.0);
+ glVertex3f( 1.0, 1.0, 1.0);
+ glVertex3f(-1.0, 1.0, 1.0);
+ glEnd();
+
+ glBegin(GL_LINES);
+ glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, 1.0);
+ glVertex3f( 1.0, -1.0, -1.0); glVertex3f( 1.0, -1.0, 1.0);
+ glVertex3f( 1.0, 1.0, -1.0); glVertex3f( 1.0, 1.0, 1.0);
+ glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, 1.0);
+ glEnd();
+
+ /*
+ * Solid box
+ */
+ glPushMatrix();
+ glScalef(0.75, 0.75, 0.75);
+
+ glColor3f(1, 0, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(1, -1, -1);
+ glVertex3f(1, 1, -1);
+ glVertex3f(1, 1, 1);
+ glVertex3f(1, -1, 1);
+ glEnd();
+
+ glColor3f(0, 1, 1);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, -1);
+ glVertex3f(-1, 1, -1);
+ glVertex3f(-1, 1, 1);
+ glVertex3f(-1, -1, 1);
+ glEnd();
+
+ glColor3f(0, 1, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, 1, -1);
+ glVertex3f( 1, 1, -1);
+ glVertex3f( 1, 1, 1);
+ glVertex3f(-1, 1, 1);
+ glEnd();
+
+ glColor3f(1, 0, 1);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, -1);
+ glVertex3f( 1, -1, -1);
+ glVertex3f( 1, -1, 1);
+ glVertex3f(-1, -1, 1);
+ glEnd();
+
+ glColor3f(0, 0, 1);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, 1);
+ glVertex3f( 1, -1, 1);
+ glVertex3f( 1, 1, 1);
+ glVertex3f(-1, 1, 1);
+ glEnd();
+
+ glColor3f(1, 1, 0);
+ glBegin(GL_POLYGON);
+ glVertex3f(-1, -1, -1);
+ glVertex3f( 1, -1, -1);
+ glVertex3f( 1, 1, -1);
+ glVertex3f(-1, 1, -1);
+ glEnd();
+ glPopMatrix();
+
+
+ glPopMatrix();
+
+ glXSwapBuffers(dpy, win);
+}
+
+
+/*
+ * Called when no events are pending.
+ */
+static void idle(void)
+{
+ Xangle += 2.0;
+ Yangle += 3.3;
+ Redraw = 1;
+}
+
+
+/*
+ * This is called when we have to recompute the window shape bitmask.
+ * We just generate an n-sided regular polygon here but any other shape
+ * would be possible.
+ */
+static void make_shape_mask(Display *dpy, Window win, int width, int height,
+ int sides)
+{
+ Pixmap shapeMask;
+ XGCValues xgcv;
+ GC gc;
+
+ /* allocate 1-bit deep pixmap and a GC */
+ shapeMask = XCreatePixmap(dpy, win, width, height, 1);
+ gc = XCreateGC(dpy, shapeMask, 0, &xgcv);
+
+ /* clear shapeMask to zeros */
+ XSetForeground(dpy, gc, 0);
+ XFillRectangle(dpy, shapeMask, gc, 0, 0, width, height);
+
+ /* draw mask */
+ XSetForeground(dpy, gc, 1);
+ {
+ int cx = width / 2;
+ int cy = height / 2;
+ float angle = 0.0;
+ float step = 2.0 * PI / sides;
+ float radius = width / 2;
+ int i;
+ XPoint points[100];
+ for (i=0;i<sides;i++) {
+ int x = cx + radius * sin(angle);
+ int y = cy - radius * cos(angle);
+ points[i].x = x;
+ points[i].y = y;
+ angle += step;
+ }
+ XFillPolygon(dpy, shapeMask, gc, points, sides, Convex, CoordModeOrigin);
+ }
+
+ /* This is the only SHAPE extension call- simple! */
+ XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, shapeMask, ShapeSet);
+
+ XFreeGC(dpy, gc);
+ XFreePixmap(dpy, shapeMask);
+}
+
+
+/*
+ * Called when window is resized. Do OpenGL viewport and projection stuff.
+ */
+static void reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 3.0, 20.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+
+ glEnable(GL_DEPTH_TEST);
+}
+
+
+/*
+ * Process X events.
+ */
+static void event_loop(Display *dpy, Window win)
+{
+ while (1) {
+ XEvent event;
+ if (XPending(dpy)) {
+ XNextEvent(dpy, &event);
+ switch (event.type) {
+ case Expose:
+ display(dpy, event.xexpose.window);
+ break;
+ case ConfigureNotify:
+ Width = event.xconfigure.width;
+ Height = event.xconfigure.height,
+ make_shape_mask(dpy, win, Width, Height, Sides);
+ reshape(Width, Height);
+ break;
+ case KeyPress:
+ {
+ char buf[100];
+ KeySym keySym;
+ XComposeStatus stat;
+ XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
+ switch (keySym) {
+ case XK_Escape:
+ exit(0);
+ break;
+ case XK_Up:
+ Sides++;
+ if (Sides>MaxSides) Sides = MaxSides;
+ make_shape_mask(dpy, win, Width, Height, Sides);
+ break;
+ case XK_Down:
+ Sides--;
+ if (Sides<MinSides) Sides = MinSides;
+ make_shape_mask(dpy, win, Width, Height, Sides);
+ break;
+ }
+ }
+ break;
+ default:
+ ;;
+ }
+ }
+ else {
+ idle();
+ if (Redraw) {
+ display(dpy, win);
+ Redraw = 0;
+ }
+ }
+ }
+}
+
+
+/*
+ * Allocate a "nice" colormap. This could be better (HP-CR support, etc).
+ */
+static Colormap alloc_colormap(Display *dpy, Window parent, Visual *vis)
+{
+ Screen *scr = DefaultScreenOfDisplay(dpy);
+ int scrnum = DefaultScreen(dpy);
+
+ if (MaxCmapsOfScreen(scr)==1 && vis==DefaultVisual(dpy, scrnum)) {
+ /* The window and root are of the same visual type so */
+ /* share the root colormap. */
+ return DefaultColormap(dpy, scrnum);
+ }
+ else {
+ return XCreateColormap(dpy, parent, vis, AllocNone);
+ }
+}
+
+
+int main(int argc, char *argv[])
+{
+ static int glAttribs[] = {
+ GLX_DOUBLEBUFFER,
+ GLX_RGBA,
+ GLX_DEPTH_SIZE, 1,
+ None
+ };
+ Display *dpy;
+ XVisualInfo *visInfo;
+ int scrn;
+ Window root;
+ Colormap cmap;
+ Window win;
+ XSetWindowAttributes winAttribs;
+ unsigned long winAttribsMask;
+ GLXContext glCtx;
+ int ignore;
+ const char *name = "OpenGL in a Shaped Window";
+
+ dpy = XOpenDisplay(NULL);
+ if (!dpy) {
+ fprintf(stderr, "Couldn't open default display\n");
+ return 1;
+ }
+
+ /* check that we can use the shape extension */
+ if (!XQueryExtension(dpy, "SHAPE", &ignore, &ignore, &ignore )) {
+ fprintf(stderr, "Display doesn't support shape extension\n");
+ return 1;
+ }
+
+ scrn = DefaultScreen(dpy);
+
+ root = RootWindow(dpy, scrn);
+
+ visInfo = glXChooseVisual(dpy, scrn, glAttribs);
+ if (!visInfo) {
+ fprintf(stderr, "Couldn't get RGB, DB, Z visual\n");
+ return 1;
+ }
+
+ glCtx = glXCreateContext(dpy, visInfo, 0, True);
+ if (!glCtx) {
+ fprintf(stderr, "Couldn't create GL context\n");
+ return 1;
+ }
+
+ cmap = alloc_colormap(dpy, root, visInfo->visual);
+ if (!cmap) {
+ fprintf(stderr, "Couln't create colormap\n");
+ return 1;
+ }
+
+ winAttribs.border_pixel = 0;
+ winAttribs.colormap = cmap;
+ winAttribs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ winAttribsMask = CWBorderPixel | CWColormap | CWEventMask;
+ win = XCreateWindow(dpy, root, 0, 0, Width, Height, 0,
+ visInfo->depth, InputOutput,
+ visInfo->visual,
+ winAttribsMask, &winAttribs);
+
+ {
+ XSizeHints sizehints;
+ /*
+ sizehints.x = xpos;
+ sizehints.y = ypos;
+ sizehints.width = width;
+ sizehints.height = height;
+ */
+ sizehints.flags = 0;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+
+ XMapWindow(dpy, win);
+
+ glXMakeCurrent(dpy, win, glCtx);
+
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("Press ESC to exit.\n");
+ printf("Press up/down to change window shape.\n");
+
+ event_loop(dpy, win);
+
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/vgears.c b/xc/extras/Mesa/xdemos/vgears.c
new file mode 100644
index 000000000..13d030a8b
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/vgears.c
@@ -0,0 +1,282 @@
+/* $ID$ */
+
+/*
+ * Spinning gears demo for Linux SVGA/Mesa interface in 32K color mode.
+ *
+ * Compile with: gcc vgears.c -I../include -L../lib -lMesaGL -lX11 -lXext
+ * -lvga -lm -o vgears
+ *
+ * This program is in the public domain.
+ * Brian Paul, January 1996
+ */
+
+
+#include <vga.h>
+#include <math.h>
+#include "GL/svgamesa.h"
+#include "GL/gl.h"
+
+
+int width = 800, height = 600;
+
+SVGAMesaContext vmc;
+
+
+
+/*
+ * Draw a gear wheel. You'll probably want to call this function when
+ * building a display list since we do a lot of trig here.
+ *
+ * Input: inner_radius - radius of hole at center
+ * outer_radius - radius at center of teeth
+ * width - width of gear
+ * teeth - number of teeth
+ * tooth_depth - depth of tooth
+ */
+static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
+ GLint teeth, GLfloat tooth_depth )
+{
+ GLint i;
+ GLfloat r0, r1, r2;
+ GLfloat angle, da;
+ GLfloat u, v, len;
+
+ r0 = inner_radius;
+ r1 = outer_radius - tooth_depth/2.0;
+ r2 = outer_radius + tooth_depth/2.0;
+
+ da = 2.0*M_PI / teeth / 4.0;
+
+ glShadeModel( GL_FLAT );
+
+ glNormal3f( 0.0, 0.0, 1.0 );
+
+ /* draw front face */
+ glBegin( GL_QUAD_STRIP );
+ for (i=0;i<=teeth;i++) {
+ angle = i * 2.0*M_PI / teeth;
+ glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
+ glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
+ glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
+ glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
+ }
+ glEnd();
+
+ /* draw front sides of teeth */
+ glBegin( GL_QUADS );
+ da = 2.0*M_PI / teeth / 4.0;
+ for (i=0;i<teeth;i++) {
+ angle = i * 2.0*M_PI / teeth;
+
+ glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
+ glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
+ glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
+ glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
+ }
+ glEnd();
+
+
+ glNormal3f( 0.0, 0.0, -1.0 );
+
+ /* draw back face */
+ glBegin( GL_QUAD_STRIP );
+ for (i=0;i<=teeth;i++) {
+ angle = i * 2.0*M_PI / teeth;
+ glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
+ glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
+ glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
+ glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
+ }
+ glEnd();
+
+ /* draw back sides of teeth */
+ glBegin( GL_QUADS );
+ da = 2.0*M_PI / teeth / 4.0;
+ for (i=0;i<teeth;i++) {
+ angle = i * 2.0*M_PI / teeth;
+
+ glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
+ glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
+ glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
+ glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
+ }
+ glEnd();
+
+
+ /* draw outward faces of teeth */
+ glBegin( GL_QUAD_STRIP );
+ for (i=0;i<teeth;i++) {
+ angle = i * 2.0*M_PI / teeth;
+
+ glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
+ glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
+ u = r2*cos(angle+da) - r1*cos(angle);
+ v = r2*sin(angle+da) - r1*sin(angle);
+ len = sqrt( u*u + v*v );
+ u /= len;
+ v /= len;
+ glNormal3f( v, -u, 0.0 );
+ glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
+ glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
+ glNormal3f( cos(angle), sin(angle), 0.0 );
+ glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
+ glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
+ u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
+ v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
+ glNormal3f( v, -u, 0.0 );
+ glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
+ glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
+ glNormal3f( cos(angle), sin(angle), 0.0 );
+ }
+
+ glVertex3f( r1*cos(0), r1*sin(0), width*0.5 );
+ glVertex3f( r1*cos(0), r1*sin(0), -width*0.5 );
+
+ glEnd();
+
+
+ glShadeModel( GL_SMOOTH );
+
+ /* draw inside radius cylinder */
+ glBegin( GL_QUAD_STRIP );
+ for (i=0;i<=teeth;i++) {
+ angle = i * 2.0*M_PI / teeth;
+ glNormal3f( -cos(angle), -sin(angle), 0.0 );
+ glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
+ glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
+ }
+ glEnd();
+
+}
+
+
+static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
+static GLint gear1, gear2, gear3;
+static GLfloat angle = 0.0;
+
+static GLuint limit;
+static GLuint count = 1;
+
+
+static void draw( void )
+{
+ angle += 2.0;
+
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glPushMatrix();
+ glRotatef( view_rotx, 1.0, 0.0, 0.0 );
+ glRotatef( view_roty, 0.0, 1.0, 0.0 );
+ glRotatef( view_rotz, 0.0, 0.0, 1.0 );
+
+ glPushMatrix();
+ glTranslatef( -3.0, -2.0, 0.0 );
+ glRotatef( angle, 0.0, 0.0, 1.0 );
+ glCallList(gear1);
+ glPopMatrix();
+
+ glPushMatrix();
+ glTranslatef( 3.1, -2.0, 0.0 );
+ glRotatef( -2.0*angle-9.0, 0.0, 0.0, 1.0 );
+ glCallList(gear2);
+ glPopMatrix();
+
+ glPushMatrix();
+ glTranslatef( -3.1, 4.2, 0.0 );
+ glRotatef( -2.0*angle-25.0, 0.0, 0.0, 1.0 );
+ glCallList(gear3);
+ glPopMatrix();
+
+ glPopMatrix();
+
+ SVGAMesaSwapBuffers();
+}
+
+
+static void init( void )
+{
+ static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 };
+ static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
+ static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
+ static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
+
+ GLfloat w = (float) width / (float) height;
+ GLfloat h = 1.0;
+
+ glLightfv( GL_LIGHT0, GL_POSITION, pos );
+ glEnable( GL_CULL_FACE );
+ glEnable( GL_LIGHTING );
+ glEnable( GL_LIGHT0 );
+ glEnable( GL_DEPTH_TEST );
+
+ /* make the gears */
+ gear1 = glGenLists(1);
+ glNewList(gear1, GL_COMPILE);
+ glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red );
+ gear( 1.0, 4.0, 1.0, 20, 0.7 );
+ glEndList();
+
+ gear2 = glGenLists(1);
+ glNewList(gear2, GL_COMPILE);
+ glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
+ gear( 0.5, 2.0, 2.0, 10, 0.7 );
+ glEndList();
+
+ gear3 = glGenLists(1);
+ glNewList(gear3, GL_COMPILE);
+ glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue );
+ gear( 1.3, 2.0, 0.5, 10, 0.7 );
+ glEndList();
+
+ glEnable( GL_NORMALIZE );
+
+
+ glViewport( 0, 0, width, height );
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ if (width>height) {
+ GLfloat w = (GLfloat) width / (GLfloat) height;
+ glFrustum( -w, w, -1.0, 1.0, 5.0, 60.0 );
+ }
+ else {
+ GLfloat h = (GLfloat) height / (GLfloat) width;
+ glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
+ }
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef( 0.0, 0.0, -40.0 );
+}
+
+void setup( void )
+{
+ vga_init();
+
+ vga_setmode(G800x600x32K);
+/* gl_setcontextvga(G800x600x32K);*/
+
+ vmc = SVGAMesaCreateContext(GL_TRUE);
+ SVGAMesaMakeCurrent( vmc );
+}
+
+
+void end( void )
+{
+ SVGAMesaDestroyContext( vmc );
+
+ vga_setmode( TEXT );
+}
+
+
+int main( int argc, char *argv[] )
+{
+ int i;
+
+ setup();
+ init();
+ for (i=0;i<4;i++) {
+ draw(); /*SVGAMesaSwapBuffers();*/
+ }
+ end();
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/vindex.c b/xc/extras/Mesa/xdemos/vindex.c
new file mode 100644
index 000000000..fad843409
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/vindex.c
@@ -0,0 +1,66 @@
+/* $Id: vindex.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Test Linux 8-bit SVGA/Mesa color index mode
+ *
+ * Compile with: gcc vindex.c -I../include -L../lib -lMesaGL -lX11 -lXext
+ * -lvga -lm -o vindex
+ *
+ * This program is in the public domain.
+ * Brian Paul, January 1996
+ */
+
+
+
+#include <vga.h>
+#include "GL/svgamesa.h"
+#include "GL/gl.h"
+
+
+
+static GLint width = 640, height = 480;
+
+
+
+static void display( void )
+{
+ int i, j;
+ int w, h;
+
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( 0.0, (GLfloat) width, 0.0, (GLfloat) height, -1.0, 1.0 );
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ w = width / 16;
+ h = height / 16;
+ for (i=0;i<16;i++) {
+ for (j=0;j<16;j++) {
+ glIndexi( i*16+j );
+ glRecti( i*w, j*h, i*w+w, j*h+h );
+ }
+ }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+ SVGAMesaContext vmc;
+ int i;
+
+ vga_init();
+ vga_setmode( G640x480x256 );
+
+ vmc = SVGAMesaCreateContext( GL_FALSE );
+ SVGAMesaMakeCurrent( vmc );
+
+ display();
+ sleep(3);
+
+ SVGAMesaDestroyContext( vmc );
+ vga_setmode( TEXT );
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/vtest.c b/xc/extras/Mesa/xdemos/vtest.c
new file mode 100644
index 000000000..5cc477595
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/vtest.c
@@ -0,0 +1,83 @@
+/* $Id: vtest.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Test SVGA/Mesa interface in 32K color mode.
+ *
+ * Compile with: gcc vtest.c -I../include -L../lib -lMesaGL -lX11 -lXext
+ * -lvga -lm -o vtest
+ *
+ * This program is in the public domain.
+ * Brian Paul, January 1996
+ */
+
+
+
+#include <vga.h>
+#include "GL/svgamesa.h"
+#include "GL/gl.h"
+
+
+SVGAMesaContext vmc;
+
+
+
+void setup( void )
+{
+ vga_init();
+
+ vga_setmode(G800x600x32K);
+/* gl_setcontextvga(G800x600x32K);*/
+
+ vmc = SVGAMesaCreateContext( GL_FALSE ); /* single buffered */
+ SVGAMesaMakeCurrent( vmc );
+}
+
+
+void test( void )
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
+ glMatrixMode(GL_MODELVIEW);
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ glBegin( GL_LINES );
+ glColor3f( 1.0, 0.0, 0.0 );
+ glVertex2f( -0.5, 0.5 );
+ glVertex2f( 0.5, 0.5 );
+ glColor3f( 0.0, 1.0, 0.0 );
+ glVertex2f( -0.5, 0.25 );
+ glVertex2f( 0.5, 0.25 );
+ glColor3f( 0.0, 0.0, 1.0 );
+ glVertex2f( -0.5, 0.0 );
+ glVertex2f( 0.5, 0.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glColor3f( 1.0, 0.0, 0.0 );
+ glVertex2f( 0.0, 0.7 );
+ glColor3f( 0.0, 1.0, 0.0 );
+ glVertex2f( -0.5, -0.5 );
+ glColor3f( 0.0, 0.0, 1.0 );
+ glVertex2f( 0.5, -0.5 );
+ glEnd();
+
+ sleep(3);
+}
+
+void end( void )
+{
+ SVGAMesaDestroyContext( vmc );
+
+ vga_setmode( TEXT );
+}
+
+
+int main( int argc, char *argv[] )
+{
+ setup();
+ test();
+ end();
+ return 0;
+}
diff --git a/xc/extras/Mesa/xdemos/wincopy.c b/xc/extras/Mesa/xdemos/wincopy.c
new file mode 100644
index 000000000..4c8f1f041
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/wincopy.c
@@ -0,0 +1,270 @@
+/* $Id: wincopy.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.3
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * This program opens two GLX windows, renders into one and uses
+ * glCopyPixels to copy the image from the first window into the
+ * second by means of the GLX 1.3 function glxMakeContextCurrent().
+ * This function works just like the glXMakeCurrentReadSGI() function
+ * in the GLX_SGI_make_current_read extension.
+ */
+
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#ifdef GLX_VERSION_1_3
+
+
+static Display *Dpy;
+static int ScrNum;
+static GLXContext Context;
+static Window Win[2]; /* Win[0] = source, Win[1] = dest */
+static GLint Width[2], Height[2];
+
+static GLfloat Angle = 0.0;
+
+
+
+static Window
+CreateWindow(Display *dpy, int scrnum, XVisualInfo *visinfo,
+ int xpos, int ypos, int width, int height,
+ const char *name)
+{
+ Window win;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+
+ root = RootWindow(dpy, scrnum);
+
+ /* 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, xpos, ypos, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr);
+ if (win) {
+ XSizeHints sizehints;
+ sizehints.x = xpos;
+ sizehints.y = ypos;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+
+ XMapWindow(dpy, win);
+ }
+ return win;
+}
+
+
+static void
+Redraw(void)
+{
+ /* make the first window the current one */
+ if (!glXMakeContextCurrent(Dpy, Win[0], Win[0], Context)) {
+ printf("glXMakeContextCurrent failed in Redraw()\n");
+ return;
+ }
+
+ Angle += 1.0;
+
+ glViewport(0, 0, Width[0], Height[0]);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+
+ glShadeModel(GL_FLAT);
+ glClearColor(0.5, 0.5, 0.5, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* draw blue quad */
+ glColor3f(0.3, 0.3, 1.0);
+ glPushMatrix();
+ glRotatef(Angle, 0, 0, 1);
+ glBegin(GL_POLYGON);
+ glVertex2f(-0.5, -0.25);
+ glVertex2f( 0.5, -0.25);
+ glVertex2f( 0.5, 0.25);
+ glVertex2f(-0.5, 0.25);
+ glEnd();
+ glPopMatrix();
+
+ glXSwapBuffers(Dpy, Win[0]);
+
+
+ /* copy image from window 0 to window 1 */
+ if (!glXMakeContextCurrent(Dpy, Win[1], Win[0], Context)) {
+ printf("glXMakeContextCurrent failed in Redraw()\n");
+ return;
+ }
+
+ /* raster pos setup */
+ glViewport(0, 0, Width[1], Height[1]);
+ glPushMatrix();
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(-1, 1, -1, 1, -1, 1);
+ glRasterPos2f(-1, -1);
+
+ /* copy the image between windows */
+ glDrawBuffer(GL_FRONT);
+ glCopyPixels(0, 0, Width[0], Height[0], GL_COLOR);
+ glDrawBuffer(GL_BACK);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+}
+
+
+
+static void
+Resize(Window win, unsigned int width, unsigned int height)
+{
+ int i;
+ if (win == Win[0]) {
+ i = 0;
+ }
+ else {
+ i = 1;
+ }
+ Width[i] = width;
+ Height[i] = height;
+ if (!glXMakeCurrent(Dpy, Win[i], Context)) {
+ printf("glXMakeCurrent failed in Resize()\n");
+ return;
+ }
+}
+
+
+
+static void
+EventLoop(void)
+{
+ XEvent event;
+ while (1) {
+ if (XPending(Dpy) > 0) {
+ XNextEvent( Dpy, &event );
+ switch (event.type) {
+ case Expose:
+ Redraw();
+ break;
+ case ConfigureNotify:
+ Resize(event.xany.window, event.xconfigure.width, event.xconfigure.height);
+ break;
+ case KeyPress:
+ return;
+ default:
+ /*no-op*/ ;
+ }
+ }
+ else {
+ /* animate */
+ Redraw();
+ }
+ }
+}
+
+
+static void
+Init(void)
+{
+ XVisualInfo *visinfo;
+ int attrib[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None };
+
+ Dpy = XOpenDisplay(NULL);
+ if (!Dpy) {
+ printf("Couldn't open default display!\n");
+ exit(1);
+ }
+
+ ScrNum = DefaultScreen(Dpy);
+
+ visinfo = glXChooseVisual(Dpy, ScrNum, attrib);
+ if (!visinfo) {
+ printf("Unable to find RGB, double-buffered visual\n");
+ exit(1);
+ }
+
+ Context = glXCreateContext(Dpy, visinfo, NULL, True);
+ if (!Context) {
+ printf("Couldn't create GLX context\n");
+ exit(1);
+ }
+
+
+ Win[0] = CreateWindow(Dpy, ScrNum, visinfo,
+ 0, 0, 300, 300, "source window");
+
+ Win[1] = CreateWindow(Dpy, ScrNum, visinfo,
+ 350, 0, 300, 300, "dest window");
+
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ Init();
+ EventLoop();
+ return 0;
+}
+
+
+#else
+
+
+int
+main(int argc, char *argv[])
+{
+ printf("This program requires GLX 1.3!\n");
+ return 0;
+}
+
+
+#endif /* GLX_VERSION_1_3 */
diff --git a/xc/extras/Mesa/xdemos/xdemo.c b/xc/extras/Mesa/xdemos/xdemo.c
new file mode 100644
index 000000000..6102242de
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/xdemo.c
@@ -0,0 +1,355 @@
+/* $Id: xdemo.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+
+/*
+ * Very simple demo of how to use the Mesa/X11 interface instead of the
+ * glx, tk or aux toolkits. I highly recommend using the GLX interface
+ * instead of the X/Mesa interface, however.
+ *
+ * This program is in the public domain.
+ *
+ * Brian Paul
+ */
+
+
+/*
+ * $Log: xdemo.c,v $
+ * Revision 1.1 2000/12/05 16:38:37 dawes
+ * Initial revision
+ *
+ * Revision 1.2 2000/04/05 22:09:58 brianp
+ * new arguments to XMesaCreateVisual()
+ *
+ * Revision 1.1.1.1 1999/08/19 00:55:43 jtg
+ * Imported sources
+ *
+ * Revision 3.0 1998/02/21 02:16:54 brianp
+ * initial rev
+ *
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include "GL/xmesa.h"
+#include "GL/gl.h"
+
+
+
+static GLint Black, Red, Green, Blue;
+
+
+
+static void make_window( char *title, int color_flag )
+{
+ int x = 10, y = 10, width = 400, height = 300;
+ Display *dpy;
+ int scr;
+ Window root, win;
+ Colormap cmap;
+ XColor xcolor;
+ int attr_flags;
+ XVisualInfo *visinfo;
+ XSetWindowAttributes attr;
+ XTextProperty tp;
+ XSizeHints sh;
+ XEvent e;
+ XMesaContext context;
+ XMesaVisual visual;
+ XMesaBuffer buffer;
+
+
+ /*
+ * Do the usual X things to make a window.
+ */
+
+ dpy = XOpenDisplay(NULL);
+ if (!dpy) {
+ printf("Couldn't open default display!\n");
+ exit(1);
+ }
+
+ scr = DefaultScreen(dpy);
+ root = RootWindow(dpy, scr);
+
+ /* alloc visinfo struct */
+ visinfo = (XVisualInfo *) malloc( sizeof(XVisualInfo) );
+
+ /* Get a visual and colormap */
+ if (color_flag) {
+ /* Open TrueColor window */
+
+/*
+ if (!XMatchVisualInfo( dpy, scr, 24, TrueColor, visinfo )) {
+ printf("Couldn't get 24-bit TrueColor visual!\n");
+ exit(1);
+ }
+*/
+ if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
+ printf("Couldn't get 8-bit PseudoColor visual!\n");
+ exit(1);
+ }
+
+ cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
+ Black = Red = Green = Blue = 0;
+ }
+ else {
+ /* Open color index window */
+
+ if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
+ printf("Couldn't get 8-bit PseudoColor visual\n");
+ exit(1);
+ }
+
+ cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
+
+ /* Allocate colors */
+ xcolor.red = 0x0;
+ xcolor.green = 0x0;
+ xcolor.blue = 0x0;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate black!\n");
+ exit(1);
+ }
+ Black = xcolor.pixel;
+
+ xcolor.red = 0xffff;
+ xcolor.green = 0x0;
+ xcolor.blue = 0x0;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate red!\n");
+ exit(1);
+ }
+ Red = xcolor.pixel;
+
+ xcolor.red = 0x0;
+ xcolor.green = 0xffff;
+ xcolor.blue = 0x0;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate green!\n");
+ exit(1);
+ }
+ Green = xcolor.pixel;
+
+ xcolor.red = 0x0;
+ xcolor.green = 0x0;
+ xcolor.blue = 0xffff;
+ xcolor.flags = DoRed | DoGreen | DoBlue;
+ if (!XAllocColor( dpy, cmap, &xcolor )) {
+ printf("Couldn't allocate blue!\n");
+ exit(1);
+ }
+ Blue = xcolor.pixel;
+ }
+
+ /* set window attributes */
+ attr.colormap = cmap;
+ attr.event_mask = ExposureMask | StructureNotifyMask;
+ attr.border_pixel = BlackPixel( dpy, scr );
+ attr.background_pixel = BlackPixel( dpy, scr );
+ attr_flags = CWColormap | CWEventMask | CWBorderPixel | CWBackPixel;
+
+ /* Create the window */
+ win = XCreateWindow( dpy, root, x,y, width, height, 0,
+ visinfo->depth, InputOutput,
+ visinfo->visual,
+ attr_flags, &attr);
+ if (!win) {
+ printf("Couldn't open window!\n");
+ exit(1);
+ }
+
+ XStringListToTextProperty(&title, 1, &tp);
+ sh.flags = USPosition | USSize;
+ XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0);
+ XMapWindow(dpy, win);
+ while (1) {
+ XNextEvent( dpy, &e );
+ if (e.type == MapNotify && e.xmap.window == win) {
+ break;
+ }
+ }
+
+
+ /*
+ * Now do the special Mesa/Xlib stuff!
+ */
+
+ visual = XMesaCreateVisual( dpy, visinfo,
+ (GLboolean) color_flag,
+ GL_FALSE, /* alpha_flag */
+ GL_FALSE, /* db_flag */
+ GL_FALSE, /* stereo flag */
+ GL_FALSE, /* ximage_flag */
+ 0, /* depth size */
+ 0, /* stencil size */
+ 0,0,0,0, /* accum_size */
+ 0, /* num samples */
+ 0, /* level */
+ 0 /* caveat */
+ );
+ if (!visual) {
+ printf("Couldn't create Mesa/X visual!\n");
+ exit(1);
+ }
+
+ /* Create a Mesa rendering context */
+ context = XMesaCreateContext( visual,
+ NULL /* share_list */
+ );
+ if (!context) {
+ printf("Couldn't create Mesa/X context!\n");
+ exit(1);
+ }
+
+ buffer = XMesaCreateWindowBuffer( visual, win );
+ if (!buffer) {
+ printf("Couldn't create Mesa/X buffer!\n");
+ exit(1);
+ }
+
+
+ XMesaMakeCurrent( context, buffer );
+
+ /* Ready to render! */
+}
+
+
+
+static void draw_cube( void )
+{
+ /* X faces */
+ glIndexi( Red );
+ glColor3f( 1.0, 0.0, 0.0 );
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, 1.0 );
+ glVertex3f( 1.0, -1.0, 1.0 );
+ glVertex3f( 1.0, -1.0, -1.0 );
+ glVertex3f( 1.0, 1.0, -1.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glVertex3f( -1.0, 1.0, 1.0 );
+ glVertex3f( -1.0, 1.0, -1.0 );
+ glVertex3f( -1.0, -1.0, -1.0 );
+ glVertex3f( -1.0, -1.0, 1.0 );
+ glEnd();
+
+ /* Y faces */
+ glIndexi( Green );
+ glColor3f( 0.0, 1.0, 0.0 );
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, 1.0 );
+ glVertex3f( 1.0, 1.0, -1.0 );
+ glVertex3f( -1.0, 1.0, -1.0 );
+ glVertex3f( -1.0, 1.0, 1.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, -1.0, 1.0 );
+ glVertex3f( -1.0, -1.0, 1.0 );
+ glVertex3f( -1.0, -1.0, -1.0 );
+ glVertex3f( 1.0, -1.0, -1.0 );
+ glEnd();
+
+ /* Z faces */
+ glIndexi( Blue );
+ glColor3f( 0.0, 0.0, 1.0 );
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, 1.0 );
+ glVertex3f( -1.0, 1.0, 1.0 );
+ glVertex3f( -1.0, -1.0, 1.0 );
+ glVertex3f( 1.0, -1.0, 1.0 );
+ glEnd();
+
+ glBegin( GL_POLYGON );
+ glVertex3f( 1.0, 1.0, -1.0 );
+ glVertex3f( 1.0,-1.0, -1.0 );
+ glVertex3f( -1.0,-1.0, -1.0 );
+ glVertex3f( -1.0, 1.0, -1.0 );
+ glEnd();
+}
+
+
+
+
+static void display_loop( void )
+{
+ GLfloat xrot, yrot, zrot;
+
+ xrot = yrot = zrot = 0.0;
+
+ glClearColor( 0.0, 0.0, 0.0, 0.0 );
+ glClearIndex( Black );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 10.0 );
+ glTranslatef( 0.0, 0.0, -5.0 );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ glCullFace( GL_BACK );
+ glEnable( GL_CULL_FACE );
+
+ glShadeModel( GL_FLAT );
+
+ while (1) {
+ glClear( GL_COLOR_BUFFER_BIT );
+ glPushMatrix();
+ glRotatef( xrot, 1.0, 0.0, 0.0 );
+ glRotatef( yrot, 0.0, 1.0, 0.0 );
+ glRotatef( zrot, 0.0, 0.0, 1.0 );
+
+ draw_cube();
+
+ glPopMatrix();
+ glFinish();
+
+ xrot += 10.0;
+ yrot += 7.0;
+ zrot -= 3.0;
+ }
+
+}
+
+
+
+
+int main( int argc, char *argv[] )
+{
+ int mode = 0;
+
+ if (argc >= 2)
+ {
+ if (strcmp(argv[1],"-ci")==0)
+ mode = 0;
+ else if (strcmp(argv[1],"-rgb")==0)
+ mode = 1;
+ else
+ {
+ printf("Bad flag: %s\n", argv[1]);
+ printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n");
+ exit(1);
+ }
+ }
+ else
+ {
+ printf("Specify -ci for 8-bit color index or -rgb for RGB mode\n");
+ printf("Defaulting to 8-bit color index\n");
+ }
+
+ make_window( argv[0], mode );
+
+ display_loop();
+ return 0;
+}
+
diff --git a/xc/extras/Mesa/xdemos/xfont.c b/xc/extras/Mesa/xdemos/xfont.c
new file mode 100644
index 000000000..d5c868cf0
--- /dev/null
+++ b/xc/extras/Mesa/xdemos/xfont.c
@@ -0,0 +1,207 @@
+/* $Id: xfont.c,v 1.1 2000/12/05 16:38:37 dawes Exp $ */
+
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * Example of using glXUseXFont().
+ * 5 November 1999
+ * Brian Paul
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+static const char *ProgramName = "xfont";
+
+static const char *FontName = "fixed";
+
+static GLuint FontBase = 0;
+
+
+
+static void redraw( Display *dpy, Window w )
+{
+ static const char *text = "This is glXUseXFont()";
+
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ /* triangle */
+ glColor3f( 0.2, 0.2, 1.0 );
+ glBegin(GL_TRIANGLES);
+ glVertex2f( 0, 0.8 );
+ glVertex2f( -0.8, -0.7 );
+ glVertex2f( 0.8, -0.7 );
+ glEnd();
+
+ /* text */
+ glColor3f( 1, 1, 1 );
+ glRasterPos2f(-0.8, 0);
+ glListBase(FontBase);
+ glCallLists(strlen(text), GL_UNSIGNED_BYTE, (GLubyte *) text);
+
+ glXSwapBuffers( dpy, w );
+}
+
+
+
+static void resize( unsigned int width, unsigned int height )
+{
+ glViewport( 0, 0, width, height );
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
+}
+
+
+
+static void setup_font( Display *dpy )
+{
+ XFontStruct *fontInfo;
+ Font id;
+ unsigned int first, last;
+
+ fontInfo = XLoadQueryFont(dpy, FontName);
+ if (!fontInfo) {
+ printf("Error: font %s not found\n", FontName);
+ exit(0);
+ }
+
+ id = fontInfo->fid;
+ first = fontInfo->min_char_or_byte2;
+ last = fontInfo->max_char_or_byte2;
+
+ FontBase = glGenLists((GLuint) last + 1);
+ if (!FontBase) {
+ printf("Error: unable to allocate display lists\n");
+ exit(0);
+ }
+ glXUseXFont(id, first, last - first + 1, FontBase + first);
+}
+
+static Window make_rgb_db_window( Display *dpy, int xpos, int ypos,
+ 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("Error: 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 );
+
+ {
+ XSizeHints sizehints;
+ sizehints.x = xpos;
+ sizehints.y = ypos;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, ProgramName, ProgramName,
+ None, (char **)NULL, 0, &sizehints);
+ }
+
+
+ ctx = glXCreateContext( dpy, visinfo, NULL, True );
+
+ glXMakeCurrent( dpy, win, ctx );
+
+ 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);
+ default:
+ ; /* no-op */
+ }
+ }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+ Display *dpy;
+ Window win;
+
+ dpy = XOpenDisplay(NULL);
+
+ win = make_rgb_db_window( dpy, 0, 0, 300, 300 );
+ setup_font( dpy );
+
+ glShadeModel( GL_FLAT );
+ glClearColor( 0.5, 0.5, 1.0, 1.0 );
+
+ XMapWindow( dpy, win );
+
+ event_loop( dpy );
+ return 0;
+}