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 - http://www.flightgear.org/~curt
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 #include <simgear/screen/jpgfactory.hxx>
52 #include <simgear/environment/visual_enviro.hxx>
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/hud.hxx>
61 #include <Model/panelnode.hxx>
62 #include <Model/modelmgr.hxx>
63 #include <Model/acmodel.hxx>
64 #include <Scenery/scenery.hxx>
65 #include <Scenery/tilemgr.hxx>
66 #include <ATC/ATCdisplay.hxx>
67 #include <Replay/replay.hxx>
68 #include <GUI/new_gui.hxx>
71 #include "renderer.hxx"
75 float default_attenuation[3] = {1.0, 0.0, 0.0};
77 ssgSelector *lightpoints_brightness = new ssgSelector;
78 ssgTransform *lightpoints_transform = new ssgTransform;
79 FGTileEntry *dummy_tile;
82 // Clip plane settings...
83 float scene_nearplane = 0.5f;
84 float scene_farplane = 120000.0f;
86 glPointParameterfProc glPointParameterfPtr = 0;
87 glPointParameterfvProc glPointParameterfvPtr = 0;
88 bool glPointParameterIsSupported = false;
91 // fog constants. I'm a little nervous about putting actual code out
92 // here but it seems to work (?)
93 static const double m_log01 = -log( 0.01 );
94 static const double sqrt_m_log01 = sqrt( m_log01 );
95 static GLfloat fog_exp_density;
96 static GLfloat fog_exp2_density;
97 static GLfloat rwy_exp2_punch_through;
98 static GLfloat taxi_exp2_punch_through;
99 static GLfloat ground_exp2_punch_through;
105 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
107 { 1.0f, 0.0f, 0.0f, 0.0f },
108 { 0.0f, 0.0f, -1.0f, 0.0f },
109 { 0.0f, 1.0f, 0.0f, 0.0f },
110 { 0.0f, 0.0f, 0.0f, 1.0f }
113 ssgSimpleState *cloud3d_imposter_state;
114 ssgSimpleState *default_state;
115 ssgSimpleState *hud_and_panel;
116 ssgSimpleState *menus;
118 FGRenderer::FGRenderer()
120 #ifdef FG_JPEG_SERVER
121 jpgRenderFrame = FGRenderer::update;
125 FGRenderer::~FGRenderer()
127 #ifdef FG_JPEG_SERVER
128 jpgRenderFrame = NULL;
134 FGRenderer::build_states( void ) {
135 default_state = new ssgSimpleState;
136 default_state->ref();
137 default_state->disable( GL_TEXTURE_2D );
138 default_state->enable( GL_CULL_FACE );
139 default_state->enable( GL_COLOR_MATERIAL );
140 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
141 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
142 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
143 default_state->disable( GL_BLEND );
144 default_state->disable( GL_ALPHA_TEST );
145 default_state->disable( GL_LIGHTING );
147 cloud3d_imposter_state = new ssgSimpleState;
148 cloud3d_imposter_state->ref();
149 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
150 cloud3d_imposter_state->enable( GL_CULL_FACE );
151 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
152 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
153 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
154 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
155 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
156 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
157 cloud3d_imposter_state->enable( GL_BLEND );
158 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
159 cloud3d_imposter_state->disable( GL_LIGHTING );
161 hud_and_panel = new ssgSimpleState;
162 hud_and_panel->ref();
163 hud_and_panel->disable( GL_CULL_FACE );
164 hud_and_panel->disable( GL_TEXTURE_2D );
165 hud_and_panel->disable( GL_LIGHTING );
166 hud_and_panel->enable( GL_BLEND );
168 menus = new ssgSimpleState;
170 menus->disable( GL_CULL_FACE );
171 menus->disable( GL_TEXTURE_2D );
172 menus->enable( GL_BLEND );
176 // Initialize various GL/view parameters
178 FGRenderer::init( void ) {
180 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
182 // Go full screen if requested ...
183 if ( fgGetBool("/sim/startup/fullscreen") ) {
187 // If enabled, normal vectors specified with glNormal are scaled
188 // to unit length after transformation. Enabling this has
189 // performance implications. See the docs for glNormal.
190 // glEnable( GL_NORMALIZE );
192 glEnable( GL_LIGHTING );
193 glEnable( GL_LIGHT0 );
194 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
197 sgSetVec3( sunpos, l->sun_vec()[0], l->sun_vec()[1], l->sun_vec()[2] );
198 ssgGetLight( 0 ) -> setPosition( sunpos );
200 glFogi (GL_FOG_MODE, GL_EXP2);
201 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
202 (!fgGetBool("/sim/rendering/shading"))) {
203 // if fastest fog requested, or if flat shading force fastest
204 glHint ( GL_FOG_HINT, GL_FASTEST );
205 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
206 glHint ( GL_FOG_HINT, GL_NICEST );
208 if ( fgGetBool("/sim/rendering/wireframe") ) {
210 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
213 // This is the default anyways, but it can't hurt
214 glFrontFace ( GL_CCW );
217 // glEnable(GL_POINT_SMOOTH);
218 // glEnable(GL_LINE_SMOOTH);
219 // glEnable(GL_POLYGON_SMOOTH);
224 // Update all Visuals (redraws anything graphics related)
226 FGRenderer::update( bool refresh_camera_settings ) {
227 bool scenery_loaded = fgGetBool("sim/sceneryloaded") || fgGetBool("sim/sceneryloaded-override");
229 if ( idle_state < 1000 || !scenery_loaded ) {
230 // still initializing, draw the splash screen
233 // Keep resetting sim time while the sim is initializing
234 globals->set_sim_time_sec( 0.0 );
235 SGAnimation::set_sim_time_sec( 0.0 );
240 bool draw_otw = fgGetBool("/sim/rendering/draw-otw");
241 bool skyblend = fgGetBool("/sim/rendering/skyblend");
242 bool enhanced_lighting = fgGetBool("/sim/rendering/enhanced-lighting");
243 bool distance_attenuation = fgGetBool("/sim/rendering/distance-attenuation");
244 bool volumetric_clouds = sgEnviro.get_clouds_enable_state();
245 #ifdef FG_ENABLE_MULTIPASS_CLOUDS
246 bool multi_pass_clouds = fgGetBool("/sim/rendering/multi-pass-clouds") &&
247 !volumetric_clouds &&
248 !SGCloudLayer::enable_bump_mapping; // ugly artefact now
250 bool multi_pass_clouds = false;
252 bool draw_clouds = fgGetBool("/environment/clouds/status");
254 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
255 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
257 // static const SGPropertyNode *longitude
258 // = fgGetNode("/position/longitude-deg");
259 // static const SGPropertyNode *latitude
260 // = fgGetNode("/position/latitude-deg");
261 // static const SGPropertyNode *altitude
262 // = fgGetNode("/position/altitude-ft");
263 static const SGPropertyNode *groundlevel_nearplane
264 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
266 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
267 static double last_visibility = -9999;
270 double actual_visibility;
271 if (fgGetBool("/environment/clouds/status")) {
272 actual_visibility = thesky->get_visibility();
274 actual_visibility = fgGetDouble("/environment/visibility-m");
277 if ( actual_visibility != last_visibility ) {
278 last_visibility = actual_visibility;
280 fog_exp_density = m_log01 / actual_visibility;
281 fog_exp2_density = sqrt_m_log01 / actual_visibility;
282 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
283 if ( actual_visibility < 8000 ) {
284 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
285 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
287 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
288 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
293 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
294 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
295 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
296 // GLfloat mat_shininess[] = { 10.0 };
297 GLbitfield clear_mask;
299 // idle_state is now 1000 meaning we've finished all our
300 // initializations and are running the main loop, so this will
301 // now work without seg faulting the system.
303 FGViewer *current__view = globals->get_current_view();
305 // calculate our current position in cartesian space
306 Point3D cntr = globals->get_scenery()->get_next_center();
307 globals->get_scenery()->set_center(cntr);
308 current__view->set_scenery_center(cntr);
310 if ( refresh_camera_settings ) {
312 resize( fgGetInt("/sim/startup/xsize"),
313 fgGetInt("/sim/startup/ysize") );
315 // Tell GL we are switching to model view parameters
316 glMatrixMode(GL_MODELVIEW);
318 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
321 clear_mask = GL_DEPTH_BUFFER_BIT;
322 if ( fgGetBool("/sim/rendering/wireframe") ) {
323 clear_mask |= GL_COLOR_BUFFER_BIT;
327 if ( fgGetBool("/sim/rendering/textures") ) {
328 // glClearColor(black[0], black[1], black[2], black[3]);
329 glClearColor(l->adj_fog_color()[0], l->adj_fog_color()[1],
330 l->adj_fog_color()[2], l->adj_fog_color()[3]);
331 clear_mask |= GL_COLOR_BUFFER_BIT;
334 glClearColor(l->sky_color()[0], l->sky_color()[1],
335 l->sky_color()[2], l->sky_color()[3]);
336 clear_mask |= GL_COLOR_BUFFER_BIT;
338 if ( multi_pass_clouds && draw_clouds ) {
340 clear_mask |= GL_STENCIL_BUFFER_BIT;
342 glClear( clear_mask );
344 // set the opengl state to known default values
345 default_state->force();
347 // update fog params if visibility has changed
348 double visibility_meters = fgGetDouble("/environment/visibility-m");
349 thesky->set_visibility(visibility_meters);
351 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
352 ( global_multi_loop * fgGetInt("/sim/speed-up") )
353 / (double)fgGetInt("/sim/model-hz") );
355 // Set correct opengl fog density
356 glFogf (GL_FOG_DENSITY, fog_exp2_density);
358 // update the sky dome
361 SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
362 << l->sky_color()[0] << " "
363 << l->sky_color()[1] << " "
364 << l->sky_color()[2] << " "
365 << l->sky_color()[3] );
366 SG_LOG( SG_GENERAL, SG_BULK, " fog = "
367 << l->fog_color()[0] << " "
368 << l->fog_color()[1] << " "
369 << l->fog_color()[2] << " "
370 << l->fog_color()[3] );
371 SG_LOG( SG_GENERAL, SG_BULK,
372 " sun_angle = " << l->sun_angle
373 << " moon_angle = " << l->moon_angle );
376 static SGSkyColor scolor;
377 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
379 scolor.sky_color = l->sky_color();
380 scolor.fog_color = l->adj_fog_color();
381 scolor.cloud_color = l->cloud_color();
382 scolor.sun_angle = l->get_sun_angle();
383 scolor.moon_angle = l->get_moon_angle();
384 scolor.nplanets = globals->get_ephem()->getNumPlanets();
385 scolor.nstars = globals->get_ephem()->getNumStars();
386 scolor.planet_data = globals->get_ephem()->getPlanets();
387 scolor.star_data = globals->get_ephem()->getStars();
389 thesky->repaint( scolor );
392 SG_LOG( SG_GENERAL, SG_BULK,
393 "thesky->reposition( view_pos = " << view_pos[0] << " "
394 << view_pos[1] << " " << view_pos[2] );
395 SG_LOG( SG_GENERAL, SG_BULK,
396 " zero_elev = " << zero_elev[0] << " "
397 << zero_elev[1] << " " << zero_elev[2]
398 << " lon = " << cur_fdm_state->get_Longitude()
399 << " lat = " << cur_fdm_state->get_Latitude() );
400 SG_LOG( SG_GENERAL, SG_BULK,
401 " sun_rot = " << l->get_sun_rotation
402 << " gst = " << SGTime::cur_time_params->getGst() );
403 SG_LOG( SG_GENERAL, SG_BULK,
404 " sun ra = " << globals->get_ephem()->getSunRightAscension()
405 << " sun dec = " << globals->get_ephem()->getSunDeclination()
406 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
407 << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
410 // The sun and moon distances are scaled down versions
411 // of the actual distance to get both the moon and the sun
412 // within the range of the far clip plane.
413 // Moon distance: 384,467 kilometers
414 // Sun distance: 150,000,000 kilometers
415 double sun_horiz_eff, moon_horiz_eff;
416 if (fgGetBool("/sim/rendering/horizon-effect")) {
417 sun_horiz_eff = 0.67+pow(0.5+cos(l->get_sun_angle())*2/2, 0.33)/3;
418 moon_horiz_eff = 0.67+pow(0.5+cos(l->get_moon_angle())*2/2, 0.33)/3;
420 sun_horiz_eff = moon_horiz_eff = 1.0;
423 static SGSkyState sstate;
425 sstate.view_pos = current__view->get_view_pos();
426 sstate.zero_elev = current__view->get_zero_elev();
427 sstate.view_up = current__view->get_world_up();
428 sstate.lon = current__view->getLongitude_deg()
429 * SGD_DEGREES_TO_RADIANS;
430 sstate.lat = current__view->getLatitude_deg()
431 * SGD_DEGREES_TO_RADIANS;
432 sstate.alt = current__view->getAltitudeASL_ft()
434 sstate.spin = l->get_sun_rotation();
435 sstate.gst = globals->get_time_params()->getGst();
436 sstate.sun_ra = globals->get_ephem()->getSunRightAscension();
437 sstate.sun_dec = globals->get_ephem()->getSunDeclination();
438 sstate.sun_dist = 50000.0 * sun_horiz_eff;
439 sstate.moon_ra = globals->get_ephem()->getMoonRightAscension();
440 sstate.moon_dec = globals->get_ephem()->getMoonDeclination();
441 sstate.moon_dist = 40000.0 * moon_horiz_eff;
443 thesky->reposition( sstate, delta_time_sec );
446 glEnable( GL_DEPTH_TEST );
447 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
449 glFogi( GL_FOG_MODE, GL_EXP2 );
450 glFogfv( GL_FOG_COLOR, l->adj_fog_color() );
453 // set sun/lighting parameters
454 ssgGetLight( 0 ) -> setPosition( l->sun_vec() );
456 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
457 // we only update GL_AMBIENT for our lights we will never get
458 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
459 // explicitely to black.
460 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
462 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient() );
463 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
464 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular() );
466 sgEnviro.setLight(l->adj_fog_color());
468 // texture parameters
469 // glEnable( GL_TEXTURE_2D );
470 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
471 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
474 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
475 - globals->get_scenery()->get_cur_elev();
478 scene_nearplane = 10.0f;
479 scene_farplane = 120000.0f;
481 scene_nearplane = groundlevel_nearplane->getDoubleValue();
482 scene_farplane = 120000.0f;
485 setNearFar( scene_nearplane, scene_farplane );
487 sgEnviro.startOfFrame(current__view->get_view_pos(),
488 current__view->get_world_up(),
489 current__view->getLongitude_deg(),
490 current__view->getLatitude_deg(),
491 current__view->getAltitudeASL_ft() * SG_FEET_TO_METER,
494 if ( draw_otw && skyblend ) {
495 // draw the sky backdrop
497 // we need a white diffuse light for the phase of the moon
498 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
499 thesky->preDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
501 // return to the desired diffuse color
502 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
505 // draw the ssg scene
506 glEnable( GL_DEPTH_TEST );
508 if ( fgGetBool("/sim/rendering/wireframe") ) {
510 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
516 FGTileMgr::set_tile_filter( true );
517 sgSetModelFilter( false );
518 globals->get_aircraft_model()->select( false );
519 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
521 // Disable depth buffer update, draw the clouds
522 glDepthMask( GL_FALSE );
523 if( !volumetric_clouds )
524 thesky->drawUpperClouds();
525 if ( multi_pass_clouds ) {
526 thesky->drawLowerClouds();
528 glDepthMask( GL_TRUE );
530 if ( multi_pass_clouds ) {
531 // Draw the objects except the aircraft
532 // and update the stencil buffer with 1
533 glEnable( GL_STENCIL_TEST );
534 glStencilFunc( GL_ALWAYS, 1, 1 );
535 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
537 FGTileMgr::set_tile_filter( false );
538 sgSetModelFilter( true );
539 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
541 FGTileMgr::set_tile_filter( true );
542 sgSetModelFilter( true );
543 globals->get_aircraft_model()->select( false );
544 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
548 // This is a bit kludgy. Every 200 frames, do an extra
549 // traversal of the scene graph without drawing anything, but
550 // with the field-of-view set to 360x360 degrees. This
551 // ensures that out-of-range random objects that are not in
552 // the current view frustum will still be freed properly.
553 static int counter = 0;
555 if (counter >= 200) {
558 // No need to put the near plane too close;
559 // this way, at least the aircraft can be
561 f.setNearFar(1000, 1000000);
563 ssgGetModelviewMatrix(m);
564 FGTileMgr::set_tile_filter( true );
565 sgSetModelFilter( true );
566 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
570 // change state for lighting here
572 // draw runway lighting
573 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
575 // CLO - 02/25/2005 - DO WE NEED THIS extra fgSetNearFar()?
576 // fgSetNearFar( scene_nearplane, scene_farplane );
578 if ( enhanced_lighting ) {
580 // Enable states for drawing points with GL_extension
581 glEnable(GL_POINT_SMOOTH);
583 if ( distance_attenuation && glPointParameterIsSupported )
585 // Enable states for drawing points with GL_extension
586 glEnable(GL_POINT_SMOOTH);
588 float quadratic[3] = {1.0, 0.001, 0.0000001};
589 // makes the points fade as they move away
590 glPointParameterfvPtr(GL_DISTANCE_ATTENUATION_EXT, quadratic);
591 glPointParameterfPtr(GL_POINT_SIZE_MIN_EXT, 1.0);
596 // blending function for runway lights
597 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
600 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
601 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
602 glEnable(GL_TEXTURE_GEN_S);
603 glEnable(GL_TEXTURE_GEN_T);
604 glPolygonMode(GL_FRONT, GL_POINT);
606 // draw runway lighting
608 ssgCullAndDraw( globals->get_scenery()->get_vasi_lights_root() );
609 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
612 // change punch through and then draw taxi lighting
613 glFogf ( GL_FOG_DENSITY, fog_exp2_density );
615 // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
616 // glFogfv ( GL_FOG_COLOR, taxi_fog );
618 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
622 glPolygonMode(GL_FRONT, GL_FILL);
623 glDisable(GL_TEXTURE_GEN_S);
624 glDisable(GL_TEXTURE_GEN_T);
626 //static int _frame_count = 0;
627 //if (_frame_count % 30 == 0) {
628 // printf("SSG: %s\n", ssgShowStats());
636 if ( enhanced_lighting ) {
637 if ( distance_attenuation && glPointParameterIsSupported ) {
638 glPointParameterfvPtr(GL_DISTANCE_ATTENUATION_EXT,
639 default_attenuation);
643 glDisable(GL_POINT_SMOOTH);
646 // draw ground lighting
647 glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
649 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
652 sgEnviro.drawLightning();
654 if ( draw_otw && draw_clouds ) {
655 if ( multi_pass_clouds ) {
656 // Disable depth buffer update, draw the clouds where the
657 // objects overwrite the already drawn clouds, by testing
658 // the stencil buffer against 1
659 glDepthMask( GL_FALSE );
660 glStencilFunc( GL_EQUAL, 1, 1 );
661 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
662 thesky->drawUpperClouds();
663 thesky->drawLowerClouds();
664 glDepthMask( GL_TRUE );
665 glDisable( GL_STENCIL_TEST );
667 glDepthMask( GL_FALSE );
668 if( volumetric_clouds )
669 thesky->drawUpperClouds();
670 thesky->drawLowerClouds();
671 glDepthMask( GL_TRUE );
674 sgEnviro.drawPrecipitation(
675 fgGetDouble("/environment/metar/rain-norm", 0.0),
676 fgGetDouble("/environment/metar/snow-norm", 0.0),
677 fgGetDouble("/environment/metar/hail-norm", 0.0),
678 current__view->getPitch_deg() - current__view->getPitchOffset_deg(),
679 current__view->getRoll_deg() + current__view->getRollOffset_deg(),
680 - current__view->getHeadingOffset_deg(),
681 fgGetDouble("/velocities/airspeed-kt", 0.0));
684 FGTileMgr::set_tile_filter( false );
685 sgSetModelFilter( false );
686 globals->get_aircraft_model()->select( true );
687 globals->get_model_mgr()->draw();
688 globals->get_aircraft_model()->draw();
689 // If the view is internal, the previous line draw the
690 // cockpit with modified near/far clip planes and deselect
691 // the aircraft in the global scenegraph
692 // Otherwise, it just enables the aircraft: The scenegraph
693 // must be drawn again to see the plane.
694 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
695 FGTileMgr::set_tile_filter( true );
696 sgSetModelFilter( true );
697 globals->get_aircraft_model()->select( true );
700 // display HUD && Panel
702 glDisable( GL_DEPTH_TEST );
703 // glDisable( GL_CULL_FACE );
704 // glDisable( GL_TEXTURE_2D );
706 // update the controls subsystem
707 globals->get_controls()->update(delta_time_sec);
709 hud_and_panel->apply();
712 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
713 // This only works properly if called before the panel call
714 if((fgGetBool("/sim/atc/enabled")) || (fgGetBool("/sim/ai-traffic/enabled")))
715 globals->get_ATC_display()->update(delta_time_sec);
717 // update the panel subsystem
718 if ( globals->get_current_panel() != NULL ) {
719 globals->get_current_panel()->update(delta_time_sec);
723 // We can do translucent menus, so why not. :-)
725 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
727 // glDisable ( GL_BLEND ) ;
729 glEnable( GL_DEPTH_TEST );
732 // Fade out the splash screen over the first three seconds.
733 double t = globals->get_sim_time_sec();
735 fgSplashUpdate((2.5 - t) / 2.5);
740 // options.cxx needs to see this for toggle_panel()
741 // Handle new window size or exposure
743 FGRenderer::resize( int width, int height ) {
746 if ( (!fgGetBool("/sim/virtual-cockpit"))
747 && fgPanelVisible() && idle_state == 1000 ) {
748 view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
749 globals->get_current_panel()->getYOffset()) / 768.0);
754 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
756 fgSetInt("/sim/startup/xsize", width);
757 fgSetInt("/sim/startup/ysize", height);
758 guiInitMouse(width, height);
761 FGViewMgr *viewmgr = globals->get_viewmgr();
763 for ( int i = 0; i < viewmgr->size(); ++i ) {
764 viewmgr->get_view(i)->
765 set_aspect_ratio((float)view_h / (float)width);
768 setFOV( viewmgr->get_current_view()->get_h_fov(),
769 viewmgr->get_current_view()->get_v_fov() );
770 // cout << "setFOV(" << viewmgr->get_current_view()->get_h_fov()
771 // << ", " << viewmgr->get_current_view()->get_v_fov() << ")"
781 // These are wrapper functions around ssgSetNearFar() and ssgSetFOV()
782 // which will post process and rewrite the resulting frustum if we
783 // want to do asymmetric view frustums.
785 static void fgHackFrustum() {
787 // specify a percent of the configured view frustum to actually
788 // display. This is a bit of a hack to achieve asymmetric view
789 // frustums. For instance, if you want to display two monitors
790 // side by side, you could specify each with a double fov, a 0.5
791 // aspect ratio multiplier, and then the left side monitor would
792 // have a left_pct = 0.0, a right_pct = 0.5, a bottom_pct = 0.0,
793 // and a top_pct = 1.0. The right side monitor would have a
794 // left_pct = 0.5 and a right_pct = 1.0.
796 static SGPropertyNode *left_pct
797 = fgGetNode("/sim/current-view/frustum-left-pct");
798 static SGPropertyNode *right_pct
799 = fgGetNode("/sim/current-view/frustum-right-pct");
800 static SGPropertyNode *bottom_pct
801 = fgGetNode("/sim/current-view/frustum-bottom-pct");
802 static SGPropertyNode *top_pct
803 = fgGetNode("/sim/current-view/frustum-top-pct");
805 sgFrustum *f = ssgGetFrustum();
807 // cout << " l = " << f->getLeft()
808 // << " r = " << f->getRight()
809 // << " b = " << f->getBot()
810 // << " t = " << f->getTop()
811 // << " n = " << f->getNear()
812 // << " f = " << f->getFar()
815 double width = f->getRight() - f->getLeft();
816 double height = f->getTop() - f->getBot();
820 if ( left_pct != NULL ) {
821 l = f->getLeft() + width * left_pct->getDoubleValue();
826 if ( right_pct != NULL ) {
827 r = f->getLeft() + width * right_pct->getDoubleValue();
832 if ( bottom_pct != NULL ) {
833 b = f->getBot() + height * bottom_pct->getDoubleValue();
838 if ( top_pct != NULL ) {
839 t = f->getBot() + height * top_pct->getDoubleValue();
844 ssgSetFrustum(l, r, b, t, f->getNear(), f->getFar());
848 // we need some static storage space for these values. However, we
849 // can't store it in a renderer class object because the functions
850 // that manipulate these are static. They are static so they can
851 // interface to the display callback system. There's probably a
852 // better way, there has to be a better way, but I'm not seeing it
854 static float fov_width = 55.0;
855 static float fov_height = 42.0;
856 static float fov_near = 1.0;
857 static float fov_far = 1000.0;
860 /** FlightGear code should use this routine to set the FOV rather than
861 * calling the ssg routine directly
863 void FGRenderer::setFOV( float w, float h ) {
867 // fully specify the view frustum before hacking it (so we don't
868 // accumulate hacked effects
870 ssgSetNearFar( fov_near, fov_far );
872 sgEnviro.setFOV( w, h );
876 /** FlightGear code should use this routine to set the Near/Far clip
877 * planes rather than calling the ssg routine directly
879 void FGRenderer::setNearFar( float n, float f ) {
883 // fully specify the view frustum before hacking it (so we don't
884 // accumulate hacked effects
885 ssgSetNearFar( n, f );
886 ssgSetFOV( fov_width, fov_height );
892 // end of renderer.cxx