1 /**************************************************************************
2 * GLmain.c -- top level sim routines
4 * Written by Curtis Olson for OpenGL, started May 1997.
7 * (Log is kept at end of this file)
8 **************************************************************************/
20 /* assumes -I/usr/include/mesa in compile command */
25 #include "../aircraft/aircraft.h"
26 #include "../scenery/scenery.h"
29 /* This is a record containing all the info for the aircraft currently
31 struct aircraft_params current_aircraft;
34 extern struct mesh *mesh_ptr;
36 /* Function prototypes */
38 static void draw_mesh();
42 static GLfloat win_ratio = 1.0;
44 /* pointer to terrain mesh structure */
47 /* init_view() -- Setup view parameters */
48 static void init_view() {
49 /* if the 4th field is 0.0, this specifies a direction ... */
50 static GLfloat pos[4] = {-3.0, 1.0, 3.0, 0.0 };
51 static GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0};
53 glLightfv( GL_LIGHT0, GL_POSITION, pos );
54 glEnable( GL_CULL_FACE );
55 glEnable( GL_LIGHTING );
56 glEnable( GL_LIGHT0 );
57 glEnable( GL_DEPTH_TEST );
60 glFogi (GL_FOG_MODE, GL_LINEAR);
61 /* glFogf (GL_FOG_START, 1.0); */
62 glFogf (GL_FOG_END, 1000.0);
63 glFogfv (GL_FOG_COLOR, fogColor);
64 glFogf (GL_FOG_DENSITY, 0.04);
65 glHint(GL_FOG_HINT, GL_FASTEST);
67 glClearColor(0.6, 0.6, 0.9, 1.0);
71 /* init_scene() -- build all objects */
72 static void init_scene() {
74 /* make terrain mesh */
77 /* If enabled, normal vectors specified with glNormal are scaled
78 to unit length after transformation. See glNormal. */
79 glEnable( GL_NORMALIZE );
83 /* create the terrain mesh */
87 mesh = mesh_to_ogl(mesh_ptr);
93 /* create the terrain mesh */
94 GLint make_mesh_old() {
96 static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 };
99 glNewList(mesh, GL_COMPILE);
100 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color );
101 glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */
104 glVertex3f(-10.0, -10.0, 0.0);
105 glVertex3f(0.0, -10.0, 0.0);
106 glVertex3f(0.0, 0.0, 1.0);
107 glVertex3f(-10.0, 0.0, 1.0);
111 glVertex3f(-10.0, 0.0, 1.0);
112 glVertex3f(0.0, 0.0, 1.0);
113 glVertex3f(0.0, 10.0, 0.0);
114 glVertex3f(-10.0, 10.0, 0.0);
118 glVertex3f(0.0, 0.0, 0.0);
119 glVertex3f(10.0, 0.0, 2.0);
120 glVertex3f(10.0, 10.0, 2.0);
121 glVertex3f(0.0, 10.0, 0.0);
125 glVertex3f(0.0, -10.0, -1.0);
126 glVertex3f(10.0, -10.0, 0.0);
127 glVertex3f(10.0, 0.0, -1.0);
128 glVertex3f(0.0, 0.0, 0.0);
137 /* update the view volume */
138 static void update_view() {
139 struct flight_params *f;
141 f = ¤t_aircraft.flight;
143 /* Tell GL we are about to modify the projection parameters */
144 glMatrixMode(GL_PROJECTION);
147 gluPerspective(45.0, 1.0/win_ratio, 1.0, 6000.0);
148 gluLookAt(f->pos_x, f->pos_y, f->pos_z,
149 f->pos_x + cos(f->Psi), f->pos_y + sin(f->Psi), f->pos_z,
155 static void draw_scene( void ) {
156 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
158 /* update view volume parameters */
161 /* Tell GL we are switching to model view parameters */
162 glMatrixMode(GL_MODELVIEW);
165 /* glTranslatef(0.0, 0.0, -5.0); */
169 /* draw terrain mesh */
182 /* draw the terrain mesh */
183 static void draw_mesh() {
188 /* What should we do when we have nothing else to do? How about get
189 * ready for the next move?*/
190 static void idle( void )
199 /* new window size or exposure */
200 static void reshape( int width, int height ) {
201 /* Do this so we can call reshape(0,0) ourselves without having to know
202 * what the values of width & height are. */
203 if ( (height > 0) && (width > 0) ) {
204 win_ratio = (GLfloat) height / (GLfloat) width;
207 /* Inform gl of our view window size */
208 glViewport(0, 0, (GLint)width, (GLint)height);
212 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
216 /**************************************************************************
218 **************************************************************************/
220 int main( int argc, char *argv[] ) {
221 /* parse the scenery file */
222 parse_scenery(argv[1]);
225 /* initialize GLUT */
226 glutInit(&argc, argv);
228 /* Define initial window size */
229 glutInitWindowSize(640, 400);
231 /* Define Display Parameters */
232 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
234 /* Initialize the main window */
235 glutCreateWindow("Terrain Demo");
237 /* Define initial window size */
238 tkInitPosition(0, 0, 640, 400);
240 /* Define Display Parameters */
241 tkInitDisplayMode( TK_RGB | TK_DEPTH | TK_DOUBLE | TK_DIRECT );
243 /* Initialize the main window */
244 if (tkInitWindow("Terrain Demo") == GL_FALSE) {
249 /* setup view parameters, only makes GL calls */
252 /* build all objects */
255 /* Set initial position and slew parameters */
256 /* slew_init(-398391.3, 120070.4, 244, 3.1415); */ /* GLOBE Airport */
257 slew_init(-398673.28,120625.64, 53, 4.38);
260 /* call reshape() on window resizes */
261 glutReshapeFunc( reshape );
263 /* call key() on keyboard event */
264 glutKeyboardFunc( GLUTkey );
265 glutSpecialFunc( GLUTkey );
267 /* call idle() whenever there is nothing else to do */
268 glutIdleFunc( idle );
271 glutDisplayFunc( draw_scene );
273 /* pass control off to the GLUT event handler */
276 /* call reshape() on expose events */
277 tkExposeFunc( reshape );
279 /* call reshape() on window resizes */
280 tkReshapeFunc( reshape );
282 /* call key() on keyboard event */
283 tkKeyDownFunc( GLTKkey );
285 /* call idle() whenever there is nothing else to do */
289 tkDisplayFunc( draw_scene );
291 /* pass control off to the tk event handler */
300 /* Revision 1.1 1997/05/21 15:57:51 curt
301 /* Renamed due to added GLUT support.
303 * Revision 1.3 1997/05/19 18:22:42 curt
304 * Parameter tweaking ... starting to stub in fog support.
306 * Revision 1.2 1997/05/17 00:17:34 curt
307 * Trying to stub in support for standard OpenGL.
309 * Revision 1.1 1997/05/16 16:05:52 curt