1 /* NIGHTFALL OpenGL Interface                                              */
2 /* Copyright (C) 2001 Markus Kuster                                        */
3 /*                                                                         */
4 /*  This program is free software; you can redistribute it                 */
5 /*  and/or modify                                                          */
6 /*  it under the terms of the GNU General Public License as                */
7 /*  published by                                                           */
8 /*  the Free Software Foundation; either version 2 of the License, or      */
9 /*  (at your option) any later version.                                    */
10 /*                                                                         */
11 /*  This program is distributed in the hope that it will be useful,        */
12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of         */
13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
14 /*  GNU General Public License for more details.                           */
15 /*                                                                         */
16 /*  You should have received a copy of the GNU General Public License      */
17 /*  along with this program; if not, write to the Free Software            */
18 /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
19 
20 #ifdef _WITH_OPENGL
21 #include <gtk/gtk.h>
22 #include <gdk/gdk.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtkgl/gtkglarea.h>
25 #include <GL/gl.h>
26 #include <GL/glut.h>
27 #include <jpeglib.h>
28 
29 #include "LightGLTrackball.h"
30 
31 /* Maximum number of lights allowed in OpenGL */
32 #define MAX_LIGHT_NUM 8
33 #define MAX_STR_LEN   256
34 
35 /* Definitions for light spots used in visualisation */
36 #define SCENE_LIGHT   GL_LIGHT0
37 #define DISK_SPOT     GL_LIGHT1
38 /* User defined spots                           */
39 #define PRIMARY_ONE   GL_LIGHT2
40 #define PRIMARY_TWO   GL_LIGHT3
41 #define SECONDARY_ONE GL_LIGHT4
42 #define SECONDARY_TWO GL_LIGHT5
43 
44 #define GLWGAP        10
45 #define GLHGAP        50
46 #define GLWIN_WIDTH   800+GLWGAP
47 #define GLWIN_HEIGHT  500+GLHGAP
48 
49 #define GLAREA_WIDTH  800
50 #define GLAREA_HEIGHT 500
51 
52 /* 3D viewport           */
53 #define VP_3D_X0      0
54 #define VP_3D_Y0      50
55 #define VP_3D_WIDTH   500
56 #define VP_3D_HEIGHT  450
57 
58 /* light curve viewport           */
59 #define VP_LC_X0      500
60 #define VP_LC_Y0      250
61 #define VP_LC_WIDTH   300
62 #define VP_LC_HEIGHT  250
63 
64 /* radial velocity viewport       */
65 #define VP_RV_X0      500
66 #define VP_RV_Y0      0
67 #define VP_RV_WIDTH   300
68 #define VP_RV_HEIGHT  250
69 
70 extern float   texture_minval[NUM_COMP];
71 extern float   texture_maxval[NUM_COMP];
72 
73 /* wedge primary */
74 #define VP_WP_X0      0
75 #define VP_WP_Y0      5
76 #define VP_WP_WIDTH   500
77 #define VP_WP_HEIGHT  20
78 
79 /* wedge secondary */
80 #define VP_WS_X0      0
81 #define VP_WS_Y0      30
82 #define VP_WS_WIDTH   500
83 #define VP_WS_HEIGHT  20
84 
85 /* wedge disk */
86 #define VP_WD_X0      0
87 #define VP_WD_Y0      55
88 #define VP_WD_WIDTH   500
89 #define VP_WD_HEIGHT  20
90 
91 /* Definition of fonts */
92 #define HELVETICA  0
93 #define TIMESROMAN 1
94 
95 /* Plot types          */
96 #define LIGHTCURVE  0
97 #define RADVELOCITY 1
98 
99 /* Texturing types     */
100 #define NONE        0
101 #define IMAGE       1
102 #define TEMP        2
103 #define GRAV        3
104 #define FLUX        4
105 #define BBCOLOR     5
106 #define VELOCITY    6
107 
108 #define TEXTURE_WIDTH  256
109 #define TEXTURE_HEIGHT 256
110 #define TEXTURE_COMPONENTS  3
111 
112 /* Definition of white points for black body color model */
113 #define D65     0.3127, 0.3291
114 #define CWP     0.3101, 0.3162
115 
116 typedef struct AxisStruct {
117   char      label[256];
118   float     min_value;
119   float     max_value;
120   float     length;
121   float     numticks;
122 } AxisType;
123 
124 typedef struct CoordFrame {
125   char      title[256];
126   float     titlepos;
127   AxisType  xaxis;
128   AxisType  yaxis;
129   float     xborder_size;
130   float     yborder_size;
131 } CoordType;
132 
133 typedef struct LightStruct {
134   GLenum  Light;                   /* Which light                       */
135   GLfloat Pos[4];                  /* position of the light source      */
136   GLfloat Direction[3];            /* direction vector of the spot      */
137   GLfloat Diffuse;
138   GLfloat Specular;
139   GLfloat Const_Att;
140   GLfloat Lin_Att;
141   GLfloat Quad_Att;
142 } LightType;
143 
144 /* texture information */
145 typedef struct TextureStruct {
146   int       IsOn;                  /* we want texturing (ON/OFF)        */
147   int       Type;                  /* What kind of texture              */
148   char      TextFile[1024+MAX_CFG_INLINE+1]; /* texture image file                */
149   GLint     Width;                 /* width of the image                */
150   GLint     Height;                /* height of the image               */
151   GLint     Components;            /* depth of image                    */
152   GLuint    TexName;               /* texture name                      */
153 } TextureType;
154 
155 extern struct GLColorSystem {
156   /* We give only X and Y values here, because the Z values are implicitly    */
157   /* given by the relations Zn = 1.0 - (Xn + Yn), where n = r,g,b             */
158   double xr,yr,
159          xg,yg,
160          xb,yb,
161          xw,yw;
162 } Temp;
163 
164 /* display information */
165 typedef struct {
166   float mousex,mousey;  /* position of mouse             */
167   float quat[4];        /* orientation of object         */
168   float zoom;           /* field of view in degrees      */
169   float xpos;           /* x position of the observer    */
170 } DispInfo;
171 
172 /* 3D  animation                                     */
173 void AnimateGL( int j );
174 
175 /* Init 3D model                                     */
176 gint GLInit3d( GtkWidget *widget );
177 gint GLLightPlot(GtkWidget *widget );
178 
179 /* Init lighting                                     */
180 void GLInitLighting( GtkWidget *widget );
181 
182 /* color stuff for GL                                */
183 void GLBBtoXYZ(double temperature, double *X, double *Y,double *Z);
184 void GLXYZtoRGB(double *X, double *Y,double *Z, double *R, double *G, double *B);
185 
186 /* Init spots on components                          */
187 void GLMakeSpots( int Comp, float xpos );
188 
189 /* Update all graphic viewports                      */
190 void GLUpdateAll( void );
191 /* Update the primary/secondary geometry             */
192 void GLUpdate3d( GtkWidget *widget );
193 /* Update plot viewport                              */
194 void GLUpdatePlot( int viewport, int type );
195 
196 /* Button event                                      */
197 gint GLButtonPress(GtkWidget *widget, GdkEventButton *event);
198 
199 /* Motion event                                      */
200 gint GLMotionNotify(GtkWidget *widget, GdkEventMotion *event);
201 
202 /* Reshape for GL code                               */
203 gint GLReshape( GtkWidget *widget, GdkEventConfigure *event );
204 
205 /* Display function for GL mode                      */
206 void GLDisplayAll( void );
207 void GLDisplay3d( GtkWidget *widget );
208 void GLDisplayPlot( GtkWidget *widget, int type);
209 void GLDisplayWedge( int Comp );
210 
211 void GLMakeLCPlot( void );
212 void GLMakeRVPlot( void );
213 
214 /* Display list for the components                   */
215 void GLMakeVolumeEclipsed( int Comp );
216 
217 /* Keybord related function for GL mode              */
218 gint GLKeyboard(GtkWidget *widget, GdkEventKey *event);
219 
220 /* Set default values for coordinate system          */
221 CoordType SetupCoords(float ymin, float ymax,char *xlabel, char *ylabel, char *title);
222 /* Draw x-, y-, z-Axes                               */
223 void GLDrawAxes(GLfloat length, GtkWidget *widget);
224 /* Draw x- and y-Axes for plotting light curve       */
225 void GLMake2DAxes(CoordType CoordPara, GtkWidget *widget);
226 /* Draw some labels                                  */
227 void GLDrawLabels(GtkWidget *widget);
228 
229 /* GL sting plotting functions                       */
230 void GLSetFont(int style, int size);
231 void GLDrawStr(GLfloat x, GLfloat y, GLfloat z, char* format, ...);
232 void GLDrawStrRightAdj(GLfloat x, GLfloat y, GLfloat z, char* format, ...);
233 
234 /* Texturing stuff                                   */
235 int GLInitTextureParams(int Comp);
236 int GLInitTexture(int Comp, int type);
237 double GLbbflux(double lambda, double temp);
238 void GLBBtoxyz(double temperature, double *x, double *y,double *z);
239 void GLxyztoRGB(struct GLColorSystem *csyst, double x, double y,double z,
240 		double *R, double *G, double *B);
241 
242 
243 /* libjpeg suff                                      */
244 GLubyte *ReadJPEGFile(char *filename, int *width, int *height, int *components);
245 int WriteJPEGFile(JSAMPLE *imgbuff, char *filename, int imgwidth, int imgheight, int components, int quality);
246 int GLGrabScreen(char *filename, int x0, int y0, int width, int height, int quality);
247 
248 /* Gtk Menu for GL window                            */
249 void GLMakeMenu(GtkWidget *glmenu_bar);
250 void GLAnimationEvent (GtkWidget *widget, gpointer *data);
251 
252 /* Preferences window                                       */
253 extern GtkWidget   *glPrefsWindow;
254 extern GtkWidget   *glArea,*glWindow;
255 
256 /* OpenGL window opened                    */
257 extern int GLWindowOpened;
258 /* OpenGL window hidden                    */
259 extern int GLWindowHidden;
260 /* OpenGL preferences window opened        */
261 extern int GLPrefWinOpened;
262 
263 extern GLdouble a;
264 
265 /*  Display lists                                    */
266 extern GLint thePrimary, theSecondary, theDisk;
267 
268 /* Display contexts                                  */
269 extern GtkWidget  *glArea,*glPlot,*glVelo,*glWindow;
270 
271 /* Color definitions for primary component           */
272 extern GLfloat primary_colour[4];
273 extern GLfloat primary_mat_specular[4];
274 extern GLfloat primary_mat_diffuse[4];
275 extern GLfloat primary_mat_shininess[1];
276 
277 /* Color definitions for secondary component        */
278 extern GLfloat secondary_colour[4];
279 extern GLfloat secondary_mat_specular[4];
280 extern GLfloat secondary_mat_diffuse[4];
281 extern GLfloat secondary_mat_shininess[4];
282 
283 /* color and emission properties of the disk        */
284 /* disk                                             */
285 extern GLfloat disk_colour[4];
286 extern GLfloat disk_mat_specular[4];
287 extern GLfloat disk_mat_diffuse[4];
288 extern GLfloat disk_mat_shininess[1];
289 
290 extern GLfloat bulge_light[4];
291 extern GLfloat bgd_colour[4];
292 
293 /* Display lists                                     */
294 extern GLint PrimaryList, SecondaryList, DiskList, PlotList[2];
295 
296 /* Texture definitions                               */
297 extern TextureType Texture[3];
298 extern LightType Lights[MAX_LIGHT_NUM];
299 
300 extern int phaseind;
301 
302 /* Paramters for the coordinate systems              */
303 extern CoordType CoordSys[2];
304 
305 extern double RtoL2,RtoL3;
306 
307 #endif
308 
309 
310 
311 
312 
313 
314 
315