]> git.mxchange.org Git - flightgear.git/blob - Cockpit/panel.cxx
Converted to new logstream debugging facility. This allows release
[flightgear.git] / Cockpit / panel.cxx
1 /**************************************************************************
2  * panel.cxx -- routines to draw an instrument panel
3  *
4  * Written by Friedemann Reinhard, started June 1998.
5  *
6  * Copyright(C)1998 Friedemann Reinhard-reinhard@theorie2.physik.uni-erlangen.de
7  *
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.
12  *
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.
17  *
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.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #ifdef HAVE_WINDOWS_H          
32 #  include <windows.h>
33 #endif
34
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <string>
42 #include <math.h>
43
44 #include <Aircraft/aircraft.hxx>
45 #include <Main/options.hxx>
46 #include <Main/views.hxx>
47
48 #include "panel.hxx"
49 #include "cockpit.hxx"
50 #include "hud.hxx"
51
52 #define IMAGIC      0x01da
53 #define IMAGIC_SWAP 0xda01
54
55 #define SWAP_SHORT_BYTES(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
56 #define SWAP_LONG_BYTES(x) (((((x) & 0xff) << 24) | (((x) & 0xff00) << 8)) | \
57 ((((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24)))
58
59 typedef struct {
60     unsigned short imagic;
61     unsigned short type;
62     unsigned short dim;
63     unsigned short sizeX, sizeY, sizeZ;
64     unsigned long min, max;
65     unsigned long wasteBytes;
66     char name[80];
67     unsigned long colorMap;
68     FILE *file;
69     unsigned char *tmp[5];
70     unsigned long rleEnd;
71     unsigned long *rowStart;
72     unsigned long *rowSize;
73 } Image;
74
75
76 IMAGE *imag;
77 IMAGE *img2;
78 IMAGE *img;
79
80 static GLuint panel_list;
81 static GLuint panel_tex_id;
82 static GLubyte tex[32][128][3];
83 static GLint stencil[1024][768];
84 static float alphahist;
85 static float Xzoom, Yzoom;
86 // static GLint viewport[4];
87 // static GLdouble mvmatrix[16], projmatrix[16];
88 static Pointer pointer[20];
89 static float NumPoint = 4;
90 static double var[20];
91 static double offset;
92 static float alpha;
93
94 /* image.c THIS FILE WAS COPIED FROM THE MESA GRAPHICS LIBRARY */
95
96
97 static Image *ImageOpen(char *fileName)
98 {
99   Image *image;
100   unsigned long *rowStart, *rowSize, ulTmp;
101   int x, i;
102
103   image = (Image *)malloc(sizeof(Image));
104   if (image == NULL) 
105     {
106       fprintf(stderr, "Out of memory!\n");
107       exit(-1);
108     }
109   if ((image->file = fopen(fileName, "rb")) == NULL) 
110     {
111       perror(fileName);
112       exit(-1);
113     }
114   /*
115    *    Read the image header
116    */
117   fread(image, 1, 12, image->file);
118   /*
119    *    Check byte order
120    */
121   if (image->imagic == IMAGIC_SWAP) 
122     {
123       image->type = SWAP_SHORT_BYTES(image->type);
124       image->dim = SWAP_SHORT_BYTES(image->dim);
125       image->sizeX = SWAP_SHORT_BYTES(image->sizeX);
126       image->sizeY = SWAP_SHORT_BYTES(image->sizeY);
127       image->sizeZ = SWAP_SHORT_BYTES(image->sizeZ);
128     }
129
130   for ( i = 0 ; i <= image->sizeZ ; i++ )
131     {
132       image->tmp[i] = (unsigned char *)malloc(image->sizeX*256);
133       if (image->tmp[i] == NULL ) 
134         {
135           fprintf(stderr, "Out of memory!\n");
136           exit(-1);
137         }
138     }
139
140   if ((image->type & 0xFF00) == 0x0100) /* RLE image */
141     {
142       x = image->sizeY * image->sizeZ * sizeof(long);
143       image->rowStart = (unsigned long *)malloc(x);
144       image->rowSize = (unsigned long *)malloc(x);
145       if (image->rowStart == NULL || image->rowSize == NULL) 
146         {
147           fprintf(stderr, "Out of memory!\n");
148           exit(-1);
149         }
150       image->rleEnd = 512 + (2 * x);
151       fseek(image->file, 512, SEEK_SET);
152       fread(image->rowStart, 1, x, image->file);
153       fread(image->rowSize, 1, x, image->file);
154       if (image->imagic == IMAGIC_SWAP) 
155         {
156           x /= sizeof(long);
157           rowStart = image->rowStart;
158           rowSize = image->rowSize;
159           while (x--) 
160             {
161               ulTmp = *rowStart;
162               *rowStart++ = SWAP_LONG_BYTES(ulTmp);
163               ulTmp = *rowSize;
164               *rowSize++ = SWAP_LONG_BYTES(ulTmp);
165             }
166         }
167     }
168   return image;
169 }
170
171 static void ImageClose( Image *image)
172 {
173   int i;
174
175   fclose(image->file);
176   for ( i = 0 ; i <= image->sizeZ ; i++ )
177     free(image->tmp[i]);
178   free(image);
179 }
180
181 static void ImageGetRow( Image *image, unsigned char *buf, int y, int z)
182 {
183   unsigned char *iPtr, *oPtr, pixel;
184   int count;
185
186   if ((image->type & 0xFF00) == 0x0100)  /* RLE image */
187     {
188       fseek(image->file, image->rowStart[y+z*image->sizeY], SEEK_SET);
189       fread(image->tmp[0], 1, (unsigned int)image->rowSize[y+z*image->sizeY],
190             image->file);
191
192       iPtr = image->tmp[0];
193       oPtr = buf;
194       while (1) 
195         {
196           pixel = *iPtr++;
197           count = (int)(pixel & 0x7F);
198           if (!count)
199             return;
200           if (pixel & 0x80) 
201             {
202               while (count--) 
203                 {
204                   *oPtr++ = *iPtr++;
205                 }
206             } 
207           else 
208             {
209               pixel = *iPtr++;
210               while (count--) 
211                 {
212                   *oPtr++ = pixel;
213                 }
214             }
215         }
216     }
217   else /* verbatim image */
218     {
219       fseek(image->file, 512+(y*image->sizeX)+(z*image->sizeX*image->sizeY),
220             SEEK_SET);
221       fread(buf, 1, image->sizeX, image->file);
222     }
223 }
224
225 static void ImageGetRawData( Image *image, char *data)
226 {
227   int i, j, k;
228   int remain;
229
230   switch ( image->sizeZ )
231     {
232     case 1:
233       remain = image->sizeX % 4;
234       break;
235     case 2:
236       remain = image->sizeX % 2;
237       break;
238     case 3:
239       remain = (image->sizeX * 3) & 0x3;
240       if (remain)
241         remain = 4 - remain;
242       break;
243     case 4:
244       remain = 0;
245       break;
246     }
247
248   for (i = 0; i < image->sizeY; i++) 
249     {
250       for ( k = 0; k < image->sizeZ ; k++ )
251         ImageGetRow(image, image->tmp[k+1], i, k);
252       for (j = 0; j < image->sizeX; j++) 
253         for ( k = 1; k <= image->sizeZ ; k++ )
254           *data++ = *(image->tmp[k] + j);
255       data += remain;
256     }
257 }
258
259 static IMAGE *ImageLoad(char *fileName)
260 {
261   Image *image;
262   IMAGE *final;
263   int sx;
264
265   image = ImageOpen(fileName);
266
267   final = (IMAGE *)malloc(sizeof(IMAGE));
268   if (final == NULL) 
269     {
270       fprintf(stderr, "Out of memory!\n");
271       exit(-1);
272     }
273   final->imagic = image->imagic;
274   final->type = image->type;
275   final->dim = image->dim;
276   final->sizeX = image->sizeX; 
277   final->sizeY = image->sizeY;
278   final->sizeZ = image->sizeZ;
279
280   /* 
281    * Round up so rows are long-word aligned 
282    */
283   sx = ( (image->sizeX) * (image->sizeZ) + 3) >> 2;
284
285   final->data 
286     = (unsigned char *)malloc( sx * image->sizeY * sizeof(unsigned int));
287
288   if (final->data == NULL) 
289     {
290       fprintf(stderr, "Out of memory!\n");
291       exit(-1);
292     }
293
294   ImageGetRawData(image, final->data);
295   ImageClose(image);
296   return final;
297 }
298
299 /* Beginning of the "panel-code" */
300 void fgPanelInit ( void ) {
301     fgVIEW *v;
302     string tpath;
303     // char *root;
304     int x, y, i;
305
306     v = &current_view;
307
308     Xzoom = (float)((float)(current_view.winWidth)/1024);
309     Yzoom = (float)((float)(current_view.winHeight)/768);
310
311 pointer[1].XPos = 352;
312 pointer[1].YPos = 156;
313 pointer[1].radius = 4;
314 pointer[1].length = 32;
315 pointer[1].width = 3;
316 pointer[1].angle = 30;
317 pointer[1].value1 = 0;
318 pointer[1].value2 = 3000;
319 pointer[1].alpha1 = 0;
320 pointer[1].alpha2 = 1080;
321 pointer[1].variable = 1;
322 pointer[1].teXpos = 59;
323 pointer[1].texYpos = 199;
324
325 pointer[0].XPos = 352;
326 pointer[0].YPos = 156;
327 pointer[0].radius = 4;
328 pointer[0].length = 25;
329 pointer[0].width = 4;
330 pointer[0].angle = 30;
331 pointer[0].value1 = 0;
332 pointer[0].value2 = 10000;
333 pointer[0].alpha1 = 0;
334 pointer[0].alpha2 = 360;
335 pointer[0].variable = 1;
336 pointer[0].teXpos = 59;
337 pointer[0].texYpos = 199;
338
339 pointer[2].XPos = 352;
340 pointer[2].YPos = 48;
341 pointer[2].radius = 4;
342 pointer[2].length = 30;
343 pointer[2].width = 3;
344 pointer[2].angle = 30;
345 pointer[2].value1 = -3;
346 pointer[2].value2 = 3;
347 pointer[2].alpha1 = 100;
348 pointer[2].alpha2 = 440;
349 pointer[2].variable = 2;
350 pointer[2].teXpos = 63;
351 pointer[2].texYpos = 68;
352
353
354 pointer[3].XPos = 451;
355 pointer[3].YPos = 125;
356 pointer[3].radius = 9;
357 pointer[3].length = 20;
358 pointer[3].width = 5;
359 pointer[3].angle = 50;
360 pointer[3].value1 = 0.0;
361 pointer[3].value2 = 1.0;
362 pointer[3].alpha1 = 280;
363 pointer[3].alpha2 = 540;
364 pointer[3].variable = 3;
365 pointer[3].teXpos = 162;
366 pointer[3].texYpos = 40;
367
368 for(i=0;i<NumPoint;i++){
369 CreatePointer(&pointer[i]);
370 }
371 #ifdef GL_VERSION_1_1
372     xglGenTextures(1, &panel_tex_id);
373     xglBindTexture(GL_TEXTURE_2D, panel_tex_id);
374 #elif GL_EXT_texture_object
375     xglGenTexturesEXT(1, &panel_tex_id);
376     xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id);
377 #else
378 #  error port me
379 #endif
380     xglMatrixMode(GL_PROJECTION);
381     xglPushMatrix();
382     xglLoadIdentity();
383     xglViewport(0, 0, 640, 480);
384     gluOrtho2D(0, 640, 0, 480);
385     xglMatrixMode(GL_MODELVIEW);
386     xglPushMatrix();
387     xglLoadIdentity();
388     xglClearStencil(0x0);
389     xglClear(GL_STENCIL_BUFFER_BIT);
390     xglEnable(GL_STENCIL_TEST);
391     //xglPixelStorei(GL_UNPACK_ROW_LENGTH, 32);
392     xglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
393     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
394     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   
395     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
396     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
397
398     /* load in the texture data */
399     // current_options.get_fg_root(root);
400     // tpath[0] = '\0';
401     // strcat(tpath, "/home/fried/Flugsim/FlightGear-0.52");
402     // strcat(tpath, "/Textures/");
403     // strcat(tpath, "arthor.rgb");
404
405  //   if ( (imag = ImageLoad(tpath)) == NULL ){
406  //     fgPrintf( FG_COCKPIT, FG_ALERT, 
407                  // "Error loading cockpit texture %s\n", tpath );
408     //  exit(-1);
409    // }
410     
411     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
412     // tpath[0] = '\0';
413     // strcat(tpath, "/home/fried/Flugsim/FlightGear-0.52");
414     tpath = current_options.get_fg_root() + "/Textures/gauges.rgb";
415     if((img = ImageLoad( (char *)tpath.c_str() ))==NULL){
416     }
417
418     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
419
420     // tpath[0] = '\0';
421     // strcat(tpath,"/home/fried/Flugsim/FlightGear-0.52" );
422     tpath = current_options.get_fg_root() + "/Textures/Fullone.rgb";
423     
424     if ((img2 = ImageLoad( (char *)tpath.c_str() ))==NULL ){
425         }
426
427 for ( y = 0; y < 768; y++ ) {
428         for ( x = 0; x < 1024; x++ ) { 
429             if ( (img2->data[(y+x*768)*3] == 0) && (img2->data[(y+x*768)*3+1] == 0) && (img2->data[(y+x*768)*3+2] == 0) ) {
430                 stencil[x][y]=0x0;//0x0
431             } else {
432                 stencil[x][y]=0x1;//0x1
433             }
434         }
435     }
436     xglPixelZoom(Xzoom, Yzoom);
437     xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
438     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
439     xglStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
440     xglRasterPos2i(0,0);
441     xglDrawPixels(1024, 768, GL_STENCIL_INDEX, GL_UNSIGNED_INT, (GLvoid *)(stencil));
442     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
443     xglStencilFunc(GL_EQUAL, 0x1, 0x1);//0x1..
444     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
445     xglRasterPos2i(0,0);
446     xglPixelZoom(Xzoom, Yzoom);
447    // xglDrawPixels(1024, 768, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)(img2->data));
448     xglStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
449     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
450     xglEnable(GL_STENCIL_TEST);
451     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
452     xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, 
453                   GL_UNSIGNED_BYTE, (GLvoid *)(img->data));
454 // #ifdef GL_VERSION_1_1
455    //  xglBindTexture(GL_TEXTURE_2D, panel_tex_id[1]);
456 // #elif GL_EXT_texture_object 
457    //  xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[1]);
458 // #else
459 // # error port me
460 // #endif
461    //  xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
462    //  xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)(img->data));
463     xglMatrixMode(GL_MODELVIEW);
464     xglPopMatrix();
465 }
466
467 void fgPanelReInit( void){
468     fgVIEW *v;
469     fgOPTIONS *o;
470     int x, y, i;
471     
472     o = &current_options;
473     v = &current_view;
474     
475     Xzoom = (float)((float)(current_view.winWidth)/1024);
476     Yzoom = (float)((float)(current_view.winHeight)/768);
477     
478     xglMatrixMode(GL_PROJECTION);
479     xglPushMatrix();
480     xglLoadIdentity();
481     xglViewport(0, 0, 640, 480);
482     gluOrtho2D(0, 640, 0, 480);
483     xglMatrixMode(GL_MODELVIEW);
484     xglPushMatrix();
485     xglLoadIdentity();
486     xglClearStencil(0x0);
487     xglClear(GL_STENCIL_BUFFER_BIT);
488     xglEnable(GL_STENCIL_TEST);
489     xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
490     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
491     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   
492     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
493     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
494
495     xglPixelZoom(Xzoom, Yzoom);
496     xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
497     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
498     xglStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
499     xglRasterPos2i(0,0);
500     xglDrawPixels(1024, 768, GL_STENCIL_INDEX, GL_UNSIGNED_INT, (GLvoid *)(stencil));
501     xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
502     xglStencilFunc(GL_EQUAL, 0x1, 0x1);//0x1..
503     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
504     xglRasterPos2i(0,0);
505     xglPixelZoom(Xzoom, Yzoom);
506     xglDrawPixels(1024, 768, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)(img2->data));
507     xglStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
508     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
509     xglEnable(GL_STENCIL_TEST);
510 }
511
512 void fgPanelUpdate ( void ) {
513     fgVIEW *v;
514     float alpha;
515     double pitch;
516     double roll;
517     float alpharad;
518     double speed;
519     int i;
520     var[0] = get_speed();
521     var[1] = get_altitude();
522     var[2] = get_aoa(); // A placeholder. It should be the vertical speed once. 
523     var[3] = get_throttleval();
524     v = &current_view;
525     xglMatrixMode(GL_PROJECTION);
526     xglPushMatrix();
527     xglLoadIdentity();
528     gluOrtho2D(0, 640, 0, 480);
529     xglMatrixMode(GL_MODELVIEW);
530     xglPushMatrix();
531     xglLoadIdentity();
532     xglDisable(GL_DEPTH_TEST);
533     xglDisable(GL_LIGHTING);
534     xglStencilFunc(GL_EQUAL, 0x1, 0x1);
535     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
536     // xglEnable(GL_STENCIL_TEST);
537         xglEnable(GL_TEXTURE_2D);
538 #ifdef GL_VERSION_1_1
539     xglBindTexture(GL_TEXTURE_2D, panel_tex_id);
540 #elif GL_EXT_texture_object
541     xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id);
542 #else
543 #  error port me
544 #endif
545     xglMatrixMode(GL_MODELVIEW);
546     xglPopMatrix();
547     xglPushMatrix();
548     for(i=0;i<NumPoint;i++){
549     xglLoadIdentity();
550     xglTranslatef(pointer[i].XPos, pointer[i].YPos, 0.0);
551     xglRotatef(-pointer[i].hist, 0.0, 0.0, 1.0);
552     ErasePointer(pointer[i]);
553     xglLoadIdentity();
554     }
555     for(i=0;i<NumPoint;i++){
556     pointer[i].hist = UpdatePointer( pointer[i]);
557     xglPopMatrix();
558     xglPushMatrix();
559     }
560     xglDisable(GL_TEXTURE_2D);
561     xglPopMatrix();   
562     xglRasterPos2i(0, 0);
563   //  horizont();  //Let's do this, when Michael's horizont image is ready
564     xglEnable(GL_DEPTH_TEST);
565     xglEnable(GL_STENCIL_TEST);
566     xglStencilFunc(GL_NOTEQUAL, 0x1, 0x1);//1 1
567     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
568     xglEnable(GL_LIGHTING);
569     xglDisable(GL_TEXTURE_2D);
570     xglDisable(GL_BLEND);
571     xglDisable(GL_ALPHA_TEST);
572     xglMatrixMode(GL_PROJECTION);
573     xglPopMatrix();
574     xglMatrixMode(GL_MODELVIEW);
575     xglPopMatrix();
576 }
577
578 void horizont(void){ 
579     double pitch;
580     double roll;
581     pitch = get_pitch() * RAD_TO_DEG;
582     roll = get_roll() * RAD_TO_DEG;
583     xglEnable(GL_TEXTURE_2D);
584     xglMatrixMode(GL_MODELVIEW);
585     xglLoadIdentity();
586    xglDisable(GL_STENCIL_TEST);
587     xglStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
588     xglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
589     xglTranslatef(200, 130, 0);
590     xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);    
591     #ifdef GL_VERSION_1_1
592     xglBindTexture(GL_TEXTURE_2D, panel_tex_id);
593     #elif GL_EXT_texture_object
594     xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id);
595     #else
596     #  error port me
597     #endif
598     xglMatrixMode(GL_TEXTURE);
599     xglLoadIdentity();
600     //xglTranslatef(0.0, 0.33, 0.0);
601     xglScalef(0.5, 0.5, 0.0);
602     xglTranslatef(0.0, (pitch / 45), 0.0);
603     xglTranslatef(1.0, 1.0, 0.0);
604     xglRotatef(-roll, 0.0, 0.0, 1.0);
605     xglTranslatef(-0.5, -0.5, 0.0);
606     xglBegin(GL_POLYGON);
607     xglTexCoord2f(0.0, 0.1); xglVertex2f(0.0, 0.0);
608     xglTexCoord2f(1.0, 0.1); xglVertex2f(70.0, 0.0);
609     xglTexCoord2f(1.0, 0.9); xglVertex2f(70.0, 70.0);
610     xglTexCoord2f(0.0, 0.9); xglVertex2f(0.0, 70.0);
611     xglEnd();
612     xglPopMatrix();
613     xglMatrixMode(GL_PROJECTION);
614     xglPopMatrix();
615     xglDisable(GL_TEXTURE_2D);
616     xglEnable(GL_STENCIL_TEST);
617     }
618
619 float UpdatePointer(Pointer pointer){
620     double pitch;
621     double roll;
622     float alpharad;
623     double speed;    
624     glEnableClientState(GL_VERTEX_ARRAY);
625     glVertexPointer(2, GL_FLOAT, 0, pointer.vertices);
626     alpha=((((float)((var[pointer.variable]) - (pointer.value1)))/(pointer.value2 - pointer.value1))*(pointer.alpha2 - pointer.alpha1) + pointer.alpha1);
627         if (alpha < pointer.alpha1)
628                 alpha = pointer.alpha1;
629         if (alpha > pointer.alpha2)
630                 alpha = pointer.alpha2;
631     xglMatrixMode(GL_MODELVIEW);  
632     xglPushMatrix();
633     xglLoadIdentity();
634     xglDisable(GL_TEXTURE_2D);
635     xglTranslatef(pointer.XPos, pointer.YPos, 0);
636     xglRotatef(-alpha, 0.0, 0.0, 1.0);
637     xglColor4f(1.0, 1.0, 1.0, 1.0);
638     glDrawArrays(GL_POLYGON, 0, 10);
639     return alpha;
640     xglEnable(GL_TEXTURE_2D);
641     glDisableClientState(GL_VERTEX_ARRAY);
642 }
643
644 void ErasePointer(Pointer pointer){
645 int i, j;
646 float a;
647 float ififth;
648
649 xglEnable(GL_TEXTURE_2D);
650 xglEnable(GL_TEXTURE_GEN_S);
651 xglEnable(GL_TEXTURE_GEN_T);
652 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
653 //glTexGenfv(GL_S, GL_EYE_PLANE, currentCoeff);
654 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
655 //glTexGenfv(GL_T, GL_EYE_PLANE, currentCoeff);
656 xglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
657 xglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
658 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
659 xglMatrixMode(GL_TEXTURE);
660 xglLoadIdentity();
661     
662     #ifdef GL_VERSION_1_1
663     xglBindTexture(GL_TEXTURE_2D, panel_tex_id);
664     #elif GL_EXT_texture_object
665     xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id);
666     #else
667     #  error port me
668     #endif
669
670 xglMatrixMode(GL_TEXTURE);
671 xglLoadIdentity();
672 xglTranslatef(-((float)(((float)(pointer.XPos)/0.625)/256)) /* - 0.057143*/, -((float)(((float)(pointer.YPos)/0.625)/256)), 0.0);
673 xglTranslatef(pointer.teXpos/256 , pointer.texYpos/256, 0.0);
674 xglScalef(0.00625, 0.00625, 1.0);
675 //xglTranslatef(-pointer.teXpos , -pointer.texYpos, 0.0);
676         
677         xglBegin(GL_POLYGON);
678 xglVertex2f(pointer.vertices[0], pointer.vertices[1]);
679 xglVertex2f(pointer.vertices[2], pointer.vertices[3]);
680 xglVertex2f(pointer.vertices[4], pointer.vertices[5]);
681 xglVertex2f(pointer.vertices[16], pointer.vertices[17]);
682 xglVertex2f(pointer.vertices[18], pointer.vertices[19]); 
683         xglEnd();
684  
685         xglLoadIdentity();
686         xglMatrixMode(GL_MODELVIEW);
687         xglPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
688         xglPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
689         xglDisable(GL_TEXTURE_2D);
690         xglDisable(GL_TEXTURE_GEN_S);
691         xglDisable(GL_TEXTURE_GEN_T);
692         
693 }
694
695 void CreatePointer(Pointer *pointer){
696 int i;
697 float alpha;
698 float alphastep;
699 float r = pointer->radius;
700 float angle = pointer->angle;
701 float length = pointer->length;
702 float width = pointer->width;
703
704 pointer->vertices[0] = 0;
705 pointer->vertices[1] = length;
706 pointer->vertices[2] = -(width/2);
707 pointer->vertices[3] = length - ((width/2)/(tan(angle*DEG_TO_RAD/2)));
708 pointer->vertices[4] = -(width/2);
709 pointer->vertices[5] = cos(asin((width/2)/r))*r;
710 alphastep = (asin((width/2)/r)+asin((width/2)/r))/5;
711 alpha = asin(-(width/2)/r);
712 for(i=0;i<5;i++){
713 alpha += alphastep;
714 pointer->vertices[(i*2)+6] = sin(alpha)*r;
715 }
716 alpha = asin(-(width/2)/r);
717 for(i=0;i<5;i++){
718 alpha +=alphastep;
719 pointer->vertices[(i*2)+7]= cos(alpha)*r;
720 }
721 pointer->vertices[16] = - pointer->vertices[4];
722 pointer->vertices[17] = pointer->vertices[5];
723 pointer->vertices[18] = - pointer->vertices[2];
724 pointer->vertices[19] = pointer->vertices[3];
725 }
726
727
728 /* $Log$
729 /* Revision 1.9  1998/11/06 21:18:01  curt
730 /* Converted to new logstream debugging facility.  This allows release
731 /* builds with no messages at all (and no performance impact) by using
732 /* the -DFG_NDEBUG flag.
733 /*
734 /* Revision 1.8  1998/10/16 23:27:37  curt
735 /* C++-ifying.
736 /*
737  * Revision 1.7  1998/08/31 20:45:31  curt
738  * Tweaks from Friedemann.
739  *
740  * Revision 1.6  1998/08/28 18:14:40  curt
741  * Added new cockpit code from Friedemann Reinhard
742  * <mpt218@faupt212.physik.uni-erlangen.de>
743  *
744  * Revision 1.1  1998/06/27 16:47:54  curt
745  * Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
746  * first pass at an isntrument panel.
747  *
748  */