]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sky/skysun.cxx
Working on ssg-ifying sky.
[simgear.git] / simgear / sky / skysun.cxx
index 583593f7f4ca374732362bed2bedc7c12a875353..1e40e2a51a3a52a3d9e0507f39c38e083fbac179 100644 (file)
 // $Id$
 
 
-// #ifdef __BORLANDC__
-// #  define exception c_exception
-// #endif
-// #include <math.h>
+#include <stdio.h>
+#include <iostream>
 
-// #include <simgear/debug/logstream.hxx>
-
-// #include <Time/sunpos.hxx>
-// #include <Time/light.hxx>
-// #include <Main/options.hxx>
+#include <plib/ssg.h>
 
+#include <simgear/constants.h>
+#include <simgear/misc/fgpath.hxx>
 
+#include "sphere.hxx"
 #include "skysun.hxx"
 
 
@@ -49,390 +46,303 @@ FGSkySun::~FGSkySun( void ) {
 }
 
 
-// initialize the sun object and connect it into our scene graph root
-bool FGSkySun::initialize() {
-    sgVec3 color;
-
-    float theta;
-    int i;
-
-    // create the scene graph for the dome
-    skysun = new ssgRoot;
-    skysun->setName( "Sky Sun" );
+#if 0
+static GLuint makeHalo( GLubyte *sun_texbuf, int width ) {
+    int texSize;
+    GLuint texid;
+    GLubyte *p;
+    int i,j;
+    double radius;
+  
+    // create a texture id
+#ifdef GL_VERSION_1_1
+    glGenTextures(1, &texid);
+    glBindTexture(GL_TEXTURE_2D, texid);
+#elif GL_EXT_texture_object
+    glGenTexturesEXT(1, &texid);
+    glBindTextureEXT(GL_TEXTURE_2D, texid);
+#else
+#   error port me
+#endif
 
-    // set up the state
-    sun_state = new ssgSimpleState();
-    sun_state->setShadeModel( GL_SMOOTH );
-    sun_state->disable( GL_LIGHTING );
-    sun_state->disable( GL_DEPTH_TEST );
-    sun_state->disable( GL_CULL_FACE );
-    sun_state->disable( GL_TEXTURE_2D );
-    sun_state->disable( GL_COLOR_MATERIAL );
-    sun_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
-
-    // initially seed to all white
-    sgSetVec3( color, 1.0, 1.0, 1.0 );
-
-    // generate the raw vertex data
-    sgVec3 center_vertex;
-    sgVec3 upper_vertex[12];
-    sgVec3 middle_vertex[12];
-    sgVec3 lower_vertex[12];
-    sgVec3 bottom_vertex[12];
-
-    sgSetVec3( center_vertex, 0.0, 0.0, CENTER_ELEV );
-
-    for ( i = 0; i < 12; i++ ) {
-       theta = (i * 30.0) * DEG_TO_RAD;
-
-       sgSetVec3( upper_vertex[i],
-                  cos(theta) * UPPER_RADIUS,
-                  sin(theta) * UPPER_RADIUS,
-                  UPPER_ELEV );
-       
-       sgSetVec3( middle_vertex[i],
-                  cos((double)theta) * MIDDLE_RADIUS,
-                  sin((double)theta) * MIDDLE_RADIUS,
-                  MIDDLE_ELEV );
-
-       sgSetVec3( lower_vertex[i],
-                  cos((double)theta) * LOWER_RADIUS,
-                  sin((double)theta) * LOWER_RADIUS,
-                  LOWER_ELEV );
-
-       sgSetVec3( bottom_vertex[i],
-                  cos((double)theta) * BOTTOM_RADIUS,
-                  sin((double)theta) * BOTTOM_RADIUS,
-                  BOTTOM_ELEV );
+    glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
+    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
+    // create the actual texture contents
+    texSize = width * width;
+  
+    if ( !sun_texbuf ) {
+       cout << "ouch ..." << endl;
+       exit(-1);  // Ugly!
     }
 
-    // generate the center disk vertex/color arrays
-    center_disk_vl->add( center_vertex );
-    center_disk_cl->add( color );
-    for ( i = 11; i >= 0; i-- ) {
-       center_disk_vl->add( upper_vertex[i] );
-       center_disk_cl->add( color );
+    p = sun_texbuf;
+  
+    radius = (double)(width / 2);
+  
+    GLubyte value;
+    double x, y, d;
+    for ( i = 0; i < width; i++ ) {
+       for ( j = 0; j < width; j++ ) {
+           x = fabs((double)(i - (width / 2)));
+           y = fabs((double)(j - (width / 2)));
+           d = sqrt((x * x) + (y * y));
+           if (d < radius) {
+               // t is 1.0 at center, 0.0 at edge
+               double t = 1.0 - (d / radius);
+
+               // inverse square looks nice 
+               value = (int)((double) 0xff * (t*t));
+           } else {
+               value = 0x00;
+           }
+           *p = value;
+           *(p+1) = value;
+           *(p+2) = value;
+           // *(p+3) = value;
+
+           p += 3;
+       }
     }
-    center_disk_vl->add( upper_vertex[11] );
-    center_disk_cl->add( color );
-
-    // generate the upper ring
-    for ( i = 0; i < 12; i++ ) {
-       upper_ring_vl->add( middle_vertex[i] );
-       upper_ring_cl->add( color );
 
-       upper_ring_vl->add( upper_vertex[i] );
-       upper_ring_cl->add( color );
-    }
-    upper_ring_vl->add( middle_vertex[0] );
-    upper_ring_cl->add( color );
+    /* glTexImage2D( GL_TEXTURE_2D,
+                 0,
+                 GL_RGBA,
+                 width, width,
+                 0,
+                 GL_RGBA, GL_UNSIGNED_BYTE,
+                 sun_texbuf ); */
 
-    upper_ring_vl->add( upper_vertex[0] );
-    upper_ring_cl->add( color );
+    return texid;
+}
 
-    // generate middle ring
-    for ( i = 0; i < 12; i++ ) {
-       middle_ring_vl->add( lower_vertex[i] );
-       middle_ring_cl->add( color );
 
-       middle_ring_vl->add( middle_vertex[i] );
-       middle_ring_cl->add( color );
+#define RGB  3                 // 3 bytes of color info per pixel
+#define RGBA 4                 // 4 bytes of color+alpha info
+void my_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int win_height, int mode)
+{
+    int i, j, k, q;
+    unsigned char *ibuffer;
+    FILE *fp;
+    int pixelSize = mode==GL_RGBA?4:3;
+
+    ibuffer = (unsigned char *) malloc(win_width*win_height*RGB);
+
+    fp = fopen(filename, "wb");
+    fprintf(fp, "P6\n# CREATOR: glReadPixel()\n%d %d\n%d\n",
+           win_width, win_height, UCHAR_MAX);
+    q = 0;
+    for (i = 0; i < win_height; i++) {
+       for (j = 0; j < win_width; j++) {
+           for (k = 0; k < RGB; k++) {
+               ibuffer[q++] = (unsigned char)
+                   *(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k));
+           }
+       }
     }
-    middle_ring_vl->add( lower_vertex[0] );
-    middle_ring_cl->add( color );
 
-    middle_ring_vl->add( middle_vertex[0] );
-    middle_ring_cl->add( color );
+    // *(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k));
 
-    // generate lower ring
-    for ( i = 0; i < 12; i++ ) {
-       lower_ring_vl->add( bottom_vertex[i] );
-       lower_ring_cl->add( color );
+    fwrite(ibuffer, sizeof(unsigned char), RGB*win_width*win_height, fp);
+    fclose(fp);
+    free(ibuffer);
 
-       lower_ring_vl->add( lower_vertex[i] );
-       lower_ring_cl->add( color );
-    }
-    lower_ring_vl->add( bottom_vertex[0] );
-    lower_ring_cl->add( color );
+    printf("wrote file (%d x %d pixels, %d bytes)\n",
+          win_width, win_height, RGB*win_width*win_height);
+}
+#endif
 
-    lower_ring_vl->add( lower_vertex[0] );
-    lower_ring_cl->add( color );
 
-    // force a repaint of the sky colors with ugly defaults
-    sgVec3 fog_color;
-    sgSetVec3( fog_color, 1.0, 1.0, 1.0 );
-    repaint( color, fog_color, 0.0 );
+// initialize the sun object and connect it into our scene graph root
+bool FGSkySun::initialize( const FGPath& path ) {
+    // create the scene graph for the sun/halo
+    skysun = new ssgRoot;
+    skysun->setName( "Sky Sun" );
+
+    // set up the orb state
+    orb_state = new ssgSimpleState();
+    orb_state->setShadeModel( GL_SMOOTH );
+    orb_state->disable( GL_LIGHTING );
+    orb_state->disable( GL_CULL_FACE );
+    orb_state->disable( GL_TEXTURE_2D );
+    orb_state->enable( GL_COLOR_MATERIAL );
+    orb_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
+    orb_state->disable( GL_BLEND );
+    orb_state->disable( GL_ALPHA_TEST );
+
+    cl = new ssgColourArray( 1 );
+    sgVec4 color;
+    sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
+    cl->add( color );
+
+    ssgBranch *orb = ssgMakeSphere( orb_state, cl, 550.0, 10, 10 );
+
+    // force a repaint of the sun colors with arbitrary defaults
+    repaint( 0.0 );
+
+    // build the halo
+    // sun_texbuf = new GLubyte[64*64*3];
+    // sun_texid = makeHalo( sun_texbuf, 64 );
+    // my_glWritePPMFile("sunhalo.ppm", sun_texbuf, 64, 64, RGB);
+
+    // set up the halo state
+    FGPath halo_path = path;
+    halo_path.append( "halo.rgba" );
+
+    halo_state = new ssgSimpleState();
+    halo_state->setTexture( (char *)halo_path.c_str() );
+    // halo_state->setTexture( sun_texid );
+    halo_state->enable( GL_TEXTURE_2D );
+    halo_state->disable( GL_LIGHTING );
+    halo_state->setShadeModel( GL_SMOOTH );
+    halo_state->disable( GL_CULL_FACE );
+
+    halo_state->disable( GL_COLOR_MATERIAL );
+    halo_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
+    halo_state->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
+    halo_state -> setMaterial ( GL_EMISSION, 0, 0, 0, 1 ) ;
+    halo_state -> setMaterial ( GL_SPECULAR, 0, 0, 0, 1 ) ;
+    // halo_state -> setShininess ( 0 ) ;
+
+    halo_state->setTranslucent();
+    halo_state->enable( GL_ALPHA_TEST );
+    halo_state->setAlphaClamp(0.01);
+    halo_state->enable ( GL_BLEND ) ;
+
+
+    // Build ssg structure
+    sgVec3 v3;
+    halo_vl = new ssgVertexArray;
+    sgSetVec3( v3, -5000.0, 0.0, -5000.0 );
+    halo_vl->add( v3 );
+    sgSetVec3( v3, 5000.0, 0.0, -5000.0 );
+    halo_vl->add( v3 );
+    sgSetVec3( v3, -5000.0, 0.0,  5000.0 );
+    halo_vl->add( v3 );
+    sgSetVec3( v3, 5000.0, 0.0,  5000.0 );
+    halo_vl->add( v3 );
+
+    sgVec2 v2;
+    halo_tl = new ssgTexCoordArray;
+    sgSetVec2( v2, 0.0f, 0.0f );
+    halo_tl->add( v2 );
+    sgSetVec2( v2, 1.0, 0.0 );
+    halo_tl->add( v2 );
+    sgSetVec2( v2, 0.0, 1.0 );
+    halo_tl->add( v2 );
+    sgSetVec2( v2, 1.0, 1.0 );
+    halo_tl->add( v2 );
+
+    ssgLeaf *halo = 
+       new ssgVtxTable ( GL_TRIANGLE_STRIP, halo_vl, NULL, halo_tl, cl );
+    halo->setState( halo_state );
 
     // build the ssg scene graph sub tree for the sky and connected
     // into the provide scene graph branch
-    dome_selector = new ssgSelector;
-    dome_transform = new ssgTransform;
+    sun_selector = new ssgSelector;
+    sun_transform = new ssgTransform;
 
-    ssgVtxTable *center_disk, *upper_ring, *middle_ring, *lower_ring;
+    sun_selector->addKid( sun_transform );
+    sun_selector->clrTraversalMaskBits( SSGTRAV_HOT );
 
-    center_disk = new ssgVtxTable( GL_TRIANGLE_FAN, 
-                                  center_disk_vl, NULL, NULL, center_disk_cl );
+    skysun->addKid( sun_selector );
 
-    upper_ring = new ssgVtxTable( GL_TRIANGLE_STRIP, 
-                                 upper_ring_vl, NULL, NULL, upper_ring_cl );
-
-    middle_ring = new ssgVtxTable( GL_TRIANGLE_STRIP, 
-                                  middle_ring_vl, NULL, NULL, middle_ring_cl );
-
-    lower_ring = new ssgVtxTable( GL_TRIANGLE_STRIP, 
-                                 lower_ring_vl, NULL, NULL, lower_ring_cl );
-
-    center_disk->setState( dome_state );
-    upper_ring->setState( dome_state );
-    middle_ring->setState( dome_state );
-    lower_ring->setState( dome_state );
-
-    dome_transform->addKid( center_disk );
-    dome_transform->addKid( upper_ring );
-    dome_transform->addKid( middle_ring );
-    dome_transform->addKid( lower_ring );
-
-    dome_selector->addKid( dome_transform );
-    dome_selector->clrTraversalMaskBits( SSGTRAV_HOT );
-
-    dome->addKid( dome_selector );
+    sun_transform->addKid( halo );
+    sun_transform->addKid( orb );
 
     return true;
 }
 
 
-#if 0
-/*************************************************************************
- * Star::Star(FGTime *t)
- * Public constructor for class Star
- * Argument: The current time.
- * the hard coded orbital elements our sun are passed to 
- * CelestialBody::CelestialBody();
- * note that the word sun is avoided, in order to prevent some compilation
- * problems on sun systems 
- ************************************************************************/
-Star::Star(FGTime *t) :
-  CelestialBody (0.000000,  0.0000000000,
-                0.0000,    0.00000,
-                282.9404,  4.7093500E-5,       
-                1.0000000, 0.000000,   
-                0.016709,  -1.151E-9,
-                356.0470,  0.98560025850, t)
-{
+// repaint the sun colors based on current value of sun_angle in
+// degrees relative to verticle
+// 0 degrees = high noon
+// 90 degrees = sun rise/set
+// 180 degrees = darkest midnight
+bool FGSkySun::repaint( double sun_angle ) {
+    if ( sun_angle * RAD_TO_DEG < 100 ) {
+       // else sun is well below horizon (so no point in repainting it)
     
-  FG_LOG( FG_GENERAL, FG_INFO, "Initializing Sun Texture");
-#ifdef GL_VERSION_1_1
-  xglGenTextures(1, &sun_texid);
-  xglBindTexture(GL_TEXTURE_2D, sun_texid);
-#elif GL_EXT_texture_object
-  xglGenTexturesEXT(1, &sun_texid);
-  xglBindTextureEXT(GL_TEXTURE_2D, sun_texid);
-#else
-#  error port me
-#endif
+       // x_10 = sun_angle^10
+       double x_10 = sun_angle * sun_angle * sun_angle * sun_angle * sun_angle
+           * sun_angle * sun_angle * sun_angle * sun_angle * sun_angle;
+
+       float ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
+       if (ambient < 0.3) { ambient = 0.3; }
+       if (ambient > 1.0) { ambient = 1.0; }
+
+       sgVec4 color;
+       sgSetVec4( color,
+                  (ambient * 6.0)  - 1.0, // minimum value = 0.8
+                  (ambient * 11.0) - 3.0, // minimum value = 0.3
+                  (ambient * 12.0) - 3.6, // minimum value = 0.0
+                  1.0 );
+    
+       if (color[0] > 1.0) color[0] = 1.0;
+       if (color[1] > 1.0) color[1] = 1.0;
+       if (color[2] > 1.0) color[2] = 1.0;
+
+       // cout << "color = " << color[0] << " " << color[1] << " " 
+       //      << color[2] << endl;
 
-  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-  setTexture();
-  glTexImage2D( GL_TEXTURE_2D,
-               0,
-               GL_RGBA,
-               256, 256,
-               0,
-               GL_RGBA, GL_UNSIGNED_BYTE,
-               sun_texbuf);
-     
-  SunObject = gluNewQuadric();
-  if(SunObject == NULL)
-    {
-      printf("gluNewQuadric(SunObject) failed  !\n");
-      exit(0);
+       float *ptr;
+       ptr = cl->get( 0 );
+       sgCopyVec4( ptr, color );
     }
-  
-  //SunList = 0;
-  distance = 0.0;
-}
 
-Star::~Star()
-{
-  //delete SunObject;
-  delete [] sun_texbuf;
+    return true;
 }
 
 
+// reposition the sun at the specified right ascension and
+// declination, offset by our current position (p) so that it appears
+// fixed at a great distance from the viewer.  Also add in an optional
+// rotation (i.e. for the current time of day.)
+bool FGSkySun::reposition( sgVec3 p, double angle,
+                          double rightAscension, double declination )
+{
+    sgMat4 T1, T2, GST, RA, DEC;
+    sgVec3 axis;
+    sgVec3 v;
 
-static int texWidth = 256;     /* 64x64 is plenty */
+    sgMakeTransMat4( T1, p );
 
-void Star::setTexture()
-{
-  int texSize;
-  //void *textureBuf;
-  GLubyte *p;
-  int i,j;
-  double radius;
-  
-  texSize = texWidth*texWidth;
-  
-  sun_texbuf = new GLubyte[texSize*4];
-  if (!sun_texbuf) 
-    return;  // Ugly!
-  
-  p = sun_texbuf;
-  
-  radius = (double)(texWidth / 2);
-  
-  for (i=0; i < texWidth; i++) {
-    for (j=0; j < texWidth; j++) {
-      double x, y, d;
-           
-      *p = 0xff;
-      *(p+1) = 0xff;
-      *(p+2) = 0xff;
-
-      x = fabs((double)(i - (texWidth / 2)));
-      y = fabs((double)(j - (texWidth / 2)));
-
-      d = sqrt((x * x) + (y * y));
-      if (d < radius) {
-         double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
-         // inverse square looks nice 
-         *(p+3) = (int)((double) 0xff * (t*t));
-      } else {
-         *(p+3) = 0x00;
-      }
-      p += 4;
-    }
-  }
-  //gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth, 
-  //       GL_LUMINANCE,
-  //       GL_UNSIGNED_BYTE, textureBuf);
-  //free(textureBuf);
-}
-/*************************************************************************
- * void Jupiter::updatePosition(FGTime *t, Star *ourSun)
- * 
- * calculates the current position of our sun.
- *************************************************************************/
-void Star::updatePosition(FGTime *t)
-{
-  double 
-    actTime, eccAnom, 
-    xv, yv, v, r,
-    xe, ye, ze, ecl;
+    sgSetVec3( axis, 0.0, 0.0, -1.0 );
+    sgMakeRotMat4( GST, angle, axis );
 
-  updateOrbElements(t);
-  
-  actTime = fgCalcActTime(t);
-  ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle in Radians
-  eccAnom = fgCalcEccAnom(M, e);  // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
-  
-  xv = cos(eccAnom) - e;
-  yv = sqrt (1.0 - e*e) * sin(eccAnom);
-  v = atan2 (yv, xv);                   // the sun's true anomaly
-  distance = r = sqrt (xv*xv + yv*yv);  // and its distance
+    // xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
+    sgSetVec3( axis, 0.0, 0.0, 1.0 );
+    sgMakeRotMat4( RA, (rightAscension * RAD_TO_DEG) - 90.0, axis );
 
-  lonEcl = v + w; // the sun's true longitude
-  latEcl = 0;
+    // xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
+    sgSetVec3( axis, 1.0, 0.0, 0.0 );
+    sgMakeRotMat4( DEC, declination * RAD_TO_DEG, axis );
 
-  // convert the sun's true longitude to ecliptic rectangular 
-  // geocentric coordinates (xs, ys)
-  xs = r * cos (lonEcl);
-  ys = r * sin (lonEcl);
+    // xglTranslatef(0,60000,0);
+    sgSetVec3( v, 0.0, 60000.0, 0.0 );
+    sgMakeTransMat4( T2, v );
 
-  // convert ecliptic coordinates to equatorial rectangular
-  // geocentric coordinates
+    sgMat4 TRANSFORM;
+    sgCopyMat4( TRANSFORM, T1 );
+    sgPreMultMat4( TRANSFORM, GST );
+    sgPreMultMat4( TRANSFORM, RA );
+    sgPreMultMat4( TRANSFORM, DEC );
+    sgPreMultMat4( TRANSFORM, T2 );
 
-  xe = xs;
-  ye = ys * cos (ecl);
-  ze = ys * sin (ecl);
+    sgCoord skypos;
+    sgSetCoord( &skypos, TRANSFORM );
 
-  // And finally, calculate right ascension and declination
-  rightAscension = atan2 (ye, xe);
-  declination = atan2 (ze, sqrt (xe*xe + ye*ye));
+    sun_transform->setTransform( &skypos );
+
+    return true;
 }
-  
-void Star::newImage(void)
-{
-  /*static float stars[3];
-  stars[0] = 0.0;
-  stars[1] = 0.0;
-  stars[2] = 1.0;*/
 
-  fgLIGHT *l = &cur_light_params;
-  float sun_angle = l->sun_angle;
-  
-  if( sun_angle*RAD_TO_DEG < 100 ) { // else no need to draw sun
-    
-    
-    double x_2, x_4, x_8, x_10;
-    GLfloat ambient;
-    GLfloat amb[4];
-    int sun_size = 550;
-    
-    // daily variation sun gets larger near horizon
-    /*if(sun_angle*RAD_TO_DEG > 84.0 && sun_angle*RAD_TO_DEG < 95)
-      {
-      double sun_grow = 9*fabs(94-sun_angle*RAD_TO_DEG);
-      sun_size = (int)(sun_size + sun_size * cos(sun_grow*DEG_TO_RAD));
-      }*/
-    x_2 = sun_angle * sun_angle;
-    x_4 = x_2 * x_2;
-    x_8 = x_4 * x_4;
-    x_10 = x_8 * x_2;
-    ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
-    if (ambient < 0.3) ambient = 0.3;
-    if (ambient > 1.0) ambient = 1.0;
-    
-    amb[0] = ((ambient * 6.0)  - 1.0); // minimum value = 0.8
-    amb[1] = ((ambient * 11.0) - 3.0); // minimum value = 0.3
-    amb[2] = ((ambient * 12.0) - 3.6); // minimum value = 0.0
-    amb[3] = 1.00;
-    
-    if (amb[0] > 1.0) amb[0] = 1.0;
-    if (amb[1] > 1.0) amb[1] = 1.0;
-    if (amb[2] > 1.0) amb[2] = 1.0;
-    xglColor3fv(amb);
-    glPushMatrix();
-    {
-      xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
-      xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
-      xglTranslatef(0,60000,0);
-      if (current_options.get_textures())
-       {
-         glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
-         glEnable(GL_BLEND);   // BLEND ENABLED
-         
-         // glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-         glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
-         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);  
-         glBindTexture(GL_TEXTURE_2D, sun_texid);
-
-         glBegin(GL_QUADS);
-         glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
-         glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
-         glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0,  5000);
-         glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0,  5000);
-         glEnd();
-       }
-      xglDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
-      xglDisable(GL_BLEND);    // BLEND DISABLED
-    }
 
-    glPopMatrix();
-    glDisable(GL_LIGHTING);    // LIGHTING DISABLED
-    glDisable(GL_BLEND);       // BLEND DISABLED
-    glPushMatrix();
-    {     
-      xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
-      xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
-      xglColor4fv(amb);
-      xglTranslatef(0,60000,0);
-      gluSphere( SunObject,  sun_size, 10, 10 );
-      }
-    glPopMatrix();
-    glDisable(GL_TEXTURE_2D);  // TEXTURE DISABLED
-    glDisable(GL_BLEND);       // BLEND DISABLED  
-  }
+// Draw the sun
+bool FGSkySun::draw() {
+    ssgCullAndDraw( skysun );
+
+    return true;
 }
-#endif