1 // renderer.cxx -- top level sim routines
3 // Written by Curtis Olson, started May 1997.
4 // This file contains parts of main.cxx prior to october 2004
6 // Copyright (C) 1997 - 2002 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <simgear/compiler.h>
36 #include <plib/netSocket.h>
38 #include <simgear/screen/extensions.hxx>
39 #include <simgear/scene/material/matlib.hxx>
40 #include <simgear/props/props.hxx>
41 #include <simgear/timing/sg_time.hxx>
42 #include <simgear/scene/model/animation.hxx>
43 #include <simgear/ephemeris/ephemeris.hxx>
44 #include <simgear/scene/model/placement.hxx>
45 #include <simgear/math/sg_random.h>
46 #include <simgear/scene/model/modellib.hxx>
47 #include <simgear/scene/model/model.hxx>
49 #ifdef FG_USE_CLOUDS_3D
50 # include <simgear/scene/sky/clouds3d/SkySceneLoader.hpp>
51 # include <simgear/scene/sky/clouds3d/SkyUtil.hpp>
54 #include <Scenery/tileentry.hxx>
55 #include <Time/light.hxx>
56 #include <Time/light.hxx>
57 #include <Aircraft/aircraft.hxx>
58 #include <Cockpit/panel.hxx>
59 #include <Cockpit/cockpit.hxx>
60 #include <Cockpit/radiostack.hxx>
61 #include <Cockpit/hud.hxx>
62 #include <Model/panelnode.hxx>
63 #include <Model/modelmgr.hxx>
64 #include <Model/acmodel.hxx>
65 #include <Scenery/scenery.hxx>
66 #include <Scenery/tilemgr.hxx>
67 #include <ATC/ATCdisplay.hxx>
68 #include <Replay/replay.hxx>
69 #include <GUI/new_gui.hxx>
72 #include "renderer.hxx"
76 float default_attenuation[3] = {1.0, 0.0, 0.0};
78 ssgSelector *lightpoints_brightness = new ssgSelector;
79 ssgTransform *lightpoints_transform = new ssgTransform;
80 FGTileEntry *dummy_tile;
83 // Clip plane settings...
84 float scene_nearplane = 0.5f;
85 float scene_farplane = 120000.0f;
87 glPointParameterfProc glPointParameterfPtr = 0;
88 glPointParameterfvProc glPointParameterfvPtr = 0;
89 bool glPointParameterIsSupported = false;
92 // fog constants. I'm a little nervous about putting actual code out
93 // here but it seems to work (?)
94 static const double m_log01 = -log( 0.01 );
95 static const double sqrt_m_log01 = sqrt( m_log01 );
96 static GLfloat fog_exp_density;
97 static GLfloat fog_exp2_density;
98 static GLfloat rwy_exp2_punch_through;
99 static GLfloat taxi_exp2_punch_through;
100 static GLfloat ground_exp2_punch_through;
105 #ifdef FG_USE_CLOUDS_3D
106 SkySceneLoader *sgClouds3d;
107 bool _bcloud_orig = true;
111 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
113 { 1.0f, 0.0f, 0.0f, 0.0f },
114 { 0.0f, 0.0f, -1.0f, 0.0f },
115 { 0.0f, 1.0f, 0.0f, 0.0f },
116 { 0.0f, 0.0f, 0.0f, 1.0f }
119 ssgSimpleState *cloud3d_imposter_state;
120 ssgSimpleState *default_state;
121 ssgSimpleState *hud_and_panel;
122 ssgSimpleState *menus;
126 FGRenderer::build_states( void ) {
127 default_state = new ssgSimpleState;
128 default_state->ref();
129 default_state->disable( GL_TEXTURE_2D );
130 default_state->enable( GL_CULL_FACE );
131 default_state->enable( GL_COLOR_MATERIAL );
132 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
133 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
134 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
135 default_state->disable( GL_BLEND );
136 default_state->disable( GL_ALPHA_TEST );
137 default_state->disable( GL_LIGHTING );
139 cloud3d_imposter_state = new ssgSimpleState;
140 cloud3d_imposter_state->ref();
141 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
142 cloud3d_imposter_state->enable( GL_CULL_FACE );
143 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
144 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
145 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
146 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
147 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
148 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
149 cloud3d_imposter_state->enable( GL_BLEND );
150 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
151 cloud3d_imposter_state->disable( GL_LIGHTING );
153 hud_and_panel = new ssgSimpleState;
154 hud_and_panel->ref();
155 hud_and_panel->disable( GL_CULL_FACE );
156 hud_and_panel->disable( GL_TEXTURE_2D );
157 hud_and_panel->disable( GL_LIGHTING );
158 hud_and_panel->enable( GL_BLEND );
160 menus = new ssgSimpleState;
162 menus->disable( GL_CULL_FACE );
163 menus->disable( GL_TEXTURE_2D );
164 menus->enable( GL_BLEND );
168 // Initialize various GL/view parameters
170 FGRenderer::init( void ) {
172 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
174 // Go full screen if requested ...
175 if ( fgGetBool("/sim/startup/fullscreen") ) {
179 // If enabled, normal vectors specified with glNormal are scaled
180 // to unit length after transformation. Enabling this has
181 // performance implications. See the docs for glNormal.
182 // glEnable( GL_NORMALIZE );
184 glEnable( GL_LIGHTING );
185 glEnable( GL_LIGHT0 );
186 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
189 sgSetVec3( sunpos, l->sun_vec()[0], l->sun_vec()[1], l->sun_vec()[2] );
190 ssgGetLight( 0 ) -> setPosition( sunpos );
192 glFogi (GL_FOG_MODE, GL_EXP2);
193 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
194 (!fgGetBool("/sim/rendering/shading"))) {
195 // if fastest fog requested, or if flat shading force fastest
196 glHint ( GL_FOG_HINT, GL_FASTEST );
197 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
198 glHint ( GL_FOG_HINT, GL_NICEST );
200 if ( fgGetBool("/sim/rendering/wireframe") ) {
202 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
205 // This is the default anyways, but it can't hurt
206 glFrontFace ( GL_CCW );
209 // glEnable(GL_POINT_SMOOTH);
210 // glEnable(GL_LINE_SMOOTH);
211 // glEnable(GL_POLYGON_SMOOTH);
215 // Update all Visuals (redraws anything graphics related)
217 FGRenderer::update( bool refresh_camera_settings ) {
218 bool scenery_loaded = fgGetBool("sim/sceneryloaded") || fgGetBool("sim/sceneryloaded-override");
219 bool draw_otw = fgGetBool("/sim/rendering/draw-otw");
220 bool skyblend = fgGetBool("/sim/rendering/skyblend");
221 bool enhanced_lighting = fgGetBool("/sim/rendering/enhanced-lighting");
222 bool distance_attenuation = fgGetBool("/sim/rendering/distance-attenuation");
223 #ifdef FG_ENABLE_MULTIPASS_CLOUDS
224 bool multi_pass_clouds = fgGetBool("/sim/rendering/multi-pass-clouds") &&
225 !SGCloudLayer::enable_bump_mapping; // ugly artefact now
227 bool multi_pass_clouds = false;
229 bool draw_clouds = fgGetBool("/environment/clouds/status");
231 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
232 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
234 // static const SGPropertyNode *longitude
235 // = fgGetNode("/position/longitude-deg");
236 // static const SGPropertyNode *latitude
237 // = fgGetNode("/position/latitude-deg");
238 // static const SGPropertyNode *altitude
239 // = fgGetNode("/position/altitude-ft");
240 static const SGPropertyNode *groundlevel_nearplane
241 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
243 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
244 static double last_visibility = -9999;
247 double actual_visibility;
248 if (fgGetBool("/environment/clouds/status")) {
249 actual_visibility = thesky->get_visibility();
251 actual_visibility = fgGetDouble("/environment/visibility-m");
254 if ( actual_visibility != last_visibility ) {
255 last_visibility = actual_visibility;
257 fog_exp_density = m_log01 / actual_visibility;
258 fog_exp2_density = sqrt_m_log01 / actual_visibility;
259 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
260 if ( actual_visibility < 8000 ) {
261 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
262 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
264 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
265 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
270 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
271 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
272 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
273 // GLfloat mat_shininess[] = { 10.0 };
274 GLbitfield clear_mask;
276 if ( idle_state != 1000 || !scenery_loaded ) {
277 // still initializing, draw the splash screen
278 if ( fgGetBool("/sim/startup/splash-screen") ) {
279 fgSplashUpdate(0.0, 1.0);
281 // Keep resetting sim time while the sim is initializing
282 globals->set_sim_time_sec( 0.0 );
283 SGAnimation::set_sim_time_sec( 0.0 );
285 // idle_state is now 1000 meaning we've finished all our
286 // initializations and are running the main loop, so this will
287 // now work without seg faulting the system.
289 FGViewer *current__view = globals->get_current_view();
291 // calculate our current position in cartesian space
292 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
294 if ( refresh_camera_settings ) {
296 resize( fgGetInt("/sim/startup/xsize"),
297 fgGetInt("/sim/startup/ysize") );
299 // Tell GL we are switching to model view parameters
300 glMatrixMode(GL_MODELVIEW);
302 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
305 if ( fgGetBool("/sim/rendering/clouds3d") ) {
306 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
307 cloud3d_imposter_state->force();
309 glColor4f( 1.0, 1.0, 1.0, 1.0 );
310 glEnable(GL_DEPTH_TEST);
312 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
314 #ifdef FG_USE_CLOUDS_3D
315 if ( _bcloud_orig ) {
316 Point3D c = globals->get_scenery()->get_center();
317 sgClouds3d->Set_Cloud_Orig( &c );
318 _bcloud_orig = false;
320 sgClouds3d->Update( current__view->get_absolute_view_pos() );
322 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
323 glDisable(GL_DEPTH_TEST);
326 clear_mask = GL_DEPTH_BUFFER_BIT;
327 if ( fgGetBool("/sim/rendering/wireframe") ) {
328 clear_mask |= GL_COLOR_BUFFER_BIT;
332 if ( fgGetBool("/sim/rendering/textures") ) {
333 // glClearColor(black[0], black[1], black[2], black[3]);
334 glClearColor(l->adj_fog_color()[0], l->adj_fog_color()[1],
335 l->adj_fog_color()[2], l->adj_fog_color()[3]);
336 clear_mask |= GL_COLOR_BUFFER_BIT;
339 glClearColor(l->sky_color()[0], l->sky_color()[1],
340 l->sky_color()[2], l->sky_color()[3]);
341 clear_mask |= GL_COLOR_BUFFER_BIT;
343 if ( multi_pass_clouds && draw_clouds ) {
345 clear_mask |= GL_STENCIL_BUFFER_BIT;
347 glClear( clear_mask );
349 // set the opengl state to known default values
350 default_state->force();
352 // update fog params if visibility has changed
353 double visibility_meters = fgGetDouble("/environment/visibility-m");
354 thesky->set_visibility(visibility_meters);
356 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
357 ( global_multi_loop * fgGetInt("/sim/speed-up") )
358 / (double)fgGetInt("/sim/model-hz") );
360 // Set correct opengl fog density
361 glFogf (GL_FOG_DENSITY, fog_exp2_density);
363 // update the sky dome
366 SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
367 << l->sky_color()[0] << " "
368 << l->sky_color()[1] << " "
369 << l->sky_color()[2] << " "
370 << l->sky_color()[3] );
371 SG_LOG( SG_GENERAL, SG_BULK, " fog = "
372 << l->fog_color()[0] << " "
373 << l->fog_color()[1] << " "
374 << l->fog_color()[2] << " "
375 << l->fog_color()[3] );
376 SG_LOG( SG_GENERAL, SG_BULK,
377 " sun_angle = " << l->sun_angle
378 << " moon_angle = " << l->moon_angle );
381 static SGSkyColor scolor;
382 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
384 scolor.sky_color = l->sky_color();
385 scolor.fog_color = l->adj_fog_color();
386 scolor.cloud_color = l->cloud_color();
387 scolor.sun_angle = l->get_sun_angle();
388 scolor.moon_angle = l->get_moon_angle();
389 scolor.nplanets = globals->get_ephem()->getNumPlanets();
390 scolor.nstars = globals->get_ephem()->getNumStars();
391 scolor.planet_data = globals->get_ephem()->getPlanets();
392 scolor.star_data = globals->get_ephem()->getStars();
394 thesky->repaint( scolor );
397 SG_LOG( SG_GENERAL, SG_BULK,
398 "thesky->reposition( view_pos = " << view_pos[0] << " "
399 << view_pos[1] << " " << view_pos[2] );
400 SG_LOG( SG_GENERAL, SG_BULK,
401 " zero_elev = " << zero_elev[0] << " "
402 << zero_elev[1] << " " << zero_elev[2]
403 << " lon = " << cur_fdm_state->get_Longitude()
404 << " lat = " << cur_fdm_state->get_Latitude() );
405 SG_LOG( SG_GENERAL, SG_BULK,
406 " sun_rot = " << l->get_sun_rotation
407 << " gst = " << SGTime::cur_time_params->getGst() );
408 SG_LOG( SG_GENERAL, SG_BULK,
409 " sun ra = " << globals->get_ephem()->getSunRightAscension()
410 << " sun dec = " << globals->get_ephem()->getSunDeclination()
411 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
412 << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
415 // The sun and moon distances are scaled down versions
416 // of the actual distance to get both the moon and the sun
417 // within the range of the far clip plane.
418 // Moon distance: 384,467 kilometers
419 // Sun distance: 150,000,000 kilometers
420 double sun_horiz_eff, moon_horiz_eff;
421 if (fgGetBool("/sim/rendering/horizon-effect")) {
422 sun_horiz_eff = 0.67+pow(0.5+cos(l->get_sun_angle())*2/2, 0.33)/3;
423 moon_horiz_eff = 0.67+pow(0.5+cos(l->get_moon_angle())*2/2, 0.33)/3;
425 sun_horiz_eff = moon_horiz_eff = 1.0;
428 static SGSkyState sstate;
430 sstate.view_pos = current__view->get_view_pos();
431 sstate.zero_elev = current__view->get_zero_elev();
432 sstate.view_up = current__view->get_world_up();
433 sstate.lon = current__view->getLongitude_deg()
434 * SGD_DEGREES_TO_RADIANS;
435 sstate.lat = current__view->getLatitude_deg()
436 * SGD_DEGREES_TO_RADIANS;
437 sstate.alt = current__view->getAltitudeASL_ft()
439 sstate.spin = l->get_sun_rotation();
440 sstate.gst = globals->get_time_params()->getGst();
441 sstate.sun_ra = globals->get_ephem()->getSunRightAscension();
442 sstate.sun_dec = globals->get_ephem()->getSunDeclination();
443 sstate.sun_dist = 50000.0 * sun_horiz_eff;
444 sstate.moon_ra = globals->get_ephem()->getMoonRightAscension();
445 sstate.moon_dec = globals->get_ephem()->getMoonDeclination();
446 sstate.moon_dist = 40000.0 * moon_horiz_eff;
448 thesky->reposition( sstate, delta_time_sec );
451 glEnable( GL_DEPTH_TEST );
452 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
454 glFogi( GL_FOG_MODE, GL_EXP2 );
455 glFogfv( GL_FOG_COLOR, l->adj_fog_color() );
458 // set sun/lighting parameters
459 ssgGetLight( 0 ) -> setPosition( l->sun_vec() );
461 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
462 // we only update GL_AMBIENT for our lights we will never get
463 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
464 // explicitely to black.
465 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
467 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient() );
468 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
469 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular() );
471 // texture parameters
472 // glEnable( GL_TEXTURE_2D );
473 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
474 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
477 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
478 - globals->get_scenery()->get_cur_elev();
481 scene_nearplane = 10.0f;
482 scene_farplane = 120000.0f;
484 scene_nearplane = groundlevel_nearplane->getDoubleValue();
485 scene_farplane = 120000.0f;
488 ssgSetNearFar( scene_nearplane, scene_farplane );
490 if ( draw_otw && skyblend ) {
491 // draw the sky backdrop
493 // we need a white diffuse light for the phase of the moon
494 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
495 thesky->preDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
497 // return to the desired diffuse color
498 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
501 // draw the ssg scene
502 glEnable( GL_DEPTH_TEST );
504 ssgSetNearFar( scene_nearplane, scene_farplane );
506 if ( fgGetBool("/sim/rendering/wireframe") ) {
508 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
514 FGTileMgr::set_tile_filter( true );
515 sgSetModelFilter( false );
516 globals->get_aircraft_model()->select( false );
517 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
519 // Disable depth buffer update, draw the clouds
520 glDepthMask( GL_FALSE );
521 thesky->drawUpperClouds();
522 if ( multi_pass_clouds ) {
523 thesky->drawLowerClouds();
525 glDepthMask( GL_TRUE );
527 if ( multi_pass_clouds ) {
528 // Draw the objects except the aircraft
529 // and update the stencil buffer with 1
530 glEnable( GL_STENCIL_TEST );
531 glStencilFunc( GL_ALWAYS, 1, 1 );
532 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
534 FGTileMgr::set_tile_filter( false );
535 sgSetModelFilter( true );
536 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
538 FGTileMgr::set_tile_filter( true );
539 sgSetModelFilter( true );
540 globals->get_aircraft_model()->select( false );
541 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
545 // This is a bit kludgy. Every 200 frames, do an extra
546 // traversal of the scene graph without drawing anything, but
547 // with the field-of-view set to 360x360 degrees. This
548 // ensures that out-of-range random objects that are not in
549 // the current view frustum will still be freed properly.
550 static int counter = 0;
552 if (counter == 200) {
555 // No need to put the near plane too close;
556 // this way, at least the aircraft can be
558 f.setNearFar(1000, 1000000);
560 ssgGetModelviewMatrix(m);
561 FGTileMgr::set_tile_filter( true );
562 sgSetModelFilter( true );
563 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
567 // change state for lighting here
569 // draw runway lighting
570 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
571 ssgSetNearFar( scene_nearplane, scene_farplane );
573 if ( enhanced_lighting ) {
575 // Enable states for drawing points with GL_extension
576 glEnable(GL_POINT_SMOOTH);
578 if ( distance_attenuation && glPointParameterIsSupported )
580 // Enable states for drawing points with GL_extension
581 glEnable(GL_POINT_SMOOTH);
583 float quadratic[3] = {1.0, 0.001, 0.0000001};
584 // makes the points fade as they move away
585 glPointParameterfvPtr(GL_DISTANCE_ATTENUATION_EXT, quadratic);
586 glPointParameterfPtr(GL_POINT_SIZE_MIN_EXT, 1.0);
591 // blending function for runway lights
592 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
595 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
596 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
597 glEnable(GL_TEXTURE_GEN_S);
598 glEnable(GL_TEXTURE_GEN_T);
599 glPolygonMode(GL_FRONT, GL_POINT);
601 // draw runway lighting
603 ssgCullAndDraw( globals->get_scenery()->get_vasi_lights_root() );
604 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
607 // change punch through and then draw taxi lighting
608 glFogf ( GL_FOG_DENSITY, fog_exp2_density );
610 // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
611 // glFogfv ( GL_FOG_COLOR, taxi_fog );
613 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
617 glPolygonMode(GL_FRONT, GL_FILL);
618 glDisable(GL_TEXTURE_GEN_S);
619 glDisable(GL_TEXTURE_GEN_T);
621 //static int _frame_count = 0;
622 //if (_frame_count % 30 == 0) {
623 // printf("SSG: %s\n", ssgShowStats());
631 if ( enhanced_lighting ) {
632 if ( distance_attenuation && glPointParameterIsSupported ) {
633 glPointParameterfvPtr(GL_DISTANCE_ATTENUATION_EXT,
634 default_attenuation);
638 glDisable(GL_POINT_SMOOTH);
641 // draw ground lighting
642 glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
644 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
647 if ( draw_otw && fgGetBool("/sim/rendering/clouds3d") ) {
649 glDisable( GL_LIGHTING );
650 // cout << "drawing new clouds" << endl;
652 glEnable(GL_DEPTH_TEST);
654 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
657 glEnable( GL_TEXTURE_2D );
658 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
659 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
660 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
661 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
664 #ifdef FG_USE_CLOUDS_3D
665 sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
668 glEnable( GL_LIGHTING );
669 glEnable( GL_DEPTH_TEST );
670 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
673 if ( draw_otw && draw_clouds ) {
674 if ( multi_pass_clouds ) {
675 // Disable depth buffer update, draw the clouds where the
676 // objects overwrite the already drawn clouds, by testing
677 // the stencil buffer against 1
678 glDepthMask( GL_FALSE );
679 glStencilFunc( GL_EQUAL, 1, 1 );
680 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
681 thesky->drawUpperClouds();
682 thesky->drawLowerClouds();
683 glDepthMask( GL_TRUE );
684 glDisable( GL_STENCIL_TEST );
686 glDepthMask( GL_FALSE );
687 thesky->drawLowerClouds();
688 glDepthMask( GL_TRUE );
693 FGTileMgr::set_tile_filter( false );
694 sgSetModelFilter( false );
695 globals->get_aircraft_model()->select( true );
696 globals->get_model_mgr()->draw();
697 globals->get_aircraft_model()->draw();
698 // If the view is internal, the previous line draw the
699 // cockpit with modified near/far clip planes and deselect
700 // the aircraft in the global scenegraph
701 // Otherwise, it just enables the aircraft: The scenegraph
702 // must be drawn again to see the plane.
703 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
704 FGTileMgr::set_tile_filter( true );
705 sgSetModelFilter( true );
706 globals->get_aircraft_model()->select( true );
709 // display HUD && Panel
711 glDisable( GL_DEPTH_TEST );
712 // glDisable( GL_CULL_FACE );
713 // glDisable( GL_TEXTURE_2D );
715 // update the controls subsystem
716 globals->get_controls()->update(delta_time_sec);
718 hud_and_panel->apply();
721 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
722 // This only works properly if called before the panel call
723 if((fgGetBool("/sim/ATC/enabled")) || (fgGetBool("/sim/ai-traffic/enabled")))
724 globals->get_ATC_display()->update(delta_time_sec);
726 // update the panel subsystem
727 if ( globals->get_current_panel() != NULL ) {
728 globals->get_current_panel()->update(delta_time_sec);
732 // We can do translucent menus, so why not. :-)
734 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
736 // glDisable ( GL_BLEND ) ;
738 glEnable( GL_DEPTH_TEST );
741 // Fade out the splash screen over the first three seconds.
742 double t = globals->get_sim_time_sec();
744 fgSplashUpdate(0.0, 1.0);
745 } else if ( t <= 3.0) {
746 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
753 // options.cxx needs to see this for toggle_panel()
754 // Handle new window size or exposure
756 FGRenderer::resize( int width, int height ) {
759 if ( (!fgGetBool("/sim/virtual-cockpit"))
760 && fgPanelVisible() && idle_state == 1000 ) {
761 view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
762 globals->get_current_panel()->getYOffset()) / 768.0);
767 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
769 fgSetInt("/sim/startup/xsize", width);
770 fgSetInt("/sim/startup/ysize", height);
771 guiInitMouse(width, height);
774 FGViewMgr *viewmgr = globals->get_viewmgr();
776 for ( int i = 0; i < viewmgr->size(); ++i ) {
777 viewmgr->get_view(i)->
778 set_aspect_ratio((float)view_h / (float)width);
781 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
782 viewmgr->get_current_view()->get_v_fov() );
784 #ifdef FG_USE_CLOUDS_3D
785 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
786 viewmgr->get_current_view()->get_v_fov() );
795 // For HiRes screen Dumps using Brian Pauls TR Library
797 // Curt writes: Unfortunately, if the jpeg image server code is
798 // compiled into simgear and flightgear, this function get's called
799 // from simgear which is not the direction we want our dependencies to
800 // go, but it's the way things are right now.
802 // If I had to guess, I would speculate that this code probably
803 // doesn't work, at least not 100% correctly, but I don't have time
804 // right now to sort this one out. Also the jpeg server was very
805 // experimental and was extremely limited in the resolution images it
806 // could serve out for some never debugged reason. It's a novel
807 // feature, but I wouldn't be entirely opposed to seeing it go away
808 // unless someone wants to fix it so it works right and robustly and
809 // can serve full resolution images without crashing ourselves.
811 void trRenderFrame( void ) {
812 #ifdef FG_ENABLE_MULTIPASS_CLOUDS
813 bool multi_pass_clouds = fgGetBool("/sim/rendering/multi-pass-clouds") &&
814 !SGCloudLayer::enable_bump_mapping; // ugly artefact now
816 bool multi_pass_clouds = false;
818 bool draw_clouds = fgGetBool("/environment/clouds/status");
820 if ( fgPanelVisible() ) {
821 GLfloat height = fgGetInt("/sim/startup/ysize");
823 (globals->get_current_panel()->getViewHeight() - globals->get_current_panel()->getYOffset())
824 * (height / 768.0) + 1;
825 glTranslatef( 0.0, view_h, 0.0 );
828 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
829 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
831 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
833 glClearColor(l->adj_fog_color()[0], l->adj_fog_color()[1],
834 l->adj_fog_color()[2], l->adj_fog_color()[3]);
836 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
838 // set the opengl state to known default values
839 default_state->force();
842 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
843 glFogi ( GL_FOG_MODE, GL_EXP2 );
844 glFogfv ( GL_FOG_COLOR, l->adj_fog_color() );
846 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
847 // we only update GL_AMBIENT for our lights we will never get
848 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
849 // explicitely to black.
850 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
851 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
853 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient() );
855 // texture parameters
856 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
857 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
859 // we need a white diffuse light for the phase of the moon
860 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
861 thesky->preDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
864 // draw the ssg scene
865 // return to the desired diffuse color
866 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
867 glEnable( GL_DEPTH_TEST );
868 ssgSetNearFar( scene_nearplane, scene_farplane );
871 FGTileMgr::set_tile_filter( true );
872 sgSetModelFilter( false );
873 globals->get_aircraft_model()->select( false );
874 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
875 // Disable depth buffer update, draw the clouds
876 glDepthMask( GL_FALSE );
877 thesky->drawUpperClouds();
878 if ( multi_pass_clouds ) {
879 thesky->drawLowerClouds();
881 glDepthMask( GL_TRUE );
882 if ( multi_pass_clouds ) {
883 // Draw the objects except the aircraft
884 // and update the stencil buffer with 1
885 glEnable( GL_STENCIL_TEST );
886 glStencilFunc( GL_ALWAYS, 1, 1 );
887 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
889 FGTileMgr::set_tile_filter( false );
890 sgSetModelFilter( true );
891 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
893 FGTileMgr::set_tile_filter( true );
894 sgSetModelFilter( true );
895 globals->get_aircraft_model()->select( false );
896 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
900 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
901 ssgSetNearFar( scene_nearplane, scene_farplane );
902 ssgCullAndDraw( globals->get_scenery()->get_vasi_lights_root() );
903 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
905 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
908 if ( multi_pass_clouds ) {
909 // Disable depth buffer update, draw the clouds where the
910 // objects overwrite the already drawn clouds, by testing
911 // the stencil buffer against 1
912 glDepthMask( GL_FALSE );
913 glStencilFunc( GL_EQUAL, 1, 1 );
914 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
915 thesky->drawUpperClouds();
916 thesky->drawLowerClouds();
917 glDepthMask( GL_TRUE );
918 glDisable( GL_STENCIL_TEST );
920 glDepthMask( GL_FALSE );
921 thesky->drawLowerClouds();
922 glDepthMask( GL_TRUE );
926 globals->get_aircraft_model()->select( true );
927 globals->get_model_mgr()->draw();
928 globals->get_aircraft_model()->draw();
932 // end of renderer.cxx