summaryrefslogtreecommitdiff
path: root/progs/xdemos
diff options
context:
space:
mode:
authorjtg <jtg>1999-08-19 00:55:39 +0000
committerjtg <jtg>1999-08-19 00:55:39 +0000
commitafb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1c (patch)
tree59d65b4da12fb5379224cf5f6b808fde91523c7f /progs/xdemos
parentf2544d4920ce168bec9cd94d774b7ea5103a3d74 (diff)
Initial revision
Diffstat (limited to 'progs/xdemos')
-rw-r--r--progs/xdemos/Makefile.X1158
-rw-r--r--progs/xdemos/descrip.mms79
-rw-r--r--progs/xdemos/glxdemo.c136
-rw-r--r--progs/xdemos/glxpixmap.c160
-rw-r--r--progs/xdemos/offset.c323
-rw-r--r--progs/xdemos/shape.c305
-rw-r--r--progs/xdemos/vgears.c282
-rw-r--r--progs/xdemos/vindex.c66
-rw-r--r--progs/xdemos/vtest.c83
-rw-r--r--progs/xdemos/xdemo.c347
-rw-r--r--progs/xdemos/xfont.c148
11 files changed, 1987 insertions, 0 deletions
diff --git a/progs/xdemos/Makefile.X11 b/progs/xdemos/Makefile.X11
new file mode 100644
index 0000000000..ab5dce418d
--- /dev/null
+++ b/progs/xdemos/Makefile.X11
@@ -0,0 +1,58 @@
+# $Id: Makefile.X11,v 1.1 1999/08/19 00:55:43 jtg Exp $
+
+# Mesa 3-D graphics library
+# Version: 3.1
+# Copyright (C) 1995-1999 Brian Paul
+
+# Makefile for non-GLUT (X11, SVGA, etc) demo programs
+
+
+##### MACROS #####
+
+INCDIR = ../include
+LIBDIR = ../lib
+
+GL_LIBS = -L$(LIBDIR) -lglut -lGLU -lGL -lm $(XLIBS)
+
+LIB_DEP = $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLUT_LIB)
+
+PROGS = glxdemo glxpixmap offset xdemo
+
+
+
+##### 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/progs/xdemos/descrip.mms b/progs/xdemos/descrip.mms
new file mode 100644
index 0000000000..aa56c1cec3
--- /dev/null
+++ b/progs/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/progs/xdemos/glxdemo.c b/progs/xdemos/glxdemo.c
new file mode 100644
index 0000000000..c49cd85140
--- /dev/null
+++ b/progs/xdemos/glxdemo.c
@@ -0,0 +1,136 @@
+/* $Id: glxdemo.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */
+
+
+/*
+ * A demonstration of using the GLX functions. This program is in the
+ * public domain.
+ *
+ * Brian Paul
+ */
+
+
+/*
+ * $Log: glxdemo.c,v $
+ * Revision 1.1 1999/08/19 00:55:43 jtg
+ * Initial revision
+ *
+ * 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/progs/xdemos/glxpixmap.c b/progs/xdemos/glxpixmap.c
new file mode 100644
index 0000000000..e4a62c72d9
--- /dev/null
+++ b/progs/xdemos/glxpixmap.c
@@ -0,0 +1,160 @@
+/* $Id: glxpixmap.c,v 1.1 1999/08/19 00:55:43 jtg Exp $ */
+
+
+/*
+ * A demonstration of using the GLXPixmap functions. This program is in
+ * the public domain.
+ *
+ * Brian Paul
+ */
+
+
+/*
+ * $Id: glxpixmap.c,v 1.1 1999/08/19 00:55:43 jtg Exp $
+ */
+
+
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+static GLXContext ctx;
+static XVisualInfo *visinfo;
+static GC gc;
+
+
+
+static Window make_rgb_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,
+ None };
+ int scrnum;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ Window win;
+
+ 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;
+ /* 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 );
+
+ ctx = glXCreateContext( dpy, visinfo, NULL, True );
+
+ return win;
+}
+
+
+static GLXPixmap make_pixmap( Display *dpy, Window win,
+ unsigned int width, unsigned int height )
+{
+ Pixmap pm;
+ GLXPixmap glxpm;
+ XWindowAttributes attr;
+
+ pm = XCreatePixmap( dpy, win, width, height, visinfo->depth );
+ 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
+ glxpm = glXCreateGLXPixmapMESA( dpy, visinfo, pm, attr.colormap );
+#else
+ /* This will work with Mesa too if the visual is TrueColor or DirectColor */
+ glxpm = glXCreateGLXPixmap( dpy, visinfo, pm );
+#endif
+
+ 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;
+ GLXPixmap pm;
+
+ dpy = XOpenDisplay(NULL);
+
+ win = make_rgb_window( dpy, 300, 300 );
+ pm = make_pixmap( dpy, win, 300, 300 );
+
+#ifdef JUNK
+ glXMakeCurrent( dpy, win, ctx ); /*to make sure ctx is properly initialized*/
+#endif
+
+ glXMakeCurrent( dpy, pm, ctx );
+
+ /* 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();
+
+ /* when a redraw is needed we'll just copy the pixmap image to the window */
+
+ XMapWindow( dpy, win );
+
+ event_loop( dpy, pm );
+ return 0;
+}
diff --git a/progs/xdemos/offset.c b/progs/xdemos/offset.c
new file mode 100644
index 0000000000..158e52a97c
--- /dev/null
+++ b/progs/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 uncomment to use new version*/
+
+
+#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/progs/xdemos/shape.c b/progs/xdemos/shape.c
new file mode 100644
index 0000000000..94b9b1f26a
--- /dev/null
+++ b/progs/xdemos/shape.c
@@ -0,0 +1,305 @@
+/* $Id: shape.c,v 1.1 1999/08/19 00:55:43 jtg 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);
+
+ glPushMatrix();
+
+ glScalef(scale, scale, scale);
+ glRotatef(Xangle, 1.0, 0.0, 0.0);
+ glRotatef(Yangle, 0.0, 1.0, 0.0);
+
+ 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();
+
+ 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);
+}
+
+
+/*
+ * 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;
+
+ 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);
+ XMapWindow(dpy, win);
+
+ glXMakeCurrent(dpy, win, glCtx);
+
+ printf("Press ESC to exit.\n");
+ printf("Press up/down to change window shape.\n");
+
+ event_loop(dpy, win);
+
+ return 0;
+}
diff --git a/progs/xdemos/vgears.c b/progs/xdemos/vgears.c
new file mode 100644
index 0000000000..13d030a8be
--- /dev/null
+++ b/progs/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/progs/xdemos/vindex.c b/progs/xdemos/vindex.c
new file mode 100644
index 0000000000..f9e3192f38
--- /dev/null
+++ b/progs/xdemos/vindex.c
@@ -0,0 +1,66 @@
+/* $Id: vindex.c,v 1.1 1999/08/19 00:55:43 jtg 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/progs/xdemos/vtest.c b/progs/xdemos/vtest.c
new file mode 100644
index 0000000000..f0900b6ed6
--- /dev/null
+++ b/progs/xdemos/vtest.c
@@ -0,0 +1,83 @@
+/* $Id: vtest.c,v 1.1 1999/08/19 00:55:43 jtg 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/progs/xdemos/xdemo.c b/progs/xdemos/xdemo.c
new file mode 100644
index 0000000000..13facba839
--- /dev/null
+++ b/progs/xdemos/xdemo.c
@@ -0,0 +1,347 @@
+/* $Id: xdemo.c,v 1.1 1999/08/19 00:55:43 jtg 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 1999/08/19 00:55:43 jtg
+ * Initial revision
+ *
+ * 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, /* accum_size */
+ 0 /* level */
+ );
+ 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/progs/xdemos/xfont.c b/progs/xdemos/xfont.c
new file mode 100644
index 0000000000..31bfb4bf94
--- /dev/null
+++ b/progs/xdemos/xfont.c
@@ -0,0 +1,148 @@
+/*
+ * (c) Copyright 1993, Silicon Graphics, Inc.
+ * ALL RIGHTS RESERVED
+ * Permission to use, copy, modify, and distribute this software for
+ * any purpose and without fee is hereby granted, provided that the above
+ * copyright notice appear in all copies and that both the copyright notice
+ * and this permission notice appear in supporting documentation, and that
+ * the name of Silicon Graphics, Inc. not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.
+ *
+ * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
+ * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
+ * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
+ * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
+ * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
+ * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
+ * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
+ * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
+ * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * US Government Users Restricted Rights
+ * Use, duplication, or disclosure by the Government is subject to
+ * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
+ * (c)(1)(ii) of the Rights in Technical Data and Computer Software
+ * clause at DFARS 252.227-7013 and/or in similar or successor
+ * clauses in the FAR or the DOD or NASA FAR Supplement.
+ * Unpublished-- rights reserved under the copyright laws of the
+ * United States. Contractor/manufacturer is Silicon Graphics,
+ * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
+ *
+ * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
+ */
+/*
+ * xfont.c
+ * Draws some text in a bitmapped font. Uses glBitmap()
+ * and other pixel routines. Also demonstrates use of
+ * display lists.
+ */
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <GL/glx.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "glaux.h"
+
+GLuint base;
+
+void makeRasterFont(void)
+{
+ XFontStruct *fontInfo;
+ Font id;
+ unsigned int first, last;
+ Display *xdisplay;
+
+ xdisplay = auxXDisplay ();
+ fontInfo = XLoadQueryFont(xdisplay,
+ "-adobe-helvetica-medium-r-normal--17-120-100-100-p-88-iso8859-1");
+ if (fontInfo == NULL) {
+ printf ("no font found\n");
+ exit (0);
+ }
+
+ id = fontInfo->fid;
+ first = fontInfo->min_char_or_byte2;
+ last = fontInfo->max_char_or_byte2;
+
+ base = glGenLists((GLuint) last+1);
+ if (base == 0) {
+ printf ("out of display lists\n");
+ exit (0);
+ }
+ glXUseXFont(id, first, last-first+1, base+first);
+/* *height = fontInfo->ascent + fontInfo->descent;
+ *width = fontInfo->max_bounds.width; */
+}
+
+void printString(char *s)
+{
+ glPushAttrib (GL_LIST_BIT);
+ glListBase(base);
+ glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s);
+ glPopAttrib ();
+}
+
+void myinit (void)
+{
+ makeRasterFont ();
+ glShadeModel (GL_FLAT);
+}
+
+void display(void)
+{
+ GLfloat white[3] = { 1.0, 1.0, 1.0 };
+ int i, j;
+ char teststring[33];
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glColor3fv(white);
+ for (i = 32; i < 127; i += 32) {
+ glRasterPos2i(20, 200 - 18*(GLint) i/32);
+ for (j = 0; j < 32; j++)
+ teststring[j] = (char) (i+j);
+ teststring[32] = 0;
+ printString(teststring);
+ }
+ glRasterPos2i(20, 100);
+ printString("The quick brown fox jumps");
+ glRasterPos2i(20, 82);
+ printString("over a lazy dog.");
+ glFlush ();
+}
+
+void myReshape(int w, int h)
+{
+ glViewport(0, 0, w, h);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho (0.0, (GLfloat) w, 0.0, (GLfloat) h, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+/* Main Loop
+ * Open window with initial window size, title bar,
+ * RGBA display mode, and handle input events.
+ */
+int main(int argc, char** argv)
+{
+ auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
+ auxInitPosition (0, 0, 500, 500);
+ if (!auxInitWindow (argv[0]))
+ auxQuit();
+ auxReshapeFunc (myReshape);
+ myinit ();
+ auxMainLoop(display);
+ return 0;
+}
+
+
+
+