#define BOTTOM_ELEV -2000.0
-// static float inner_vertex[12][3];
-// static float middle_vertex[12][3];
-// static float outer_vertex[12][3];
-// static float bottom_vertex[12][3];
-
-// static GLubyte upper_color[12][4];
-// static GLubyte middle_color[12][4];
-// static GLubyte lower_color[12][4];
-
-
// Constructor
FGSkyDome::FGSkyDome( void ) {
}
// initialize the sky object and connect it into our scene graph
bool FGSkyDome::initialize( ) {
- sgVec3 color;
+ sgVec4 color;
float theta;
int i;
dome_state->enable( GL_COLOR_MATERIAL );
dome_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
dome_state->disable( GL_BLEND );
+ dome_state->disable( GL_ALPHA_TEST );
// initialize arrays
center_disk_vl = new ssgVertexArray( 14 );
lower_ring_cl = new ssgColourArray( 26 );
// initially seed to all blue
- sgSetVec3( color, 0.0, 0.0, 1.0 );
+ sgSetVec4( color, 0.0, 0.0, 1.0, 1.0 );
// generate the raw vertex data
sgVec3 center_vertex;
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
-bool FGSkyDome::repaint( sgVec3 sky_color, sgVec3 fog_color, double sun_angle ) {
+bool FGSkyDome::repaint( sgVec4 sky_color, sgVec4 fog_color, double sun_angle )
+{
double diff;
sgVec3 outer_param, outer_amt, outer_diff;
sgVec3 middle_param, middle_amt, middle_diff;
// First, recalulate the basic colors
//
- sgVec3 upper_color[12];
- sgVec3 middle_color[12];
- sgVec3 lower_color[12];
- sgVec3 bottom_color[12];
+ sgVec4 upper_color[12];
+ sgVec4 middle_color[12];
+ sgVec4 lower_color[12];
+ sgVec4 bottom_color[12];
for ( i = 0; i < 6; i++ ) {
for ( j = 0; j < 3; j++ ) {
if ( lower_color[i][j] > 1.0 ) { lower_color[i][j] = 1.0; }
if ( lower_color[i][j] < 0.1 ) { lower_color[i][j] = 0.1; }
}
- // upper_color[i][3] = middle_color[i][3] = lower_color[i][3] =
- // (GLubyte)(sky_color[3] * 1.0);
+ upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = 1.0;
for ( j = 0; j < 3; j++ ) {
outer_amt[j] -= outer_diff[j];
if ( lower_color[i][j] > 1.0 ) { lower_color[i][j] = 1.0; }
if ( lower_color[i][j] < 0.1 ) { lower_color[i][j] = 0.1; }
}
- // upper_color[i][3] = middle_color[i][3] = lower_color[i][3] =
- // (GLubyte)(sky_color[3] * 1.0);
+ upper_color[i][3] = middle_color[i][3] = lower_color[i][3] = 1.0;
for ( j = 0; j < 3; j++ ) {
outer_amt[j] += outer_diff[j];
}
for ( i = 0; i < 12; i++ ) {
- sgCopyVec3( bottom_color[i], fog_color );
+ sgCopyVec4( bottom_color[i], fog_color );
}
//
// update the center disk color arrays
counter = 0;
slot = center_disk_cl->get( counter++ );
- // sgVec3 red;
- // sgSetVec3( red, 1.0, 0.0, 0.0 );
- sgCopyVec3( slot, sky_color );
+ // sgVec4 red;
+ // sgSetVec4( red, 1.0, 0.0, 0.0, 1.0 );
+ sgCopyVec4( slot, sky_color );
for ( i = 11; i >= 0; i-- ) {
slot = center_disk_cl->get( counter++ );
- sgCopyVec3( slot, upper_color[i] );
+ sgCopyVec4( slot, upper_color[i] );
}
slot = center_disk_cl->get( counter++ );
- sgCopyVec3( slot, upper_color[11] );
+ sgCopyVec4( slot, upper_color[11] );
// generate the upper ring
counter = 0;
for ( i = 0; i < 12; i++ ) {
slot = upper_ring_cl->get( counter++ );
- sgCopyVec3( slot, middle_color[i] );
+ sgCopyVec4( slot, middle_color[i] );
slot = upper_ring_cl->get( counter++ );
- sgCopyVec3( slot, upper_color[i] );
+ sgCopyVec4( slot, upper_color[i] );
}
slot = upper_ring_cl->get( counter++ );
- sgCopyVec3( slot, middle_color[0] );
+ sgCopyVec4( slot, middle_color[0] );
slot = upper_ring_cl->get( counter++ );
- sgCopyVec3( slot, upper_color[0] );
+ sgCopyVec4( slot, upper_color[0] );
// generate middle ring
counter = 0;
for ( i = 0; i < 12; i++ ) {
slot = middle_ring_cl->get( counter++ );
- sgCopyVec3( slot, lower_color[i] );
+ sgCopyVec4( slot, lower_color[i] );
slot = middle_ring_cl->get( counter++ );
- sgCopyVec3( slot, middle_color[i] );
+ sgCopyVec4( slot, middle_color[i] );
}
slot = middle_ring_cl->get( counter++ );
- sgCopyVec3( slot, lower_color[0] );
+ sgCopyVec4( slot, lower_color[0] );
slot = middle_ring_cl->get( counter++ );
- sgCopyVec3( slot, middle_color[0] );
+ sgCopyVec4( slot, middle_color[0] );
// generate lower ring
counter = 0;
for ( i = 0; i < 12; i++ ) {
slot = lower_ring_cl->get( counter++ );
- sgCopyVec3( slot, bottom_color[i] );
+ sgCopyVec4( slot, bottom_color[i] );
slot = lower_ring_cl->get( counter++ );
- sgCopyVec3( slot, lower_color[i] );
+ sgCopyVec4( slot, lower_color[i] );
}
slot = lower_ring_cl->get( counter++ );
- sgCopyVec3( slot, bottom_color[0] );
+ sgCopyVec4( slot, bottom_color[0] );
slot = lower_ring_cl->get( counter++ );
- sgCopyVec3( slot, lower_color[0] );
+ sgCopyVec4( slot, lower_color[0] );
return true;
}
// $Id$
+#include <stdio.h>
#include <iostream>
#include <plib/ssg.h>
#include <simgear/constants.h>
+#include <simgear/misc/fgpath.hxx>
#include "sphere.hxx"
#include "skysun.hxx"
}
-static GLuint makeHalo( GLubyte *sun_texbuf ) {
- int texWidth = 64; // 64x64 is plenty
+#if 0
+static GLuint makeHalo( GLubyte *sun_texbuf, int width ) {
int texSize;
GLuint texid;
GLubyte *p;
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
// create the actual texture contents
- texSize = texWidth * texWidth;
+ texSize = width * width;
- sun_texbuf = new GLubyte[texSize*4];
if ( !sun_texbuf ) {
- return 0; // Ugly!
+ cout << "ouch ..." << endl;
+ exit(-1); // Ugly!
}
p = sun_texbuf;
- radius = (double)(texWidth / 2);
+ radius = (double)(width / 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)));
-
+ 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
- *(p+3) = (int)((double) 0xff * (t*t));
+ value = (int)((double) 0xff * (t*t));
} else {
- *(p+3) = 0x00;
+ value = 0x00;
}
- p += 4;
+ *p = value;
+ *(p+1) = value;
+ *(p+2) = value;
+ // *(p+3) = value;
+
+ p += 3;
}
}
- glTexImage2D( GL_TEXTURE_2D,
+ /* glTexImage2D( GL_TEXTURE_2D,
0,
GL_RGBA,
- texWidth, texWidth,
+ width, width,
0,
GL_RGBA, GL_UNSIGNED_BYTE,
- sun_texbuf );
+ sun_texbuf ); */
return texid;
}
-// initialize the sun object and connect it into our scene graph root
-bool FGSkySun::initialize() {
+#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));
+ }
+ }
+ }
+
+ // *(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k));
+
+ fwrite(ibuffer, sizeof(unsigned char), RGB*win_width*win_height, fp);
+ fclose(fp);
+ free(ibuffer);
+
+ printf("wrote file (%d x %d pixels, %d bytes)\n",
+ win_width, win_height, RGB*win_width*win_height);
+}
+#endif
+
+// 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" );
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 ssg scene graph sub tree for the sky and connected
- // into the provide scene graph branch
- sun_selector = new ssgSelector;
- sun_transform = new ssgTransform;
-
- // orb->setState( orb_state );
-
- sun_transform->addKid( orb );
-
- sun_selector->addKid( sun_transform );
- sun_selector->clrTraversalMaskBits( SSGTRAV_HOT );
-
- skysun->addKid( sun_selector );
+ // 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->setShadeModel( GL_SMOOTH );
+ 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->enable( GL_TEXTURE_2D );
- halo_state->enable( GL_COLOR_MATERIAL );
+
+ halo_state->disable( GL_COLOR_MATERIAL );
halo_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
- halo_state->enable( GL_BLEND );
+ 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 the halo
- sun_texid = makeHalo( sun_texbuf );
- halo_state->setTexture( sun_texid );
- cout << "set texture" << endl;;
// Build ssg structure
sgVec3 v3;
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 );
+ sgSetVec3( v3, 5000.0, 0.0, 5000.0 );
+ halo_vl->add( v3 );
sgVec2 v2;
halo_tl = new ssgTexCoordArray;
halo_tl->add( v2 );
sgSetVec2( v2, 1.0, 0.0 );
halo_tl->add( v2 );
- sgSetVec2( v2, 1.0, 1.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_QUADS, halo_vl, NULL, halo_tl, cl );
- halo->setState( halo_state);
+ 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
+ sun_selector = new ssgSelector;
+ sun_transform = new ssgTransform;
+
+ sun_selector->addKid( sun_transform );
+ sun_selector->clrTraversalMaskBits( SSGTRAV_HOT );
+
+ skysun->addKid( sun_selector );
sun_transform->addKid( halo );
+ sun_transform->addKid( orb );
return true;
}
if (ambient < 0.3) { ambient = 0.3; }
if (ambient > 1.0) { ambient = 1.0; }
- sgVec3 color;
- sgSetVec3( color,
+ 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
- );
+ (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;
float *ptr;
ptr = cl->get( 0 );
- sgCopyVec3( ptr, color );
+ sgCopyVec4( ptr, color );
}
return true;
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)
-{
-
- FG_LOG( FG_GENERAL, FG_INFO, "Initializing Sun Texture");
-#ifdef GL_VERSION_1_1
- glGenTextures(1, &sun_texid);
- glBindTexture(GL_TEXTURE_2D, sun_texid);
-#elif GL_EXT_texture_object
- glGenTexturesEXT(1, &sun_texid);
- glBindTextureEXT(GL_TEXTURE_2D, sun_texid);
-#else
-# error port me
-#endif
-
- 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);
- }
-
- //SunList = 0;
- distance = 0.0;
-}
-
-Star::~Star()
-{
- //delete SunObject;
- delete [] sun_texbuf;
-}
-
-
-
-static int texWidth = 256; /* 64x64 is plenty */
-
-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;
-
- 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
-
- lonEcl = v + w; // the sun's true longitude
- latEcl = 0;
-
- // convert the sun's true longitude to ecliptic rectangular
- // geocentric coordinates (xs, ys)
- xs = r * cos (lonEcl);
- ys = r * sin (lonEcl);
-
- // convert ecliptic coordinates to equatorial rectangular
- // geocentric coordinates
-
- xe = xs;
- ye = ys * cos (ecl);
- ze = ys * sin (ecl);
-
- // And finally, calculate right ascension and declination
- rightAscension = atan2 (ye, xe);
- declination = atan2 (ze, sqrt (xe*xe + ye*ye));
-}
-
-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;
- glColor3fv(amb);
- glPushMatrix();
- {
- glRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
- glRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
- glTranslatef(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();
- }
- glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
- glDisable(GL_BLEND); // BLEND DISABLED
- }
-
- glPopMatrix();
- glDisable(GL_LIGHTING); // LIGHTING DISABLED
- glDisable(GL_BLEND); // BLEND DISABLED
- glPushMatrix();
- {
- glRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
- glRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
- glColor4fv(amb);
- glTranslatef(0,60000,0);
- gluSphere( SunObject, sun_size, 10, 10 );
- }
- glPopMatrix();
- glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
- glDisable(GL_BLEND); // BLEND DISABLED
- }
-}
-#endif