diff options
Diffstat (limited to 'demos/natives/x11')
-rw-r--r-- | demos/natives/x11/cube.c | 95 | ||||
-rw-r--r-- | demos/natives/x11/gears.c | 374 | ||||
-rwxr-xr-x | demos/natives/x11/makeGears.sh | 3 | ||||
-rw-r--r-- | demos/natives/x11/makefile | 30 | ||||
-rw-r--r-- | demos/natives/x11/makefile.mesa | 30 | ||||
-rw-r--r-- | demos/natives/x11/makefile.x11 | 30 | ||||
-rw-r--r-- | demos/natives/x11/olympic.c | 409 | ||||
-rw-r--r-- | demos/natives/x11/testGL1.c | 222 | ||||
-rw-r--r-- | demos/natives/x11/testGL2.c | 517 | ||||
-rw-r--r-- | demos/natives/x11/wave.c | 500 |
10 files changed, 2210 insertions, 0 deletions
diff --git a/demos/natives/x11/cube.c b/demos/natives/x11/cube.c new file mode 100644 index 0000000..6f2fd57 --- /dev/null +++ b/demos/natives/x11/cube.c @@ -0,0 +1,95 @@ +
+/* Copyright (c) Mark J. Kilgard, 1997. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+/* This program was requested by Patrick Earl; hopefully someone else
+ will write the equivalent Direct3D immediate mode program. */
+
+#include <GL/glut.h>
+
+GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. */
+GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */
+GLfloat n[6][3] = { /* Normals for the 6 faces of a cube. */
+ {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
+ {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} };
+GLint faces[6][4] = { /* Vertex indices for the 6 faces of a cube. */
+ {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4},
+ {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} };
+GLfloat v[8][3]; /* Will be filled in with X,Y,Z vertexes. */
+
+void
+drawBox(void)
+{
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ glBegin(GL_QUADS);
+ glNormal3fv(&n[i][0]);
+ glVertex3fv(&v[faces[i][0]][0]);
+ glVertex3fv(&v[faces[i][1]][0]);
+ glVertex3fv(&v[faces[i][2]][0]);
+ glVertex3fv(&v[faces[i][3]][0]);
+ glEnd();
+ }
+}
+
+void
+display(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ drawBox();
+ glutSwapBuffers();
+}
+
+void
+init(void)
+{
+ /* Setup cube vertex data. */
+ v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1;
+ v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1;
+ v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1;
+ v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1;
+ v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;
+ v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;
+
+ /* Enable a single OpenGL light. */
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHTING);
+
+ glClearColor( 0.3f, 0.3f, 5.0f, 1.0f );
+
+ /* Use depth buffering for hidden surface elimination. */
+ glEnable(GL_DEPTH_TEST);
+
+ /* Setup the view of the cube. */
+ glMatrixMode(GL_PROJECTION);
+ gluPerspective( /* field of view in degree */ 40.0,
+ /* aspect ratio */ 1.0,
+ /* Z near */ 1.0, /* Z far */ 10.0);
+ glMatrixMode(GL_MODELVIEW);
+ gluLookAt(0.0, 0.0, 5.0, /* eye is at (0,0,5) */
+ 0.0, 0.0, 0.0, /* center is at (0,0,0) */
+ 0.0, 1.0, 0.); /* up is in positive Y direction */
+
+ /* Adjust cube position to be asthetic angle. */
+ glTranslatef(0.0, 0.0, -1.0);
+ glRotatef(60, 1.0, 0.0, 0.0);
+ glRotatef(-20, 0.0, 0.0, 1.0);
+}
+
+int
+main(int argc, char **argv)
+{
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
+ glutCreateWindow("red 3D lighted cube");
+ glutDisplayFunc(display);
+ init();
+ glutMainLoop();
+ return 0; /* ANSI C requires main to return int. */
+}
diff --git a/demos/natives/x11/gears.c b/demos/natives/x11/gears.c new file mode 100644 index 0000000..f1812ae --- /dev/null +++ b/demos/natives/x11/gears.c @@ -0,0 +1,374 @@ +/* $Id$ */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +/* + * $Log$ + * Revision 1.1 2000/11/18 06:54:01 sven + * Initial revision + * + * Revision 1.2 1999/10/21 16:39:06 brianp + * added -info command line option + * + * Revision 1.1.1.1 1999/08/19 00:55:40 jtg + * Imported sources + * + * Revision 3.2 1999/06/03 17:07:36 brianp + * an extra quad was being drawn in front and back faces + * + * Revision 3.1 1998/11/03 02:49:10 brianp + * added fps output + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <GL/glut.h> + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +static GLint T0 = 0; +static GLint Frames = 0; + + +/** + + 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); + if (i < teeth) { + 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); + if (i < teeth) { + 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 void +draw(void) +{ + 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(); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 5000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + T0 = t; + Frames = 0; + } + } +} + + +static void +idle(void) +{ + angle += 2.0; + glutPostRedisplay(); +} + +/* change view angle, exit upon ESC */ +/* ARGSUSED1 */ +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 'z': + view_rotz += 5.0; + break; + case 'Z': + view_rotz -= 5.0; + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* change view angle */ +/* ARGSUSED1 */ +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + view_rotx += 5.0; + break; + case GLUT_KEY_DOWN: + view_rotx -= 5.0; + break; + case GLUT_KEY_LEFT: + view_roty += 5.0; + break; + case GLUT_KEY_RIGHT: + view_roty -= 5.0; + break; + default: + return; + } + glutPostRedisplay(); +} + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + +static void +init(int argc, char *argv[]) +{ + static GLfloat pos[4] = + {5.0, 5.0, 10.0, 0.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}; + + 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); + + if (argc > 1 && strcmp(argv[1], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } +} + +void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) + glutIdleFunc(idle); + else + glutIdleFunc(NULL); +} + +int main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(300, 300); + glutCreateWindow("Gears"); + init(argc, argv); + + glutDisplayFunc(draw); + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutVisibilityFunc(visible); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/demos/natives/x11/makeGears.sh b/demos/natives/x11/makeGears.sh new file mode 100755 index 0000000..f7c6f27 --- /dev/null +++ b/demos/natives/x11/makeGears.sh @@ -0,0 +1,3 @@ +#! /bin/sh +gcc -ogears -I/usr/X11R6/include/ gears.c \ + -lGL -lGLU -lglut -L/usr/X11R6/lib -lm diff --git a/demos/natives/x11/makefile b/demos/natives/x11/makefile new file mode 100644 index 0000000..d4e03bb --- /dev/null +++ b/demos/natives/x11/makefile @@ -0,0 +1,30 @@ +# +# Uses: Linux2.0X-glibc-pthreads-mesa3.0pthreads +# + +CC = cc + +CCINCL = -I/usr/local/include -I/usr/X11/include -I/usr/X11R6/include +CCLIBS = -L/usr/X11R6/lib -L/usr/local/lib -L/usr/X11/lib \ + -lGL -lGLU -lglut \ + -lXmu -lXt -lSM -lICE -lXext -lX11 -lXi -lXext -lX11 -lm -lpthread + + +C_APPL_FILES = cube.c olympic.c testGL1.c testGL2.c wave.c + + +.SUFFIXES : .c .o + +.c.o: + $(CC) -c -o $@ $< $(CCINCL) 2>&1 | tee -a errors + $(CC) -o ${@:.o=} $@ $(CCINCL) $(CCLIBS) 2>&1 | tee -a errors + +all: ${C_APPL_FILES:.c=.o} + + +clean: + rm -f *.o *~ errors + +cleanall: clean + rm -f ${C_APPL_FILES:.c=} + diff --git a/demos/natives/x11/makefile.mesa b/demos/natives/x11/makefile.mesa new file mode 100644 index 0000000..9068e08 --- /dev/null +++ b/demos/natives/x11/makefile.mesa @@ -0,0 +1,30 @@ +# +# Uses: Linux2.0X-glibc-pthreads-mesa3.0pthreads +# + +CC = cc + +CCINCL = -I/usr/local/include -I/usr/local/mesa/include -I/usr/X11R6/include +CCLIBS = -L/usr/X11R6/lib -L/usr/local/lib -L/usr/local/mesa/lib \ + -lGL -lGLU -lglut \ + -lXmu -lXt -lSM -lICE -lXext -lX11 -lXi -lXext -lX11 -lm -lpthread + + +C_APPL_FILES = cube.c olympic.c testGL1.c testGL2.c wave.c + + +.SUFFIXES : .c .o + +.c.o: + $(CC) -c -o $@ $< $(CCINCL) 2>&1 | tee -a errors + $(CC) -o ${@:.o=} $@ $(CCINCL) $(CCLIBS) 2>&1 | tee -a errors + +all: ${C_APPL_FILES:.c=.o} + + +clean: + rm -f *.o *~ errors + +cleanall: clean + rm -f ${C_APPL_FILES:.c=} + diff --git a/demos/natives/x11/makefile.x11 b/demos/natives/x11/makefile.x11 new file mode 100644 index 0000000..d4e03bb --- /dev/null +++ b/demos/natives/x11/makefile.x11 @@ -0,0 +1,30 @@ +# +# Uses: Linux2.0X-glibc-pthreads-mesa3.0pthreads +# + +CC = cc + +CCINCL = -I/usr/local/include -I/usr/X11/include -I/usr/X11R6/include +CCLIBS = -L/usr/X11R6/lib -L/usr/local/lib -L/usr/X11/lib \ + -lGL -lGLU -lglut \ + -lXmu -lXt -lSM -lICE -lXext -lX11 -lXi -lXext -lX11 -lm -lpthread + + +C_APPL_FILES = cube.c olympic.c testGL1.c testGL2.c wave.c + + +.SUFFIXES : .c .o + +.c.o: + $(CC) -c -o $@ $< $(CCINCL) 2>&1 | tee -a errors + $(CC) -o ${@:.o=} $@ $(CCINCL) $(CCLIBS) 2>&1 | tee -a errors + +all: ${C_APPL_FILES:.c=.o} + + +clean: + rm -f *.o *~ errors + +cleanall: clean + rm -f ${C_APPL_FILES:.c=} + diff --git a/demos/natives/x11/olympic.c b/demos/natives/x11/olympic.c new file mode 100644 index 0000000..0527d58 --- /dev/null +++ b/demos/natives/x11/olympic.c @@ -0,0 +1,409 @@ +
+/* Copyright (c) Mark J. Kilgard, 1994. */
+
+/**
+ * (c) Copyright 1993, 1994, 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <GL/glut.h>
+
+/* Some <math.h> files do not define M_PI... */
+#ifndef M_PI
+#define M_PI 3.141592654
+#endif
+
+extern double drand48(void);
+extern void srand48(long seedval);
+
+#define XSIZE 100
+#define YSIZE 75
+
+#define RINGS 5
+#define BLUERING 0
+#define BLACKRING 1
+#define REDRING 2
+#define YELLOWRING 3
+#define GREENRING 4
+
+#define BACKGROUND 8
+
+enum {
+ BLACK = 0,
+ RED,
+ GREEN,
+ YELLOW,
+ BLUE,
+ MAGENTA,
+ CYAN,
+ WHITE
+};
+
+typedef short Point[2];
+
+GLenum rgb, doubleBuffer, directRender;
+
+unsigned char rgb_colors[RINGS][3];
+int mapped_colors[RINGS];
+float dests[RINGS][3];
+float offsets[RINGS][3];
+float angs[RINGS];
+float rotAxis[RINGS][3];
+int iters[RINGS];
+GLuint theTorus;
+
+void
+FillTorus(float rc, int numc, float rt, int numt)
+{
+ int i, j, k;
+ double s, t;
+ double x, y, z;
+ double pi, twopi;
+
+ pi = M_PI;
+ twopi = 2 * pi;
+
+ for (i = 0; i < numc; i++) {
+ glBegin(GL_QUAD_STRIP);
+ for (j = 0; j <= numt; j++) {
+ for (k = 1; k >= 0; k--) {
+ s = (i + k) % numc + 0.5;
+ t = j % numt;
+
+ x = cos(t * twopi / numt) * cos(s * twopi / numc);
+ y = sin(t * twopi / numt) * cos(s * twopi / numc);
+ z = sin(s * twopi / numc);
+ glNormal3f(x, y, z);
+
+ x = (rt + rc * cos(s * twopi / numc)) * cos(t * twopi / numt);
+ y = (rt + rc * cos(s * twopi / numc)) * sin(t * twopi / numt);
+ z = rc * sin(s * twopi / numc);
+ glVertex3f(x, y, z);
+ }
+ }
+ glEnd();
+ }
+}
+
+float
+Clamp(int iters_left, float t)
+{
+
+ if (iters_left < 3) {
+ return 0.0;
+ }
+ return (iters_left - 2) * t / iters_left;
+}
+
+void
+Idle(void)
+{
+ int i, j;
+ int more = GL_FALSE;
+
+ for (i = 0; i < RINGS; i++) {
+ if (iters[i]) {
+ for (j = 0; j < 3; j++) {
+ offsets[i][j] = Clamp(iters[i], offsets[i][j]);
+ }
+ angs[i] = Clamp(iters[i], angs[i]);
+ iters[i]--;
+ more = GL_TRUE;
+ }
+ }
+ if (more) {
+ glutPostRedisplay();
+ } else {
+ glutIdleFunc(NULL);
+ }
+}
+
+void
+DrawScene(void)
+{
+ int i;
+
+ glPushMatrix();
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
+
+ for (i = 0; i < RINGS; i++) {
+ if (rgb) {
+ glColor3ubv(rgb_colors[i]);
+ } else {
+ glIndexi(mapped_colors[i]);
+ }
+ glPushMatrix();
+ glTranslatef(dests[i][0] + offsets[i][0], dests[i][1] + offsets[i][1],
+ dests[i][2] + offsets[i][2]);
+ glRotatef(angs[i], rotAxis[i][0], rotAxis[i][1], rotAxis[i][2]);
+ glCallList(theTorus);
+ glPopMatrix();
+ }
+
+ glPopMatrix();
+ if (doubleBuffer) {
+ glutSwapBuffers();
+ } else {
+ glFlush();
+ }
+}
+
+float
+MyRand(void)
+{
+ return 10.0 * (drand48() - 0.5);
+}
+
+void
+ReInit(void)
+{
+ int i;
+ float deviation;
+
+ deviation = MyRand() / 2;
+ deviation = deviation * deviation;
+ for (i = 0; i < RINGS; i++) {
+ offsets[i][0] = MyRand();
+ offsets[i][1] = MyRand();
+ offsets[i][2] = MyRand();
+ angs[i] = 260.0 * MyRand();
+ rotAxis[i][0] = MyRand();
+ rotAxis[i][1] = MyRand();
+ rotAxis[i][2] = MyRand();
+ iters[i] = (deviation * MyRand() + 60.0);
+ }
+}
+
+void
+Init(void)
+{
+ int i;
+ float top_y = 1.0;
+ float bottom_y = 0.0;
+ float top_z = 0.15;
+ float bottom_z = 0.69;
+ float spacing = 2.5;
+ static float lmodel_ambient[] =
+ {0.0, 0.0, 0.0, 0.0};
+ static float lmodel_twoside[] =
+ {GL_FALSE};
+ static float lmodel_local[] =
+ {GL_FALSE};
+ static float light0_ambient[] =
+ {0.1, 0.1, 0.1, 1.0};
+ static float light0_diffuse[] =
+ {1.0, 1.0, 1.0, 0.0};
+ static float light0_position[] =
+ {0.8660254, 0.5, 1, 0};
+ static float light0_specular[] =
+ {1.0, 1.0, 1.0, 0.0};
+ static float bevel_mat_ambient[] =
+ {0.0, 0.0, 0.0, 1.0};
+ static float bevel_mat_shininess[] =
+ {40.0};
+ static float bevel_mat_specular[] =
+ {1.0, 1.0, 1.0, 0.0};
+ static float bevel_mat_diffuse[] =
+ {1.0, 0.0, 0.0, 0.0};
+
+ srand48(0x102342);
+ ReInit();
+ for (i = 0; i < RINGS; i++) {
+ rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = 0;
+ }
+ rgb_colors[BLUERING][2] = 255;
+ rgb_colors[REDRING][0] = 255;
+ rgb_colors[GREENRING][1] = 255;
+ rgb_colors[YELLOWRING][0] = 255;
+ rgb_colors[YELLOWRING][1] = 255;
+ mapped_colors[BLUERING] = BLUE;
+ mapped_colors[REDRING] = RED;
+ mapped_colors[GREENRING] = GREEN;
+ mapped_colors[YELLOWRING] = YELLOW;
+ mapped_colors[BLACKRING] = BLACK;
+
+ dests[BLUERING][0] = -spacing;
+ dests[BLUERING][1] = top_y;
+ dests[BLUERING][2] = top_z;
+
+ dests[BLACKRING][0] = 0.0;
+ dests[BLACKRING][1] = top_y;
+ dests[BLACKRING][2] = top_z;
+
+ dests[REDRING][0] = spacing;
+ dests[REDRING][1] = top_y;
+ dests[REDRING][2] = top_z;
+
+ dests[YELLOWRING][0] = -spacing / 2.0;
+ dests[YELLOWRING][1] = bottom_y;
+ dests[YELLOWRING][2] = bottom_z;
+
+ dests[GREENRING][0] = spacing / 2.0;
+ dests[GREENRING][1] = bottom_y;
+ dests[GREENRING][2] = bottom_z;
+
+ theTorus = glGenLists(1);
+ glNewList(theTorus, GL_COMPILE);
+ FillTorus(0.1, 8, 1.0, 25);
+ glEndList();
+
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glEnable(GL_DEPTH_TEST);
+ glClearDepth(1.0);
+
+ if (rgb) {
+ glClearColor(0.5, 0.5, 0.5, 0.0);
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
+ glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
+ glEnable(GL_LIGHT0);
+
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ glEnable(GL_LIGHTING);
+
+ glMaterialfv(GL_FRONT, GL_AMBIENT, bevel_mat_ambient);
+ glMaterialfv(GL_FRONT, GL_SHININESS, bevel_mat_shininess);
+ glMaterialfv(GL_FRONT, GL_SPECULAR, bevel_mat_specular);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, bevel_mat_diffuse);
+
+ glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+ glEnable(GL_COLOR_MATERIAL);
+ glShadeModel(GL_SMOOTH);
+ } else {
+ glClearIndex(BACKGROUND);
+ glShadeModel(GL_FLAT);
+ }
+
+ glMatrixMode(GL_PROJECTION);
+ gluPerspective(45, 1.33, 0.1, 100.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void
+Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+}
+
+/* ARGSUSED1 */
+void
+Key(unsigned char key, int x, int y)
+{
+
+ switch (key) {
+ case 27:
+ exit(0);
+ break;
+ case ' ':
+ ReInit();
+ glutIdleFunc(Idle);
+ break;
+ }
+}
+
+GLenum
+Args(int argc, char **argv)
+{
+ GLint i;
+
+ rgb = GL_TRUE;
+ doubleBuffer = GL_TRUE;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-ci") == 0) {
+ rgb = GL_FALSE;
+ } else if (strcmp(argv[i], "-rgb") == 0) {
+ rgb = GL_TRUE;
+ } else if (strcmp(argv[i], "-sb") == 0) {
+ doubleBuffer = GL_FALSE;
+ } else if (strcmp(argv[i], "-db") == 0) {
+ doubleBuffer = GL_TRUE;
+ } else {
+ printf("%s (Bad option).\n", argv[i]);
+ return GL_FALSE;
+ }
+ }
+ return GL_TRUE;
+}
+
+void
+visible(int vis)
+{
+ if (vis == GLUT_VISIBLE) {
+ glutIdleFunc(Idle);
+ } else {
+ glutIdleFunc(NULL);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ GLenum type;
+
+ glutInitWindowSize(400, 300);
+ glutInit(&argc, argv);
+ if (Args(argc, argv) == GL_FALSE) {
+ exit(1);
+ }
+ type = (rgb) ? GLUT_RGB : GLUT_INDEX;
+ type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
+ glutInitDisplayMode(type);
+
+ glutCreateWindow("Olympic");
+
+ Init();
+
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(DrawScene);
+
+ glutVisibilityFunc(visible);
+
+ glutMainLoop();
+ return 0; /* ANSI C requires main to return int. */
+}
diff --git a/demos/natives/x11/testGL1.c b/demos/natives/x11/testGL1.c new file mode 100644 index 0000000..71f9ab2 --- /dev/null +++ b/demos/natives/x11/testGL1.c @@ -0,0 +1,222 @@ +
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <GL/gl.h>
+#include <GL/glut.h>
+
+double width = 250;
+double height = 250;
+double fps = 25.0;
+
+ static float lmodel_twoside[] =
+ {GL_FALSE};
+ static float lmodel_local[] =
+ {GL_FALSE};
+ static float lmodel_ambient[] =
+ {0.0, 0.0, 0.0, 0.0};
+
+void CylinderDraw( )
+{
+ glBegin( GL_TRIANGLE_STRIP );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f ( 1.0, 0.0, -5.0 );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f (1.000000, 0.000000, 5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, -5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, 5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, -5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, 5.000000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, -5.00000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, 5.00000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, -5.000000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, 5.00000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, -5.000000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, 5.00000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, -5.000000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, 5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, -5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, 5.000000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, -5.00000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, 5.00000);
+ glEnd();
+}
+
+void reshape(int width, int height)
+{
+ double fov = 45.0,
+ aspect = width / height,
+ near_ = 1.0,
+ far_ = 200.0;
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near_, far_ );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+}
+
+void display()
+{
+ static int FrameStep = 0;
+
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glPushMatrix();
+ glTranslatef( 0.0, 0.0, -65.0 );
+ glRotatef( 40.0+(2*FrameStep), 0.0, 0.0, 1.0 );
+ glRotatef( 190.0+(2*FrameStep), 0.0, 1.0, 0.0 );
+ glRotatef( 200.0+(FrameStep*2), 1.0, 0.0, 0.0 );
+ glPushMatrix();
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 0.0, 1.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 1.0, 0.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPopMatrix();
+
+ glutSwapBuffers();
+ /* glFlush(); */
+
+ FrameStep++;
+
+ if(FrameStep>100000) FrameStep=0;
+
+}
+
+void init()
+{
+ double fov = 45.0;
+ double aspect = width / height ;
+ double near_ = 1.0;
+ double far_ = 200.0;
+ float lightArr[4];
+ float farr[4];
+
+ /* initialize the widget */
+ glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
+ glFrontFace( GL_CW );
+ glEnable( GL_DEPTH_TEST );
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near_, far_ );
+
+ /* render three rotated cylinders */
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ /* enable lighting */
+ lightArr[0] = 1.0f; lightArr[1] = 1.0f;
+ lightArr[2] = 1.0f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_DIFFUSE, lightArr );
+ lightArr[0] = 90.0f; lightArr[1] = 90.0f;
+ lightArr[2] = 0.0f; lightArr[3] = 0.0f;
+ glLightfv( GL_LIGHT0, GL_POSITION, lightArr );
+ lightArr[0] = 0.1f; lightArr[1] = 0.1f;
+ lightArr[2] = 0.1f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_AMBIENT, lightArr );
+ glEnable( GL_LIGHT0 );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
+ glEnable( GL_LIGHTING );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ glEnable( GL_LIGHTING );
+ */
+
+
+ glMaterialf( GL_FRONT, GL_SHININESS, 30.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_SPECULAR, farr );
+
+ farr[0] = 0.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, farr );
+
+ glMaterialf( GL_BACK, GL_SHININESS, 50.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 1.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_SPECULAR, farr );
+
+ farr[0] = 1.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_DIFFUSE, farr );
+
+}
+
+void idle()
+{
+ glutPostRedisplay();
+}
+
+int main( int argc, char **argv)
+{
+ fprintf(stderr,"1\n");
+ if(argc>2 && strcmp(argv[1], "-fps")==0)
+ {
+ fprintf(stderr,"2\n");
+ fps = atof(argv[2]);
+ argc-=2;
+ argv+=2;
+ }
+ fprintf(stderr, "Frame Per Secounds %d\n ( will be ignored this time )\n", fps);
+
+ glutInit(&argc, argv);
+ glutInitDisplayMode ( GLUT_DOUBLE
+ | GLUT_DEPTH
+ | GLUT_RGBA
+ );
+ glutInitWindowSize(width,height);
+ glutInitWindowPosition(100,100);
+ glutCreateWindow("OpenGL GLUT/NATIVE");
+ init();
+ glutDisplayFunc(display);
+ glutReshapeFunc(reshape);
+ glutIdleFunc(idle);
+ glutMainLoop();
+ return 0;
+}
+
diff --git a/demos/natives/x11/testGL2.c b/demos/natives/x11/testGL2.c new file mode 100644 index 0000000..335acc9 --- /dev/null +++ b/demos/natives/x11/testGL2.c @@ -0,0 +1,517 @@ +#include <stdio.h>
+#include <stdlib.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+Display *dpy; /* X display connection */
+Window xid; /* X window id */
+GLXContext glid; /* GL window id */
+
+double width = 250;
+double height = 250;
+double fps = 25.0;
+
+ static float lmodel_twoside[] =
+ {GL_FALSE};
+ static float lmodel_local[] =
+ {GL_FALSE};
+ static float lmodel_ambient[] =
+ {0.0, 0.0, 0.0, 0.0};
+
+void CylinderDraw( )
+{
+ glBegin( GL_TRIANGLE_STRIP );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f ( 1.0, 0.0, -5.0 );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f (1.000000, 0.000000, 5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, -5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, 5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, -5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, 5.000000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, -5.00000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, 5.00000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, -5.000000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, 5.00000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, -5.000000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, 5.00000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, -5.000000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, 5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, -5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, 5.000000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, -5.00000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, 5.00000);
+ glEnd();
+}
+
+void reshape(int width, int height)
+{
+ double fov = 45.0,
+ aspect = width / height,
+ near = 1.0,
+ far = 200.0;
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near, far );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+}
+
+void display()
+{
+ static int FrameStep = 0;
+
+ glXWaitGL();
+ glXWaitX();
+ /* associated the context with the X window */
+ if( glXMakeCurrent( dpy, xid, glid ) == False) {
+ glXDestroyContext( display, glid );
+ fprintf(stderr,"(NO GC ASSOC)\n");
+ fflush(stderr);
+ return 1;
+ }
+
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glPushMatrix();
+ glTranslatef( 0.0, 0.0, -65.0 );
+ glRotatef( 40.0+(2*FrameStep), 0.0, 0.0, 1.0 );
+ glRotatef( 190.0+(2*FrameStep), 0.0, 1.0, 0.0 );
+ glRotatef( 200.0+(FrameStep*2), 1.0, 0.0, 0.0 );
+ glPushMatrix();
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 0.0, 1.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 1.0, 0.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPopMatrix();
+
+ glXWaitGL();
+ glXWaitX();
+ glXSwapBuffers(dpy, xid);
+
+ glXWaitGL();
+ glXWaitX();
+ /* associated the context with the X window */
+ if( glXMakeCurrent( dpy, None, NULL ) == False) {
+ glXDestroyContext( display, glid );
+ fprintf(stderr,"(free GC failed)\n");
+ fflush(stderr);
+ return 1;
+ }
+
+ FrameStep++;
+
+ if(FrameStep>100000) FrameStep=0;
+
+}
+
+void init()
+{
+ double fov = 45.0;
+ double aspect = width / height ;
+ double near = 1.0;
+ double far = 200.0;
+ float lightArr[4];
+ float farr[4];
+
+ /* initialize the widget */
+ glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
+ glFrontFace( GL_CW );
+ glEnable( GL_DEPTH_TEST );
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near, far );
+
+ /* render three rotated cylinders */
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ /* enable lighting */
+ lightArr[0] = 1.0f; lightArr[1] = 1.0f;
+ lightArr[2] = 1.0f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_DIFFUSE, lightArr );
+ lightArr[0] = 90.0f; lightArr[1] = 90.0f;
+ lightArr[2] = 0.0f; lightArr[3] = 0.0f;
+ glLightfv( GL_LIGHT0, GL_POSITION, lightArr );
+ lightArr[0] = 0.1f; lightArr[1] = 0.1f;
+ lightArr[2] = 0.1f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_AMBIENT, lightArr );
+ glEnable( GL_LIGHT0 );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
+ glEnable( GL_LIGHTING );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ glEnable( GL_LIGHTING );
+ */
+
+
+ glMaterialf( GL_FRONT, GL_SHININESS, 30.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_SPECULAR, farr );
+
+ farr[0] = 0.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, farr );
+
+ glMaterialf( GL_BACK, GL_SHININESS, 50.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 1.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_SPECULAR, farr );
+
+ farr[0] = 1.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_DIFFUSE, farr );
+
+}
+
+
+static void GetLargeVisual(Display *dpy, XVisualInfo *bigVisualInfo);
+static XVisualInfo *findVisualGlX( Display *display);
+Window findAWindow( const char *frameName, Display *display, Window window);
+int verbose=1;
+
+main()
+{
+ XWMHints *p_xwmh=NULL;
+ Window xid2;
+ XEvent event;
+ XVisualInfo bigVisualInfo; /* largest pseudo color visual type */
+ XSetWindowAttributes attribs; /* X window attributes structure */
+ Colormap bigColormap; /* 12-bit color map */
+ unsigned long vmask; /* value mask for attributes */
+ int i;
+
+
+ /* Get the X display connection. We'll assume that the DISPLAY
+ * environment variable is "unix:0" since GL windows only run on
+ * on the local display. */
+ if(!(dpy = XOpenDisplay(""))) {
+ printf("\n can't open display connection \n");
+ exit(0);
+ }
+
+ /* GetLargeVisual(dpy, &bigVisualInfo); */
+ bigVisualInfo = * findVisualGlX(dpy);
+ printf("\n address of XVisualInfo structure = 0x%x \n", bigVisualInfo);
+ printf("\n address of Visual structure = 0x%x ", bigVisualInfo.visual);
+ printf("\n visualID = 0x%x ", bigVisualInfo.visualid);
+ printf("\n depth of visual = %d", bigVisualInfo.depth);
+ printf("\n class of visual = %d", bigVisualInfo.class);
+ printf("\n bits_per_rgb of visual = %d", bigVisualInfo.bits_per_rgb);
+ printf("\n colormap_size of visual = %d \n", bigVisualInfo.colormap_size);
+
+ attribs.event_mask =
+ ExposureMask;
+ attribs.border_pixel =
+ BlackPixel(dpy, bigVisualInfo.screen);
+ attribs.colormap =
+ XCreateColormap( dpy,
+ RootWindow( dpy, bigVisualInfo.screen ),
+ bigVisualInfo.visual,
+ AllocNone ) ;
+
+
+ attribs.background_pixel = 0xFFFFFFFF;
+
+ attribs.background_pixel =
+ BlackPixel(dpy, bigVisualInfo.screen);
+
+ attribs.border_pixmap = None;
+ attribs.background_pixmap = None;
+
+ vmask = CWColormap | CWBorderPixmap | CWBackPixmap;
+ vmask = CWEventMask | CWColormap | CWBorderPixel | CWBackPixel;
+
+ xid =
+ XCreateWindow(dpy,
+ RootWindow( dpy, bigVisualInfo.screen ),
+ 0,0, 400, 400,
+ 0,
+ bigVisualInfo.depth,
+ InputOutput, bigVisualInfo.visual,
+ vmask,
+ &attribs);
+
+ /* Name the window, map it, and flush the X buffer. */
+ XStoreName(dpy, xid, "GLWindow");
+ XMapWindow(dpy, xid);
+ XFlush(dpy);
+
+ glid = glXCreateContext( dpy, &bigVisualInfo, None, True );
+
+ /* check if the context could be created */
+ if( glid == NULL ) {
+ fprintf(stderr,"(NO GC)\n");
+ fflush(stderr);
+ return 1;
+ }
+ /* associated the context with the X window */
+ if( glXMakeCurrent( dpy, xid, glid ) == False) {
+ glXDestroyContext( display, glid );
+ fprintf(stderr,"(NO GC ASSOC)\n");
+ fflush(stderr);
+ return 1;
+ }
+
+ XFlush(dpy);
+ XRaiseWindow (dpy, xid);
+
+ xid2 = findAWindow("GLWindow", dpy, RootWindow( dpy, bigVisualInfo.screen ));
+
+ if(xid==xid2)
+ fprintf(stderr,"found win equals created win\n");
+ else
+ fprintf(stderr,"found win ** NOT ** equals created win\n");
+ fflush(stderr);
+
+ if((p_xwmh = XAllocWMHints()) == NULL)
+ {
+ fprintf(stderr,"No Mem for WMHints\n");
+ fflush(stderr);
+ exit(1);
+ }
+ p_xwmh->flags = (InputHint|StateHint);
+ p_xwmh->input = True;
+ p_xwmh->initial_state=NormalState;
+
+ XSetWMHints(dpy, xid, p_xwmh);
+
+ init();
+
+ for(;;)
+ display();
+
+ /* exit */
+ XDestroyWindow(dpy, xid);
+ XCloseDisplay(dpy);
+}
+
+/* ============================================================== */
+/* The following routine draws a constant pitch spiral,
+ * with initial radius r0, pitch p,
+ * nsteps line segments per revolution,
+ * and nrev revolutions */
+
+/* ============================================================== */
+
+void GetLargeVisual(Display *dpy, XVisualInfo *bigVisualInfo)
+{
+ XVisualInfo *visual_info; /* Info. about visual classes */
+ /*
+ * Get all visuals based on these masks
+ */
+ long vinfo_mask = VisualClassMask | VisualScreenMask;
+ XVisualInfo vtemp ; /* template for visuals to look for */
+ int i; /* counter */
+ int nitem ; /* number of visuals returned */
+
+ /*
+ * Get All PseudoColor Visuals
+ */
+ vtemp.class = PseudoColor ; /* Set PseudoColor class */
+ vtemp.screen = DefaultScreen(dpy) ; /* Set screen */
+ /*
+ * Get all visuals of the correct class on the correct screen
+ */
+ visual_info = XGetVisualInfo(dpy, vinfo_mask, &vtemp, &nitem) ;
+ /*
+ * Search for largest visual from all visual classes
+ */
+ *(bigVisualInfo) = *(visual_info);
+
+
+ /* NOTE: on GXT1000 and GXT500 family, winX does not support
+ * overlay window, so careful not to pick up overlay visual
+ * here!
+ */
+
+ for (i=0; i<nitem; i++, visual_info++) {
+ if (visual_info->colormap_size >= bigVisualInfo->colormap_size) {
+ *(bigVisualInfo) = *(visual_info);
+ }
+ }
+ /*
+ * return largest visual
+ */
+ return;
+}
+
+static XVisualInfo *findVisualGlX( Display *display )
+{
+ int visualAttribList[11];
+ XVisualInfo *visual;
+
+ /* Ask GLX for a visual that matches the attributes we want: Single
+ buffered and RGB with at least 4 bits for each component
+ */
+ visualAttribList[0] = GLX_RGBA;
+ visualAttribList[1] = GLX_RED_SIZE;
+ visualAttribList[2] = 1;
+ visualAttribList[3] = GLX_GREEN_SIZE;
+ visualAttribList[4] = 1;
+ visualAttribList[5] = GLX_BLUE_SIZE;
+ visualAttribList[6] = 1;
+ visualAttribList[7] = GLX_DOUBLEBUFFER;
+ visualAttribList[8] = GLX_DEPTH_SIZE;
+ visualAttribList[9] = 1;
+ visualAttribList[10] = None;
+
+ visual = glXChooseVisual( display,
+ DefaultScreen( display ),
+ visualAttribList );
+ fprintf(stderr, "\nused vi(ID:%d): \n screen %d, depth %d, class %d,\n clrmapsz %d, bitsPerRGB %d\n",
+ visual->visualid,
+ visual->screen,
+ visual->depth,
+ visual->class,
+ visual->colormap_size,
+ visual->bits_per_rgb );
+ fflush(stderr);
+
+ return( visual );
+}
+
+Window findAWindow( const char *frameName, Display *display, Window window)
+{
+ /* Variables used to find the correct java Window to render into */
+ Window root, parent, *children;
+ unsigned int numOfChildren;
+ char *buff;
+ int i, status;
+ Window retWindow, lastWindow;
+
+ /* debug helpers */
+ int i1, i2, i3;
+
+ XFlush(display);
+
+ status = XFetchName( display, window, &buff );
+
+ if( status )
+ {
+ if( !strcmp( frameName, buff ) )
+ {
+ /* Ok, we've found it,
+ so return the last child under this heirarchy
+ */
+ lastWindow = window;
+
+ XFlush(display);
+
+ status = XQueryTree( display, window,
+ &root, &parent, &children, &numOfChildren );
+
+ if(verbose)
+ {
+ fprintf(stderr,"\nfjw 4 (got :0x%x with %d childs)\n",
+ window, numOfChildren);
+ fflush(stderr);
+ }
+
+ i1=0;
+
+ while( status )
+ {
+ if( children == NULL )
+ {
+ XFlush(display);
+
+ if(verbose)
+ {
+ fprintf(stderr,"\nfjw 4 (FOUND LAST WINDOW 0x%x)\n",
+ lastWindow);
+ fflush(stderr);
+ }
+ return lastWindow;
+ }
+ lastWindow = children[numOfChildren-1];
+
+ status = XQueryTree( display, lastWindow,
+ &root, &parent, &children, &numOfChildren );
+
+ if(verbose)
+ {
+ fprintf(stderr,"fjw 4 (got :0x%x with %d childs)\n",
+ lastWindow, numOfChildren);
+ fflush(stderr);
+ }
+
+ XFlush(display);
+
+ }
+
+ return (Window)0;
+ }
+ }
+
+ /* If Window has no name, or if it's not equal to the java Frame window name
+ carry on searching recursivly
+ */
+ status = XQueryTree( display, window,
+ &root, &parent, &children, &numOfChildren );
+
+ XFlush(display);
+
+ if( status )
+ {
+ for( i=0; i < numOfChildren; i++ )
+ {
+ retWindow = findAWindow( frameName, display, children[ i ]);
+ if( retWindow )
+ {
+ /* Free up the child list */
+ /* XFree( children ); */
+ return retWindow;
+ }
+ }
+ }
+
+ /* Free up the child list */
+ /* if(children!=0) XFree( children ); */
+ return (Window)0;
+}
diff --git a/demos/natives/x11/wave.c b/demos/natives/x11/wave.c new file mode 100644 index 0000000..36d518d --- /dev/null +++ b/demos/natives/x11/wave.c @@ -0,0 +1,500 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include "GL/glut.h" + + +#ifndef PI +#define PI 3.14159265358979323846 +#endif + +#define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)])) +#define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX])) + + +GLenum rgb, doubleBuffer, directRender; + +GLint colorIndexes1[3]; +GLint colorIndexes2[3]; +GLenum clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; + +GLenum smooth = GL_FALSE; +GLenum lighting = GL_TRUE; +GLenum depth = GL_TRUE; +GLenum stepMode = GL_FALSE; +GLenum spinMode = GL_FALSE; +GLint contouring = 0; + +GLint widthX, widthY; +GLint checkerSize; +float height; + +GLint frames, curFrame = 0, nextFrame = 0; + +struct facet { + float color[3]; + float normal[3]; +}; +struct coord { + float vertex[3]; + float normal[3]; +}; +struct mesh { + GLint widthX, widthY; + GLint numFacets; + GLint numCoords; + GLint frames; + struct coord *coords; + struct facet *facets; +} theMesh; + +GLubyte contourTexture1[] = { + 255, 255, 255, 255, + 255, 255, 255, 255, + 255, 255, 255, 255, + 127, 127, 127, 127, +}; +GLubyte contourTexture2[] = { + 255, 255, 255, 255, + 255, 127, 127, 127, + 255, 127, 127, 127, + 255, 127, 127, 127, +}; + + +static void display(void) +{ + struct coord *coord; + struct facet *facet; + float *lastColor; + float *thisColor; + GLint i, j; + + glClear(clearMask); + + if (nextFrame || !stepMode) { + curFrame++; + } + if (curFrame >= theMesh.frames) { + curFrame = 0; + } + + if ((nextFrame || !stepMode) && spinMode) { + glRotatef(5.0, 0.0, 0.0, 1.0); + } + nextFrame = 0; + + for (i = 0; i < theMesh.widthX; i++) { + glBegin(GL_QUAD_STRIP); + lastColor = NULL; + for (j = 0; j < theMesh.widthY; j++) { + facet = GETFACET(curFrame, i, j); + if (!smooth && lighting) { + glNormal3fv(facet->normal); + } + if (lighting) { + thisColor = facet->color; + glColor3fv(facet->color); + } else { + thisColor = facet->color; + glColor3fv(facet->color); + } + + if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) { + if (lastColor) { + glEnd(); + glBegin(GL_QUAD_STRIP); + } + coord = GETCOORD(curFrame, i, j); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + coord = GETCOORD(curFrame, i+1, j); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + } + + coord = GETCOORD(curFrame, i, j+1); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + coord = GETCOORD(curFrame, i+1, j+1); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + lastColor = thisColor; + } + glEnd(); + } + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + + +static void InitMesh(void) +{ + struct coord *coord; + struct facet *facet; + float dp1[3], dp2[3]; + float *pt1, *pt2, *pt3; + float angle, d, x, y; + GLint numFacets, numCoords, frameNum, i, j; + + theMesh.widthX = widthX; + theMesh.widthY = widthY; + theMesh.frames = frames; + + numFacets = widthX * widthY; + numCoords = (widthX + 1) * (widthY + 1); + + theMesh.numCoords = numCoords; + theMesh.numFacets = numFacets; + + theMesh.coords = (struct coord *)malloc(frames*numCoords* + sizeof(struct coord)); + theMesh.facets = (struct facet *)malloc(frames*numFacets* + sizeof(struct facet)); + if (theMesh.coords == NULL || theMesh.facets == NULL) { + printf("Out of memory.\n"); + exit(0); + } + + for (frameNum = 0; frameNum < frames; frameNum++) { + for (i = 0; i <= widthX; i++) { + x = i / (float)widthX; + for (j = 0; j <= widthY; j++) { + y = j / (float)widthY; + + d = sqrt(x*x+y*y); + if (d == 0.0) { + d = 0.0001; + } + angle = 2 * PI * d + (2 * PI / frames * frameNum); + + coord = GETCOORD(frameNum, i, j); + + coord->vertex[0] = x - 0.5; + coord->vertex[1] = y - 0.5; + coord->vertex[2] = (height - height * d) * cos(angle); + + coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI * + sin(angle) + cos(angle)); + coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI * + sin(angle) + cos(angle)); + coord->normal[2] = -1; + + d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+ + coord->normal[1]*coord->normal[1]+1); + coord->normal[0] *= d; + coord->normal[1] *= d; + coord->normal[2] *= d; + } + } + for (i = 0; i < widthX; i++) { + for (j = 0; j < widthY; j++) { + facet = GETFACET(frameNum, i, j); + if (((i/checkerSize)%2)^(j/checkerSize)%2) { + facet->color[0] = 1.0; + facet->color[1] = 0.2; + facet->color[2] = 0.2; + } else { + facet->color[0] = 0.2; + facet->color[1] = 1.0; + facet->color[2] = 0.2; + } + pt1 = GETCOORD(frameNum, i, j)->vertex; + pt2 = GETCOORD(frameNum, i, j+1)->vertex; + pt3 = GETCOORD(frameNum, i+1, j+1)->vertex; + + dp1[0] = pt2[0] - pt1[0]; + dp1[1] = pt2[1] - pt1[1]; + dp1[2] = pt2[2] - pt1[2]; + + dp2[0] = pt3[0] - pt2[0]; + dp2[1] = pt3[1] - pt2[1]; + dp2[2] = pt3[2] - pt2[2]; + + facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1]; + facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2]; + facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0]; + + d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+ + facet->normal[1]*facet->normal[1]+ + facet->normal[2]*facet->normal[2]); + + facet->normal[0] *= d; + facet->normal[1] *= d; + facet->normal[2] *= d; + } + } + } +} + +static void InitMaterials(void) +{ + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; + static float position[] = {90.0, 90.0, 150.0, 0.0}; + static float front_mat_shininess[] = {60.0}; + static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; + static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; + static float back_mat_shininess[] = {60.0}; + static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; + static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; + static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; + static float lmodel_twoside[] = {GL_TRUE}; + + glMatrixMode(GL_PROJECTION); + gluPerspective(450, 1.0, 0.5, 10.0); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + + glEnable(GL_COLOR_MATERIAL); +} + +static void InitTexture(void) +{ + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +void +Idle(void) +{ + glutPostRedisplay(); +} + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glShadeModel(GL_FLAT); + + glFrontFace(GL_CW); + + glEnable(GL_DEPTH_TEST); + + InitMaterials(); + InitTexture(); + InitMesh(); + + glMatrixMode(GL_MODELVIEW); + glTranslatef(0.0, 0.4, -1.8); + glScalef(2.0, 2.0, 2.0); + glRotatef(-35.0, 1.0, 0.0, 0.0); + glRotatef(35.0, 0.0, 0.0, 1.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); +} + +void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(0); break; + case 'c': + contouring++; + if (contouring == 1) { + static GLfloat map[4] = {0, 0, 20, 0}; + + glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE, + GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGenfv(GL_S, GL_OBJECT_PLANE, map); + glTexGenfv(GL_T, GL_OBJECT_PLANE, map); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } else if (contouring == 2) { + static GLfloat map[4] = {0, 0, 20, 0}; + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTexGenfv(GL_S, GL_EYE_PLANE, map); + glTexGenfv(GL_T, GL_EYE_PLANE, map); + glPopMatrix(); + } else { + contouring = 0; + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_2D); + } + break; + case 's': + smooth = !smooth; + if (smooth) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + break; + case 'l': + lighting = !lighting; + if (lighting) { + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_COLOR_MATERIAL); + } else { + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_COLOR_MATERIAL); + } + break; + case 'd': + depth = !depth; + if (depth) { + glEnable(GL_DEPTH_TEST); + clearMask |= GL_DEPTH_BUFFER_BIT; + } else { + glDisable(GL_DEPTH_TEST); + clearMask &= ~GL_DEPTH_BUFFER_BIT; + } + break; + case ' ': + stepMode = !stepMode; + if (stepMode) { + glutIdleFunc(0); + } else { + glutIdleFunc(Idle); + } + break; + case 'n': + if (stepMode) { + nextFrame = 1; + } + break; + case 'a': + spinMode = !spinMode; + break; + default: + return ; + } + return ; +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_TRUE; + directRender = GL_TRUE; + rgb = GL_TRUE; + frames = 10; + widthX = 10; + widthY = 10; + checkerSize = 2; + height = 0.2; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-dr") == 0) { + directRender = GL_TRUE; + } else if (strcmp(argv[i], "-ir") == 0) { + directRender = GL_FALSE; + } else if (strcmp(argv[i], "-grid") == 0) { + if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') { + printf("-grid (No numbers).\n"); + return GL_FALSE; + } else { + widthX = atoi(argv[++i]); + widthY = atoi(argv[++i]); + } + } else if (strcmp(argv[i], "-size") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-checker (No number).\n"); + return GL_FALSE; + } else { + checkerSize = atoi(argv[++i]); + } + } else if (strcmp(argv[i], "-wave") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-wave (No number).\n"); + return GL_FALSE; + } else { + height = atof(argv[++i]); + } + } else if (strcmp(argv[i], "-frames") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-frames (No number).\n"); + return GL_FALSE; + } else { + frames = atoi(argv[++i]); + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int +main(int argc, char **argv) +{ + GLenum type; + + glutInitWindowSize(300, 300); + glutInit(&argc, argv); + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + type = (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + glutCreateWindow("wave"); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutIdleFunc(Idle); + glutDisplayFunc(display); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + |