From 035e96ec3cf25dfa39dcdacb0f0c7b57d9d2b85a Mon Sep 17 00:00:00 2001 From: Jon Taylor Date: Sat, 21 Aug 1999 06:27:37 +0000 Subject: *** empty log message *** --- progs/ggi/asc-view.c | 353 +++++++++++++++++++++++++++++++++++++++++++++ progs/ggi/blah | 2 + progs/ggi/blat | 7 + progs/ggi/box.asc | 66 +++++++++ progs/ggi/cone.asc | 198 ++++++++++++++++++++++++++ progs/ggi/gears.c | 359 ++++++++++++++++++++++++++++++++++++++++++++++ progs/ggi/gears2.c | 359 ++++++++++++++++++++++++++++++++++++++++++++++ progs/ggi/sphere.asc | 132 +++++++++++++++++ progs/ggi/torus.asc | 264 ++++++++++++++++++++++++++++++++++ progs/ggi/tube.asc | 396 +++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 2136 insertions(+) create mode 100644 progs/ggi/asc-view.c create mode 100644 progs/ggi/blah create mode 100644 progs/ggi/blat create mode 100644 progs/ggi/box.asc create mode 100644 progs/ggi/cone.asc create mode 100644 progs/ggi/gears.c create mode 100644 progs/ggi/gears2.c create mode 100644 progs/ggi/sphere.asc create mode 100644 progs/ggi/torus.asc create mode 100644 progs/ggi/tube.asc (limited to 'progs/ggi') diff --git a/progs/ggi/asc-view.c b/progs/ggi/asc-view.c new file mode 100644 index 0000000000..16f53e5509 --- /dev/null +++ b/progs/ggi/asc-view.c @@ -0,0 +1,353 @@ +/* + test program for the ggi-mesa driver + + Copyright (C) 1997,1998 Uwe Maurer - uwe_maurer@t-online.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +ggi_visual_t vis,vis_mem; + +GGIMesaContext ctx; + +int screen_x=320,screen_y=200; +ggi_graphtype bpp=GT_16BIT; + +//#define ZBUFFER + +//#define SMOOTH_NORMALS + +void Init() +{ + GLfloat h=(GLfloat)3/4; + GLfloat pos[4]={5,5,-20,0}; + GLfloat specular[4]={.4,.4,.4,1}; + GLfloat diffuse[4]={.3,.3,.3,1}; + GLfloat ambient[4]={.2,.2,.2,1}; + + int err; + + if (ggiInit()<0) + { + printf("ggiInit() failed\n"); + exit(1); + } + ctx=GGIMesaCreateContext(); + if (ctx==NULL) + { + printf("Can't create Context!\n"); + exit(1); + } + + vis=ggiOpen(NULL); + vis_mem=ggiOpen("display-memory",NULL); + if (vis==NULL || vis_mem==NULL) + { + printf("Can't open ggi_visuals!\n"); + exit(1); + } + err=ggiSetGraphMode(vis,screen_x,screen_y,screen_x,screen_y,bpp); + err+=ggiSetGraphMode(vis_mem,screen_x,screen_y,screen_x,screen_y,bpp); + if (err) + { + printf("Can't set %ix%i\n",screen_x,screen_y); + exit(1); + } + + if (GGIMesaSetVisual(ctx,vis_mem,GL_TRUE,GL_FALSE)<0) + { + printf("GGIMesaSetVisual() failed!\n"); + exit(1); + } + + GGIMesaMakeCurrent(ctx); + + glViewport(0,0,screen_x,screen_y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1,1,-h,h,1,50); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0,0,-9); + glShadeModel(GL_FLAT); + + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glLightfv(GL_LIGHT0,GL_POSITION,pos); + + glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse); + glLightfv(GL_LIGHT0,GL_AMBIENT,ambient); + glLightfv(GL_LIGHT0,GL_SPECULAR,specular); + + #ifdef ZBUFFER + glEnable(GL_DEPTH_TEST); + #endif +} + + +#define MAX_VERTS 1000 +#define MAX_TRIS 2000 +#define MAX_LEN 1024 +#define MAX_F 100000000 + +void LoadAsc(GLuint *list,char *file) +{ + FILE *fp; + + GLfloat p[MAX_VERTS][3]; + GLfloat normal[MAX_VERTS][3]; + float ncount[MAX_VERTS]; + int v[MAX_TRIS][3]; + char line[MAX_LEN]; + char *s; + int i,j; + int verts,faces; + GLuint v0,v1,v2; + GLfloat n[3]; + GLfloat len,k; + GLfloat min[3]={MAX_F,MAX_F,MAX_F}; + GLfloat max[3]={-MAX_F,-MAX_F,-MAX_F}; + char *coord_str[]={"X","Z","Y"}; + + fp=fopen(file,"r"); + if (!fp) + { + printf("Can't open %s!\n",file); + exit(1); + } + + while (strncmp(fgets(line,MAX_LEN,fp),"Tri-mesh",8)) ; + + s=strstr(line,":")+1; + verts=atoi(s); + s=strstr(s,":")+1; + faces=atoi(s); + + if (verts>MAX_VERTS) + { + printf("Too many vertices..\n"); + exit(1); + } + + while (strncmp(fgets(line,MAX_LEN,fp),"Vertex list",11)) ; + + for (i=0;imax[j]) max[j]=k; + if (klen) {len=k;j=i;} + n[i]=(max[i]+min[i])/2; + } + + len/=2; + + for (i=0;iread); + rotate+=10; + frames++; + if (frames==(*maxframes)) break; + + if (ggiKbhit(vis)) + { + *maxframes=frames; + break; + } + } + + gettimeofday(&stop,NULL); + len=(double)(stop.tv_sec-start.tv_sec)+ + (double)(stop.tv_usec-start.tv_usec)/1e6; + return len; +} + + +int main(int argc,char **argv) +{ + GLuint l; + char *file; + int maxframes=0; + double len; + + Init(); + + file=(argc>1) ? argv[1] : "asc/box.asc"; + if (argc>2) maxframes=atoi(argv[2]); + + if (argc==1) + { + printf("usage: %s filename.asc\n",argv[0]); + } + + LoadAsc(&l,file); + + len=Display(l,&maxframes); + + printf("\ttime: %.3f sec\n",len); + printf("\tframes: %i\n",maxframes); + printf("\tfps: %.3f \n",(double)maxframes/len); + + GGIMesaDestroyContext(ctx); + ggiClose(vis); + ggiClose(vis_mem); + ggiExit(); + return 0; +} + diff --git a/progs/ggi/blah b/progs/ggi/blah new file mode 100644 index 0000000000..2c1664d7d0 --- /dev/null +++ b/progs/ggi/blah @@ -0,0 +1,2 @@ +Terminating on signal 11 + diff --git a/progs/ggi/blat b/progs/ggi/blat new file mode 100644 index 0000000000..7ff64a9d10 --- /dev/null +++ b/progs/ggi/blat @@ -0,0 +1,7 @@ +#!/bin/sh + +function foobar() { + echo "foo!" +} + +foobar diff --git a/progs/ggi/box.asc b/progs/ggi/box.asc new file mode 100644 index 0000000000..f8b23fd85a --- /dev/null +++ b/progs/ggi/box.asc @@ -0,0 +1,66 @@ +Ambient light color: Red=0.039216 Green=0.039216 Blue=0.039216 + +Named object: "Object01" +Tri-mesh, Vertices: 8 Faces: 12 +Vertex list: +Vertex 0: X: -20 Y: -19.999998 Z: 20.000002 +Vertex 1: X: 20 Y: -19.999998 Z: 20.000002 +Vertex 2: X: 20 Y: 20.000002 Z: 19.999998 +Vertex 3: X: -20 Y: 20.000002 Z: 19.999998 +Vertex 4: X: -20 Y: -20.000002 Z: -19.999998 +Vertex 5: X: 20 Y: -20.000002 Z: -19.999998 +Vertex 6: X: 20 Y: 19.999998 Z: -20.000002 +Vertex 7: X: -20 Y: 19.999998 Z: -20.000002 +Face list: +Face 0: A:0 B:1 C:2 AB:1 BC:1 CA:0 +Smoothing: 1 +Face 1: A:0 B:2 C:3 AB:0 BC:1 CA:1 +Smoothing: 1 +Face 2: A:0 B:4 C:5 AB:1 BC:1 CA:0 +Smoothing: 2 +Face 3: A:0 B:5 C:1 AB:0 BC:1 CA:1 +Smoothing: 2 +Face 4: A:1 B:5 C:6 AB:1 BC:1 CA:0 +Smoothing: 3 +Face 5: A:1 B:6 C:2 AB:0 BC:1 CA:1 +Smoothing: 3 +Face 6: A:2 B:6 C:7 AB:1 BC:1 CA:0 +Smoothing: 4 +Face 7: A:2 B:7 C:3 AB:0 BC:1 CA:1 +Smoothing: 4 +Face 8: A:3 B:7 C:4 AB:1 BC:1 CA:0 +Smoothing: 5 +Face 9: A:3 B:4 C:0 AB:0 BC:1 CA:1 +Smoothing: 5 +Face 10: A:4 B:7 C:6 AB:1 BC:1 CA:0 +Smoothing: 6 +Face 11: A:4 B:6 C:5 AB:0 BC:1 CA:1 +Smoothing: 6 + + + + + + + + + + + + + + + + + + + + + + + + + Page 1 + + + diff --git a/progs/ggi/cone.asc b/progs/ggi/cone.asc new file mode 100644 index 0000000000..5c52285996 --- /dev/null +++ b/progs/ggi/cone.asc @@ -0,0 +1,198 @@ +Ambient light color: Red=0.039216 Green=0.039216 Blue=0.039216 + +Named object: "Object01" +Tri-mesh, Vertices: 34 Faces: 64 +Vertex list: +Vertex 0: X: 60.167416 Y: -87.419525 Z: -53.3088 +Vertex 1: X: 76.70787 Y: -87.419518 Z: -29.84565 +Vertex 2: X: 83.0103 Y: -87.419518 Z: -1.838764 +Vertex 3: X: 78.115204 Y: -87.419518 Z: 26.448057 +Vertex 4: X: 62.767834 Y: -87.41951 Z: 50.708401 +Vertex 5: X: 39.304672 Y: -87.41951 Z: 67.248848 +Vertex 6: X: 11.297782 Y: -87.41951 Z: 73.551254 +Vertex 7: X: -16.989004 Y: -87.41951 Z: 68.656158 +Vertex 8: X: -41.249344 Y: -87.41951 Z: 53.308777 +Vertex 9: X: -57.789783 Y: -87.419518 Z: 29.845612 +Vertex 10: X: -64.092194 Y: -87.419518 Z: 1.838721 +Vertex 11: X: -59.197079 Y: -87.419518 Z: -26.448097 +Vertex 12: X: -43.849678 Y: -87.419525 Z: -50.708427 +Vertex 13: X: -20.386503 Y: -87.419525 Z: -67.248856 +Vertex 14: X: 7.62039 Y: -87.419525 Z: -73.551239 +Vertex 15: X: 35.907204 Y: -87.419525 Z: -68.656105 +Vertex 16: X: 101.684875 Y: 94.590591 Z: -96.955391 +Vertex 17: X: 131.767838 Y: 94.590591 Z: -54.281792 +Vertex 18: X: 143.230377 Y: 94.590599 Z: -3.344275 +Vertex 19: X: 134.327423 Y: 94.590607 Z: 48.102379 +Vertex 20: X: 106.414383 Y: 94.590607 Z: 92.225876 +Vertex 21: X: 63.740765 Y: 94.590607 Z: 122.3088 +Vertex 22: X: 12.803238 Y: 94.590614 Z: 133.771301 +Vertex 23: X: -38.643349 Y: 94.590607 Z: 124.868355 +Vertex 24: X: -82.766846 Y: 94.590607 Z: 96.955307 +Vertex 25: X: -112.849762 Y: 94.590607 Z: 54.281677 +Vertex 26: X: -124.312256 Y: 94.590599 Z: 3.344152 +Vertex 27: X: -115.409271 Y: 94.590591 Z: -48.102493 +Vertex 28: X: -87.496201 Y: 94.590591 Z: -92.225967 +Vertex 29: X: -44.822552 Y: 94.590591 Z: -122.308861 +Vertex 30: X: 6.114983 Y: 94.590584 Z: -133.771332 +Vertex 31: X: 57.561623 Y: 94.590591 Z: -124.868301 +Vertex 32: X: 9.459057 Y: -87.419518 Z: 0.000008 +Vertex 33: X: 9.459057 Y: 94.590599 Z: -0.000008 +Face list: +Face 0: A:0 B:1 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 1: A:1 B:2 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 2: A:2 B:3 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 3: A:3 B:4 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 4: A:4 B:5 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 5: A:5 B:6 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 6: A:6 B:7 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 7: A:7 B:8 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 8: A:8 B:9 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 9: A:9 B:10 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 10: A:10 B:11 C:32 AB:1 BC:0 CA:0 + + Page 1 + + + +Smoothing: 1 +Face 11: A:11 B:12 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 12: A:12 B:13 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 13: A:13 B:14 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 14: A:14 B:15 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 15: A:15 B:0 C:32 AB:1 BC:0 CA:0 +Smoothing: 1 +Face 16: A:0 B:16 C:17 AB:1 BC:1 CA:0 +Smoothing: 2 +Face 17: A:0 B:17 C:1 AB:0 BC:1 CA:1 +Smoothing: 2 +Face 18: A:1 B:17 C:18 AB:1 BC:1 CA:0 +Smoothing: 3 +Face 19: A:1 B:18 C:2 AB:0 BC:1 CA:1 +Smoothing: 3 +Face 20: A:2 B:18 C:19 AB:1 BC:1 CA:0 +Smoothing: 4 +Face 21: A:2 B:19 C:3 AB:0 BC:1 CA:1 +Smoothing: 4 +Face 22: A:3 B:19 C:20 AB:1 BC:1 CA:0 +Smoothing: 5 +Face 23: A:3 B:20 C:4 AB:0 BC:1 CA:1 +Smoothing: 5 +Face 24: A:4 B:20 C:21 AB:1 BC:1 CA:0 +Smoothing: 6 +Face 25: A:4 B:21 C:5 AB:0 BC:1 CA:1 +Smoothing: 6 +Face 26: A:5 B:21 C:22 AB:1 BC:1 CA:0 +Smoothing: 7 +Face 27: A:5 B:22 C:6 AB:0 BC:1 CA:1 +Smoothing: 7 +Face 28: A:6 B:22 C:23 AB:1 BC:1 CA:0 +Smoothing: 8 +Face 29: A:6 B:23 C:7 AB:0 BC:1 CA:1 +Smoothing: 8 +Face 30: A:7 B:23 C:24 AB:1 BC:1 CA:0 +Smoothing: 9 +Face 31: A:7 B:24 C:8 AB:0 BC:1 CA:1 +Smoothing: 9 +Face 32: A:8 B:24 C:25 AB:1 BC:1 CA:0 +Smoothing: 10 +Face 33: A:8 B:25 C:9 AB:0 BC:1 CA:1 +Smoothing: 10 +Face 34: A:9 B:25 C:26 AB:1 BC:1 CA:0 +Smoothing: 11 +Face 35: A:9 B:26 C:10 AB:0 BC:1 CA:1 +Smoothing: 11 +Face 36: A:10 B:26 C:27 AB:1 BC:1 CA:0 +Smoothing: 12 +Face 37: A:10 B:27 C:11 AB:0 BC:1 CA:1 +Smoothing: 12 +Face 38: A:11 B:27 C:28 AB:1 BC:1 CA:0 +Smoothing: 13 +Face 39: A:11 B:28 C:12 AB:0 BC:1 CA:1 +Smoothing: 13 +Face 40: A:12 B:28 C:29 AB:1 BC:1 CA:0 +Smoothing: 14 + + Page 2 + + + +Face 41: A:12 B:29 C:13 AB:0 BC:1 CA:1 +Smoothing: 14 +Face 42: A:13 B:29 C:30 AB:1 BC:1 CA:0 +Smoothing: 15 +Face 43: A:13 B:30 C:14 AB:0 BC:1 CA:1 +Smoothing: 15 +Face 44: A:14 B:30 C:31 AB:1 BC:1 CA:0 +Smoothing: 16 +Face 45: A:14 B:31 C:15 AB:0 BC:1 CA:1 +Smoothing: 16 +Face 46: A:15 B:31 C:16 AB:1 BC:1 CA:0 +Smoothing: 17 +Face 47: A:15 B:16 C:0 AB:0 BC:1 CA:1 +Smoothing: 17 +Face 48: A:16 B:33 C:17 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 49: A:17 B:33 C:18 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 50: A:18 B:33 C:19 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 51: A:19 B:33 C:20 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 52: A:20 B:33 C:21 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 53: A:21 B:33 C:22 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 54: A:22 B:33 C:23 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 55: A:23 B:33 C:24 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 56: A:24 B:33 C:25 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 57: A:25 B:33 C:26 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 58: A:26 B:33 C:27 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 59: A:27 B:33 C:28 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 60: A:28 B:33 C:29 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 61: A:29 B:33 C:30 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 62: A:30 B:33 C:31 AB:0 BC:0 CA:1 +Smoothing: 18 +Face 63: A:31 B:33 C:16 AB:0 BC:0 CA:1 +Smoothing: 18 + + + + + + + + + + + + + + + + + Page 3 + + + diff --git a/progs/ggi/gears.c b/progs/ggi/gears.c new file mode 100644 index 0000000000..a6b5f7dda1 --- /dev/null +++ b/progs/ggi/gears.c @@ -0,0 +1,359 @@ +/* $Id: gears.c,v 1.1 1999/08/21 06:27:37 jtaylor Exp $ */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +/* + * $Log: gears.c,v $ + * Revision 1.1 1999/08/21 06:27:37 jtaylor + * *** empty log message *** + * + * Revision 1.5 1999/07/31 21:51:09 jtaylor + * *** empty log message *** + * + * 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 +#include +#include +#include + +#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(void) +{ + 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); +} + +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(); + + glutDisplayFunc(draw); + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutVisibilityFunc(visible); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/ggi/gears2.c b/progs/ggi/gears2.c new file mode 100644 index 0000000000..1d1e10db54 --- /dev/null +++ b/progs/ggi/gears2.c @@ -0,0 +1,359 @@ +/* gears.c */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + * modified by Uwe Maurer (uwe_maurer@t-online.de) + */ + +#include +#include +#include +#include +#include +#ifndef M_PI +# define M_PI 3.14159265 +#endif + + +ggi_visual_t vis; +char text[100]; + +/* + * 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 GGI"); + ggiPuts(vis,0,ggiGetInfo(vis)->mode->visible.y," Mesa -> GGI"); + + ggiPuts(vis,0,16,text); + ggiPuts(vis,0,ggiGetInfo(vis)->mode->visible.y+16,text); +#endif + + GGIMesaSwapBuffers(); + + count++; + if (count==limit) { + exit(1); + } +} + +static void idle( void ) +{ + angle += 2.0; + draw(); +} + +/* 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 ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + +} + + +static void init( void ) +{ + 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 ); + glIndexi(1); + 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 ); + glIndexi(2); + 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 ); + glIndexi(3); + gear( 1.3, 2.0, 0.5, 10, 0.7 ); + glEndList(); + + glEnable( GL_NORMALIZE ); +} + +static void usage(char *s) +{ + printf("%s visible_x visible_y virtual_x virtual_y bpp db_flag\n",s); + printf("example:\n"); + printf("%s 320 200 320 400 8 1\n",s); + exit(1); +} + +int main( int argc, char *argv[] ) +{ + GGIMesaContext ctx; + int vis_x,vis_y,vir_x,vir_y,bpp,db_flag,gt; + ggi_mode mode; + + limit=0; + + if (argc<7) usage(argv[0]); + + vis_x=atoi(argv[1]); + vis_y=atoi(argv[2]); + vir_x=atoi(argv[3]); + vir_y=atoi(argv[4]); + bpp=atoi(argv[5]); + db_flag=atoi(argv[6]); + + switch(bpp) + { + case 4: gt=GT_4BIT;break; + case 8: gt=GT_8BIT;break; + case 15:gt=GT_15BIT;break; + case 16:gt=GT_16BIT;break; + case 24:gt=GT_24BIT;break; + case 32:gt=GT_32BIT;break; + default: + printf("%i Bits per Pixel ???\n",bpp); + exit(1); + } + sprintf(text,"%sx%s %i colors, RGB mode, %s", + argv[1],argv[2],1<