From afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1c Mon Sep 17 00:00:00 2001 From: jtg Date: Thu, 19 Aug 1999 00:55:39 +0000 Subject: Initial revision --- progs/xdemos/vgears.c | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 progs/xdemos/vgears.c (limited to 'progs/xdemos/vgears.c') 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 +#include +#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;iheight) { + 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; +} -- cgit v1.2.3