1 /**************************************************************************
2 * gltkmain.c -- top level sim routines
4 * Written by Curtis Olson for Mesa (OpenGL), started May 1997.
7 * (Log is kept at end of this file)
8 **************************************************************************/
16 /* assumes -I/usr/include/mesa in compile command */
20 #include "../aircraft/aircraft.h"
21 #include "../scenery/scenery.h"
24 /* This a record containing all the info for the aircraft currently
26 struct aircraft_params current_aircraft;
29 extern struct mesh *mesh_ptr;
31 /* Function prototypes */
33 static void draw_mesh();
37 static GLfloat win_ratio = 1.0;
39 /* pointer to terrain mesh structure */
42 /* init_view() -- Setup view parameters */
43 static void init_view() {
44 /* if the 4th field is 0.0, this specifies a direction ... */
45 static GLfloat pos[4] = {2.0, 2.0, 3.0, 0.0 };
47 glLightfv( GL_LIGHT0, GL_POSITION, pos );
48 glEnable( GL_CULL_FACE );
49 glEnable( GL_LIGHTING );
50 glEnable( GL_LIGHT0 );
51 glEnable( GL_DEPTH_TEST );
52 /* glEnable( GL_FOG );
53 glFog( GL_FOG_MODE, GL_LINEAR );
54 glFogf( GL_FOG_END, 1000.0 ); */
55 glClearColor(0.6, 0.6, 0.9, 1.0);
59 /* init_scene() -- build all objects */
60 static void init_scene() {
62 /* make terrain mesh */
65 /* If enabled, normal vectors specified with glNormal are scaled
66 to unit length after transformation. See glNormal. */
67 glEnable( GL_NORMALIZE );
71 /* create the terrain mesh */
75 mesh = mesh_to_ogl(mesh_ptr);
81 /* create the terrain mesh */
82 GLint make_mesh_old() {
84 static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 };
87 glNewList(mesh, GL_COMPILE);
88 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color );
89 glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */
92 glVertex3f(-10.0, -10.0, 0.0);
93 glVertex3f(0.0, -10.0, 0.0);
94 glVertex3f(0.0, 0.0, 1.0);
95 glVertex3f(-10.0, 0.0, 1.0);
99 glVertex3f(-10.0, 0.0, 1.0);
100 glVertex3f(0.0, 0.0, 1.0);
101 glVertex3f(0.0, 10.0, 0.0);
102 glVertex3f(-10.0, 10.0, 0.0);
106 glVertex3f(0.0, 0.0, 0.0);
107 glVertex3f(10.0, 0.0, 2.0);
108 glVertex3f(10.0, 10.0, 2.0);
109 glVertex3f(0.0, 10.0, 0.0);
113 glVertex3f(0.0, -10.0, -1.0);
114 glVertex3f(10.0, -10.0, 0.0);
115 glVertex3f(10.0, 0.0, -1.0);
116 glVertex3f(0.0, 0.0, 0.0);
125 /* update the view volume */
126 static void update_view() {
127 struct flight_params *f;
129 f = ¤t_aircraft.flight;
131 /* Tell GL we are about to modify the projection parameters */
132 glMatrixMode(GL_PROJECTION);
135 gluPerspective(80.0, 1.0/win_ratio, 1.0, 6000.0);
136 gluLookAt(f->pos_x, f->pos_y, f->pos_z,
137 f->pos_x + cos(f->Psi), f->pos_y + sin(f->Psi), f->pos_z - 0.5,
143 static void draw_scene( void ) {
144 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
146 /* update view volume parameters */
149 /* Tell GL we are switching to model view parameters */
150 glMatrixMode(GL_MODELVIEW);
153 /* glTranslatef(0.0, 0.0, -5.0); */
157 /* draw terrain mesh */
166 /* draw the terrain mesh */
167 static void draw_mesh() {
172 /* What should we do when we have nothing else to do? How about get
173 * ready for the next move?*/
174 static void idle( void )
183 /* new window size or exposure */
184 static void reshape( int width, int height ) {
185 /* Do this so we can call reshape(0,0) ourselves without having to know
186 * what the values of width & height are. */
187 if ( (height > 0) && (width > 0) ) {
188 win_ratio = (GLfloat) height / (GLfloat) width;
191 /* Inform gl of our view window size */
192 glViewport(0, 0, (GLint)width, (GLint)height);
196 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
200 /**************************************************************************
202 **************************************************************************/
204 int main( int argc, char *argv[] ) {
206 /* parse the scenery file */
207 parse_scenery(argv[1]);
209 /* Define initial window size */
210 tkInitPosition(0, 0, 400, 400);
212 /* Define Display Parameters */
213 tkInitDisplayMode( TK_RGB | TK_DEPTH | TK_DOUBLE | TK_DIRECT );
215 /* Initialize the main window */
216 if (tkInitWindow("Terrain Demo") == GL_FALSE) {
220 /* setup view parameters */
223 /* build all objects */
226 /* Set initial position and slew parameters */
227 slew_init(-406658.0, 129731.0, 344, 0.79);
229 /* call reshape() on expose events */
230 tkExposeFunc( reshape );
232 /* call reshape() on window resizes */
233 tkReshapeFunc( reshape );
235 /* call key() on keyboard event */
236 tkKeyDownFunc( key );
238 /* call idle() whenever there is nothing else to do */
242 tkDisplayFunc( draw_scene );
244 /* pass control off to the tk event handler */
252 /* Revision 1.1 1997/05/16 16:05:52 curt