diff --git a/Main/GLUTkey.c b/Main/GLUTkey.c index b02fe88d0..1118c9a90 100644 --- a/Main/GLUTkey.c +++ b/Main/GLUTkey.c @@ -15,6 +15,7 @@ #include "GLUTkey.h" #include "../aircraft/aircraft.h" +extern double fogDensity; /* Handle keyboard events */ void GLUTkey(unsigned char k, int x, int y) { @@ -48,6 +49,17 @@ void GLUTkey(unsigned char k, int x, int y) { return; case 4: c->throttle[0] += 0.05; + return; + case 122: + fogDensity *= 1.10; + glFogf(GL_FOG_DENSITY, fogDensity); + printf("Fog density = %.4f\n", fogDensity); + return; + case 90: + fogDensity /= 1.10; + glFogf(GL_FOG_DENSITY, fogDensity); + printf("Fog density = %.4f\n", fogDensity); + return; case 27: /* ESC */ exit(0); } @@ -56,9 +68,12 @@ void GLUTkey(unsigned char k, int x, int y) { /* $Log$ -/* Revision 1.1 1997/05/21 15:57:50 curt -/* Renamed due to added GLUT support. +/* Revision 1.2 1997/05/23 00:35:12 curt +/* Trying to get fog to work ... /* + * Revision 1.1 1997/05/21 15:57:50 curt + * Renamed due to added GLUT support. + * * Revision 1.2 1997/05/19 18:22:41 curt * Parameter tweaking ... starting to stub in fog support. * diff --git a/Main/GLmain.c b/Main/GLmain.c index 48c085c77..e57110095 100644 --- a/Main/GLmain.c +++ b/Main/GLmain.c @@ -44,26 +44,37 @@ static GLfloat win_ratio = 1.0; /* pointer to terrain mesh structure */ static GLint mesh; +double fogDensity = 0.04; + /* init_view() -- Setup view parameters */ static void init_view() { /* if the 4th field is 0.0, this specifies a direction ... */ static GLfloat pos[4] = {-3.0, 1.0, 3.0, 0.0 }; + static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 }; static GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0}; - glLightfv( GL_LIGHT0, GL_POSITION, pos ); + glEnable( GL_DEPTH_TEST ); glEnable( GL_CULL_FACE ); + + /* If enabled, normal vectors specified with glNormal are scaled + to unit length after transformation. See glNormal. */ + glEnable( GL_NORMALIZE ); + + glLightfv( GL_LIGHT0, GL_POSITION, pos ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); - glEnable( GL_DEPTH_TEST ); + + glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); + glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */ glEnable( GL_FOG ); - glFogi (GL_FOG_MODE, GL_LINEAR); + glFogi (GL_FOG_MODE, GL_EXP); /* glFogf (GL_FOG_START, 1.0); */ - glFogf (GL_FOG_END, 1000.0); + /* glFogf (GL_FOG_END, 1000.0); */ glFogfv (GL_FOG_COLOR, fogColor); - glFogf (GL_FOG_DENSITY, 0.04); - glHint(GL_FOG_HINT, GL_FASTEST); - + glFogf (GL_FOG_DENSITY, fogDensity); + /* glHint (GL_FOG_HINT, GL_FASTEST); */ + glClearColor(0.6, 0.6, 0.9, 1.0); } @@ -73,10 +84,6 @@ static void init_scene() { /* make terrain mesh */ mesh = make_mesh(); - - /* If enabled, normal vectors specified with glNormal are scaled - to unit length after transformation. See glNormal. */ - glEnable( GL_NORMALIZE ); } @@ -90,50 +97,6 @@ GLint make_mesh() { } -/* create the terrain mesh */ -GLint make_mesh_old() { - GLint mesh; - static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 }; - - mesh = glGenLists(1); - glNewList(mesh, GL_COMPILE); - glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); - glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */ - - glBegin(GL_POLYGON); - glVertex3f(-10.0, -10.0, 0.0); - glVertex3f(0.0, -10.0, 0.0); - glVertex3f(0.0, 0.0, 1.0); - glVertex3f(-10.0, 0.0, 1.0); - glEnd(); - - glBegin(GL_POLYGON); - glVertex3f(-10.0, 0.0, 1.0); - glVertex3f(0.0, 0.0, 1.0); - glVertex3f(0.0, 10.0, 0.0); - glVertex3f(-10.0, 10.0, 0.0); - glEnd(); - - glBegin(GL_POLYGON); - glVertex3f(0.0, 0.0, 0.0); - glVertex3f(10.0, 0.0, 2.0); - glVertex3f(10.0, 10.0, 2.0); - glVertex3f(0.0, 10.0, 0.0); - glEnd(); - - glBegin(GL_POLYGON); - glVertex3f(0.0, -10.0, -1.0); - glVertex3f(10.0, -10.0, 0.0); - glVertex3f(10.0, 0.0, -1.0); - glVertex3f(0.0, 0.0, 0.0); - glEnd(); - - glEndList(); - - return(mesh); -} - - /* update the view volume */ static void update_view() { struct flight_params *f; @@ -153,24 +116,18 @@ static void update_view() { /* draw the scene */ static void draw_scene( void ) { - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - /* update view volume parameters */ update_view(); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + /* Tell GL we are switching to model view parameters */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - /* glTranslatef(0.0, 0.0, -5.0); */ - - glPushMatrix(); - /* draw terrain mesh */ draw_mesh(); - glPopMatrix(); - #ifdef GLUT glutSwapBuffers(); #elif MESA_TK @@ -225,12 +182,12 @@ int main( int argc, char *argv[] ) { /* initialize GLUT */ glutInit(&argc, argv); - /* Define initial window size */ - glutInitWindowSize(640, 400); - /* Define Display Parameters */ glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); + /* Define initial window size */ + glutInitWindowSize(640, 400); + /* Initialize the main window */ glutCreateWindow("Terrain Demo"); #elif MESA_TK @@ -254,7 +211,8 @@ int main( int argc, char *argv[] ) { /* Set initial position and slew parameters */ /* slew_init(-398391.3, 120070.4, 244, 3.1415); */ /* GLOBE Airport */ - slew_init(-398673.28,120625.64, 53, 4.38); + /* slew_init(-398673.28,120625.64, 53, 4.38); */ + slew_init(0.0, 0.0, 53, 0.77); #ifdef GLUT /* call reshape() on window resizes */ @@ -297,9 +255,12 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.1 1997/05/21 15:57:51 curt -/* Renamed due to added GLUT support. +/* Revision 1.2 1997/05/23 00:35:12 curt +/* Trying to get fog to work ... /* + * Revision 1.1 1997/05/21 15:57:51 curt + * Renamed due to added GLUT support. + * * Revision 1.3 1997/05/19 18:22:42 curt * Parameter tweaking ... starting to stub in fog support. * diff --git a/Main/Makefile b/Main/Makefile index fccfe3c6b..1875f429e 100644 --- a/Main/Makefile +++ b/Main/Makefile @@ -37,12 +37,12 @@ INTERFACE_FILES = GLUTkey.c #--------------------------------------------------------------------------- # For OpenGL -GRAPHICS_LIBS = -lGLU -lGL -lXmu -lX11 +# GRAPHICS_LIBS = -lGLU -lGL -lXmu -lX11 # For Mesa -# MESA_LIBS = -L/usr/lib/mesa -lMesaaux -lMesatk -lMesaGLU -lMesaGL -# X11_LIBS = -L/usr/X11R6/lib -lXext -lXmu -lXi -lX11 -# GRAPHICS_LIBS = $(MESA_LIBS) $(X11_LIBS) +MESA_LIBS = -L/usr/lib/mesa -lMesaaux -lMesatk -lMesaGLU -lMesaGL +X11_LIBS = -L/usr/X11R6/lib -lXext -lXmu -lXi -lX11 +GRAPHICS_LIBS = $(MESA_LIBS) $(X11_LIBS) CFLAGS = $(STD_CFLAGS) $(INTERFACE_FLAGS) @@ -86,6 +86,9 @@ mesh2GL.o: mesh2GL.c ../scenery/mesh.h #--------------------------------------------------------------------------- # $Log$ +# Revision 1.3 1997/05/23 00:35:13 curt +# Trying to get fog to work ... +# # Revision 1.2 1997/05/21 15:57:52 curt # Renamed due to added GLUT support. # diff --git a/Main/mesh2GL.c b/Main/mesh2GL.c index 7ddf19a75..8a75cab12 100644 --- a/Main/mesh2GL.c +++ b/Main/mesh2GL.c @@ -1,5 +1,5 @@ /************************************************************************** - * mesh2ogl.c -- walk through a mesh data structure and make ogl calls + * mesh2GL.c -- walk through a mesh data structure and make GL calls * * Written by Curtis Olson, started May 1997. * @@ -37,28 +37,27 @@ static void mat3_cross_product(float result_vec[3], register float vec1[3], /* walk through mesh and make ogl calls */ GLint mesh_to_ogl(struct mesh *m) { GLint mesh; - static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 }; + /* static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 }; */ float x1, y1, x2, y2, z11, z12, z21, z22; float v1[3], v2[3], normal[3]; int i, j, istep, jstep, iend, jend; float temp; - istep = jstep = 10; /* Detail level 1 -- 1200 ... */ + istep = jstep = 25; /* Detail level 1 -- 1200 ... */ mesh = glGenLists(1); glNewList(mesh, GL_COMPILE); - glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); - glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */ + /* glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color ); */ iend = m->cols - 1; jend = m->rows - 1; - y1 = m->originy; + y1 = 0.0; /* y1 = m->originy; */ y2 = y1 + (m->col_step * istep); for ( i = 0; i < iend; i += istep ) { - x1 = m->originx; + x1 = 0.0; /* x1 = m->originx; */ x2 = x1 + (m->row_step * jstep); for ( j = 0; j < jend; j += jstep ) { z11 = 0.03 * m->mesh_data[j * m->rows + i ]; @@ -75,8 +74,8 @@ GLint mesh_to_ogl(struct mesh *m) { v2[0] = x2 - x1; v2[1] = y2 - y1; v2[2] = z22 - z11; mat3_cross_product(normal, v1, v2); MAT3_NORMALIZE_VEC(normal,temp); - glNormal3fv(normal); glBegin(GL_POLYGON); + glNormal3fv(normal); glVertex3f(x1, y1, z11); glVertex3f(x2, y1, z21); glVertex3f(x2, y2, z22); @@ -89,8 +88,8 @@ GLint mesh_to_ogl(struct mesh *m) { v2[0] = 0; v2[1] = y2 - y1; v2[2] = z12 - z11; mat3_cross_product(normal, v1, v2); MAT3_NORMALIZE_VEC(normal,temp); - glNormal3fv(normal); glBegin(GL_POLYGON); + glNormal3fv(normal); glVertex3f(x1, y1, z11); glVertex3f(x2, y2, z22); glVertex3f(x1, y2, z12); @@ -113,9 +112,12 @@ GLint mesh_to_ogl(struct mesh *m) { /* $Log$ -/* Revision 1.1 1997/05/21 15:57:52 curt -/* Renamed due to added GLUT support. +/* Revision 1.2 1997/05/23 00:35:13 curt +/* Trying to get fog to work ... /* + * Revision 1.1 1997/05/21 15:57:52 curt + * Renamed due to added GLUT support. + * * Revision 1.3 1997/05/19 18:22:42 curt * Parameter tweaking ... starting to stub in fog support. * diff --git a/Scenery/scanner.l b/Scenery/scanner.l index 64f00f235..48f56fa28 100644 --- a/Scenery/scanner.l +++ b/Scenery/scanner.l @@ -19,14 +19,6 @@ /* custom print routine */ static int scanner_debug = 0; - static int scanner_msg_len; - static char scanner_msg[1024]; - - static void scanner_print(char *s) { - if ( scanner_debug ) { - printf("%s", s); - } - } /* Routines to manage a stack of nested input buffers (for processing the #include directive */ @@ -100,87 +92,111 @@ other . /* Rules */ %% -include { scanner_print("return IncludeSym\n"); +include { if ( scanner_debug ) { + printf("return IncludeSym\n"); + } return IncludeSym; } -mesh { scanner_print("return MeshSym\n"); +mesh { if ( scanner_debug ) { + printf("return MeshSym\n"); + } return MeshSym; } -row { scanner_print("return RowSym\n"); +row { if ( scanner_debug ) { + printf("return RowSym\n"); + } return RowSym; } -chunk { scanner_print("return ChunkSym\n"); +chunk { if ( scanner_debug ) { + printf("return ChunkSym\n"); + } return ChunkSym; } -bounds { scanner_print("return BoundsSym\n"); +bounds { if ( scanner_debug ) { + printf("return BoundsSym\n"); + } return BoundsSym; } -place { scanner_print("return PlaceSym\n"); +place { if ( scanner_debug ) { + printf("return PlaceSym\n"); + } return PlaceSym; } -{ident} { scanner_msg_len = snprintf(scanner_msg, 1024, - "return Identifier = %s\n", yytext); - scanner_msg[scanner_msg_len] = '\0'; - scanner_print(scanner_msg); +{ident} { if ( scanner_debug ) { + printf("return Identifier = %s\n", yytext); + } return Identifier; } -{number} { scanner_print("return Number\n"); +{number} { if ( scanner_debug ) { + printf("return Number\n"); + } return Number; } -{string} { scanner_msg_len = snprintf(scanner_msg, 1024, - "return StringLiteral = %s\n", yytext); - scanner_msg[scanner_msg_len] = '\0'; - scanner_print(scanner_msg); +{string} { if ( scanner_debug ) { + printf("return StringLiteral = %s\n", yytext); + } return StringLiteral; } -{bad_string} { scanner_msg_len = snprintf(scanner_msg, 1024, - "return BadStringLiteral = %s\n", yytext); - scanner_msg[scanner_msg_len] = '\0'; - scanner_print(scanner_msg); +{bad_string} { if ( scanner_debug ) { + printf("return BadStringLiteral = %s\n", yytext); + } return BadStringLiteral; } "\n" { line_num++; - scanner_msg_len = snprintf(scanner_msg, 1024, - "Line number = %d\n", line_num); - scanner_msg[scanner_msg_len] = '\0'; - scanner_print(scanner_msg); - } + if ( scanner_debug ) { + printf("Line number = %d\n", line_num); + } + } -"#" { scanner_print("return HashSym\n"); +"#" { if ( scanner_debug ) { + printf("return HashSym\n"); + } return HashSym; } -"=" { scanner_print("return EqualSym\n"); +"=" { if ( scanner_debug ) { + printf("return EqualSym\n"); + } return EqualSym; } -"," { scanner_print("return CommaSym\n"); +"," { if ( scanner_debug ) { + printf("return CommaSym\n"); + } return CommaSym; } -"{" { scanner_print("return LBraceSym\n"); +"{" { if ( scanner_debug ) { + printf("return LBraceSym\n"); + } return LBraceSym; } -"}" { scanner_print("return RBraceSym\n"); +"}" { if ( scanner_debug ) { + printf("return RBraceSym\n"); + } return RBraceSym; } -"(" { scanner_print("return LParenSym\n"); +"(" { if ( scanner_debug ) { + printf("return LParenSym\n"); + } return LParenSym; } -")" { scanner_print("return RParenSym\n"); +")" { if ( scanner_debug ) { + printf("return RParenSym\n"); + } return RParenSym; } @@ -196,10 +212,9 @@ place { scanner_print("return PlaceSym\n"); {ws} { ; } -{other} { scanner_msg_len = snprintf(scanner_msg, 1024, - "Scanned some unexpected text = `%s'\n", yytext); - scanner_msg[scanner_msg_len] = '\0'; - scanner_print(scanner_msg); +{other} { if ( scanner_debug ) { + printf("Scanned some unexpected text = `%s'\n", yytext); + } return ErrorMisc; } diff --git a/Simulator/Makefile b/Simulator/Makefile index 54336e8d0..8eb3fb72c 100644 --- a/Simulator/Makefile +++ b/Simulator/Makefile @@ -12,18 +12,18 @@ CC = gcc SUBDIRS = aircraft controls flight scenery -MAIN = gltk +MAIN = OpenGL all: for dir in $(SUBDIRS) $(MAIN); do \ - ( cd $$dir; make CC=$(CC) CFLAGS=$(CFLAGS) ) ; \ + ( cd $$dir; make CC=$(CC) ) ; \ done install: for dir in $(SUBDIRS) $(MAIN); do \ - ( cd $$dir; make CC=$(CC) CFLAGS=$(CFLAGS) install) ; \ + ( cd $$dir; make CC=$(CC) install) ; \ done @@ -36,6 +36,9 @@ clean: #--------------------------------------------------------------------------- # $Log$ +# Revision 1.2 1997/05/23 00:35:09 curt +# Trying to get fog to work ... +# # Revision 1.1 1997/05/16 15:51:13 curt # Initial revision. #