/* NIGHTFALL OpenGL Interface */ /* Copyright (C) 2001 Markus Kuster */ /* */ /* This program is free software; you can redistribute it */ /* and/or modify */ /* it under the terms of the GNU General Public License as */ /* published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef _WITH_OPENGL #include #include #include #include #include #include #include #include "LightGLTrackball.h" /* Maximum number of lights allowed in OpenGL */ #define MAX_LIGHT_NUM 8 #define MAX_STR_LEN 256 /* Definitions for light spots used in visualisation */ #define SCENE_LIGHT GL_LIGHT0 #define DISK_SPOT GL_LIGHT1 /* User defined spots */ #define PRIMARY_ONE GL_LIGHT2 #define PRIMARY_TWO GL_LIGHT3 #define SECONDARY_ONE GL_LIGHT4 #define SECONDARY_TWO GL_LIGHT5 #define GLWGAP 10 #define GLHGAP 50 #define GLWIN_WIDTH 800+GLWGAP #define GLWIN_HEIGHT 500+GLHGAP #define GLAREA_WIDTH 800 #define GLAREA_HEIGHT 500 /* 3D viewport */ #define VP_3D_X0 0 #define VP_3D_Y0 50 #define VP_3D_WIDTH 500 #define VP_3D_HEIGHT 450 /* light curve viewport */ #define VP_LC_X0 500 #define VP_LC_Y0 250 #define VP_LC_WIDTH 300 #define VP_LC_HEIGHT 250 /* radial velocity viewport */ #define VP_RV_X0 500 #define VP_RV_Y0 0 #define VP_RV_WIDTH 300 #define VP_RV_HEIGHT 250 float texture_minval[NUM_COMP]; float texture_maxval[NUM_COMP]; /* wedge primary */ #define VP_WP_X0 0 #define VP_WP_Y0 5 #define VP_WP_WIDTH 500 #define VP_WP_HEIGHT 20 /* wedge secondary */ #define VP_WS_X0 0 #define VP_WS_Y0 30 #define VP_WS_WIDTH 500 #define VP_WS_HEIGHT 20 /* wedge disk */ #define VP_WD_X0 0 #define VP_WD_Y0 55 #define VP_WD_WIDTH 500 #define VP_WD_HEIGHT 20 /* Definition of fonts */ #define HELVETICA 0 #define TIMESROMAN 1 /* Plot types */ #define LIGHTCURVE 0 #define RADVELOCITY 1 /* Texturing types */ #define NONE 0 #define IMAGE 1 #define TEMP 2 #define GRAV 3 #define FLUX 4 #define BBCOLOR 5 #define VELOCITY 6 #define TEXTURE_WIDTH 256 #define TEXTURE_HEIGHT 256 #define TEXTURE_COMPONENTS 3 /* Definition of white points for black body color model */ #define D65 0.3127, 0.3291 #define CWP 0.3101, 0.3162 typedef struct AxisStruct { char label[256]; float min_value; float max_value; float length; float numticks; } AxisType; typedef struct CoordFrame { char title[256]; float titlepos; AxisType xaxis; AxisType yaxis; float xborder_size; float yborder_size; } CoordType; typedef struct LightStruct { GLenum Light; /* Which light */ GLfloat Pos[4]; /* position of the light source */ GLfloat Direction[3]; /* direction vector of the spot */ GLfloat Diffuse; GLfloat Specular; GLfloat Const_Att; GLfloat Lin_Att; GLfloat Quad_Att; } LightType; /* texture information */ typedef struct TextureStruct { int IsOn; /* we want texturing (ON/OFF) */ int Type; /* What kind of texture */ char TextFile[1024+MAX_CFG_INLINE+1]; /* texture image file */ GLint Width; /* width of the image */ GLint Height; /* height of the image */ GLint Components; /* depth of image */ GLuint TexName; /* texture name */ } TextureType; extern struct GLColorSystem { /* We give only X and Y values here, because the Z values are implicitly */ /* given by the relations Zn = 1.0 - (Xn + Yn), where n = r,g,b */ double xr,yr, xg,yg, xb,yb, xw,yw; } Temp; /* display information */ typedef struct { float mousex,mousey; /* position of mouse */ float quat[4]; /* orientation of object */ float zoom; /* field of view in degrees */ float xpos; /* x position of the observer */ } DispInfo; /* 3D animation */ void AnimateGL( int j ); /* Init 3D model */ gint GLInit3d( GtkWidget *widget ); gint GLLightPlot(GtkWidget *widget ); /* Init lighting */ void GLInitLighting( GtkWidget *widget ); /* color stuff for GL */ void GLBBtoXYZ(double temperature, double *X, double *Y,double *Z); void GLXYZtoRGB(double *X, double *Y,double *Z, double *R, double *G, double *B); /* Init spots on components */ void GLMakeSpots( int Comp, float xpos ); /* Update all graphic viewports */ void GLUpdateAll( void ); /* Update the primary/secondary geometry */ void GLUpdate3d( GtkWidget *widget ); /* Update plot viewport */ void GLUpdatePlot( int viewport, int type ); /* Button event */ gint GLButtonPress(GtkWidget *widget, GdkEventButton *event); /* Motion event */ gint GLMotionNotify(GtkWidget *widget, GdkEventMotion *event); /* Reshape for GL code */ gint GLReshape( GtkWidget *widget, GdkEventConfigure *event ); /* Display function for GL mode */ void GLDisplayAll( void ); void GLDisplay3d( GtkWidget *widget ); void GLDisplayPlot( GtkWidget *widget, int type); void GLDisplayWedge( int Comp ); void GLMakeLCPlot( void ); void GLMakeRVPlot( void ); /* Display list for the components */ void GLMakeVolumeEclipsed( int Comp ); /* Keybord related function for GL mode */ gint GLKeyboard(GtkWidget *widget, GdkEventKey *event); /* Set default values for coordinate system */ CoordType SetupCoords(float ymin, float ymax,char *xlabel, char *ylabel, char *title); /* Draw x-, y-, z-Axes */ void GLDrawAxes(GLfloat length, GtkWidget *widget); /* Draw x- and y-Axes for plotting light curve */ void GLMake2DAxes(CoordType CoordPara, GtkWidget *widget); /* Draw some labels */ void GLDrawLabels(GtkWidget *widget); /* GL sting plotting functions */ void GLSetFont(int style, int size); void GLDrawStr(GLfloat x, GLfloat y, GLfloat z, char* format, ...); /* Texturing stuff */ int GLInitTextureParams(int Comp); int GLInitTexture(int Comp, int type); double GLbbflux(double lambda, double temp); void GLBBtoxyz(double temperature, double *x, double *y,double *z); void GLxyztoRGB(struct GLColorSystem *csyst, double x, double y,double z, double *R, double *G, double *B); /* libjpeg suff */ GLubyte *ReadJPEGFile(char *filename, int *width, int *height, int *components); int WriteJPEGFile(JSAMPLE *imgbuff, char *filename, int imgwidth, int imgheight, int components, int quality); int GLGrabScreen(char *filename, int x0, int y0, int width, int height, int quality); /* Gtk Menu for GL window */ void GLMakeMenu(GtkWidget *glmenu_bar); void GLAnimationEvent (GtkWidget *widget, gpointer *data); /* Preferences window */ extern GtkWidget *glPrefsWindow; extern GtkWidget *glArea,*glWindow; /* OpenGL window opened */ extern int GLWindowOpened; /* OpenGL window hidden */ extern int GLWindowHidden; /* OpenGL preferences window opened */ extern int GLPrefWinOpened; extern GLdouble a; /* Display lists */ extern GLint thePrimary, theSecondary, theDisk; /* Display contexts */ extern GtkWidget *glArea,*glPlot,*glVelo,*glWindow; /* Color definitions for primary component */ extern GLfloat primary_colour[4]; extern GLfloat primary_mat_specular[4]; extern GLfloat primary_mat_diffuse[4]; extern GLfloat primary_mat_shininess[1]; /* Color definitions for secondary component */ extern GLfloat secondary_colour[4]; extern GLfloat secondary_mat_specular[4]; extern GLfloat secondary_mat_diffuse[4]; extern GLfloat secondary_mat_shininess[4]; /* color and emission properties of the disk */ /* disk */ extern GLfloat disk_colour[4]; extern GLfloat disk_mat_specular[4]; extern GLfloat disk_mat_diffuse[4]; extern GLfloat disk_mat_shininess[1]; extern GLfloat bulge_light[4]; extern GLfloat bgd_colour[4]; /* Display lists */ extern GLint PrimaryList, SecondaryList, DiskList, PlotList[2]; /* Texture definitions */ extern TextureType Texture[3]; extern LightType Lights[MAX_LIGHT_NUM]; extern int phaseind; /* Paramters for the coordinate systems */ extern CoordType CoordSys[2]; extern double RtoL2,RtoL3; #endif