1 // panel.cxx -- routines to draw an instrument panel
3 // Written by Friedemann Reinhard, started June 1998.
5 // Copyright(C)1998 Friedemann Reinhard-reinhard@theorie2.physik.uni-erlangen.de
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
43 #include <Debug/logstream.hxx>
44 #include <Aircraft/aircraft.hxx>
45 #include <Main/options.hxx>
46 #include <Main/views.hxx>
47 #include <Objects/texload.h>
50 #include "cockpit.hxx"
54 int imag_width, imag_height;
57 int img_width, img_height;
59 static float value[4];
60 static GLuint panel_tex_id[2];
61 static GLubyte tex[32][128][3];
62 static float alphahist;
63 static float Xzoom, Yzoom;
64 static Pointer pointer[20];
65 static int NumPoint = 4;
67 static GLdouble mvmatrix[16];
68 static GLdouble matrix[16];
69 static double var[20];
75 static GLfloat Wings[] = {-1.25, -28.125, 1.255, -28.125, 1.255, 28.125, -1.25, 28.125};
76 static GLfloat Elevator[] = { 3.0, -10.9375, 4.5, -10.9375, 4.5, 10.9375, 3.0, 10.9375};
77 static GLfloat Rudder[] = {2.0, -0.45, 10.625, -0.45, 10.625, 0.55, 2.0, 0.55};
79 FGPanel* FGPanel::OurPanel = 0;
81 // FGPanel::FGPanel() - constructor to initialize the panel.
82 FGPanel::FGPanel(void){
93 Xzoom = (float)((float)(current_view.get_winWidth())/1024);
94 Yzoom = (float)((float)(current_view.get_winHeight())/768);
96 test_instr[3] = new FGTexInstrument(144.375, 166.875, 4, 32, 3, 30, 15.0, 260.0, -20.0, 360, 65, 193, 0);
97 test_instr[4] = new FGTexInstrument(358, 52, 4, 30, 3, 30, -3.0, 3.0, 100, 440, 66.15, 66, 2);
98 test_instr[5] = new FGTexInstrument(357.5, 167, 5, 25, 4, 30, 0, 10000, 0, 360, 194, 191, 1);
99 test_instr[6] = new FGTexInstrument(357.5, 167, 5, 32, 3, 30, 0, 3000, 0, 1080, 194, 191, 1);
100 test_instr[0] = new FGHorizon(251, 166.75);
101 test_instr[1] = new FGTurnCoordinator(143.75, 51.75);
102 //test_instr[2] = new FGRpmGauge(462.5, 133);
103 test_instr[2] = new FGTexInstrument(462.5, 133, 10, 20, 5.5, 60, 0.0, 1.0, -67, 180, 174, 83, 3);
105 // FontList = glGenLists (256);
106 // glListBase(FontList);
109 #ifdef GL_VERSION_1_1
110 xglGenTextures(2, panel_tex_id);
111 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[1]);
112 #elif GL_EXT_texture_object
113 xglGenTexturesEXT(2, panel_tex_id);
114 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[1]);
119 xglMatrixMode(GL_PROJECTION);
122 xglViewport(0, 0, 640, 480);
123 xglOrtho(0, 640, 0, 480, 1, -1);
124 xglMatrixMode(GL_MODELVIEW);
127 xglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
128 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
129 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
130 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
131 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
133 // load in the texture data
135 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
136 tpath = current_options.get_fg_root() + "/Textures/gauges.rgb";
137 if((img = read_rgb_texture( (char *)tpath.c_str(), &img_width, &img_height ))==NULL){
140 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
141 tpath = current_options.get_fg_root() + "/Textures/gauges2.rgb";
142 if((imag = read_rgb_texture( (char *)tpath.c_str(), &imag_width, &imag_height ))==NULL){
145 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
147 tpath = current_options.get_fg_root() + "/Textures/Fullone.rgb";
148 if ((background = read_rgb_texture( (char *)tpath.c_str(), &width, &height ))==NULL ){
151 // for(y=0;y<256;y++){
152 // for(x=0;x<256;x++){
153 // tex[(y+x*256)*3] = imag[(y+x*256)*3];
154 // tex[(y+x*256)*3 + 1] = imag[(y+x*256)*3 + 1];
155 // tex[(y+x*256)*3 + 2] = imag[(y+x*256)*3 + 2];
156 // tex[(y+x*256)*3 + 3] = (imag[(y+x*256)*3 + 1] + imag[(y+x*256)*3 + 2] // + imag[(y+x*256)*3 + 0])/3;
158 // if((imag[(y+x*256)*3] < 150) && (imag[(y+x*256)*3 +1] < 150) && // (imag[(y+x*256)*3 + 2] < 150) ){
159 // tex[(y+x*256)*3 + 3] = 0x0;
162 // tex[(y+x*256)*3 + 3] = 0xff;
167 xglPixelZoom(Xzoom, Yzoom);
168 xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
169 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
170 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
172 xglPixelZoom(Xzoom, Yzoom);
173 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
174 xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, imag);
176 #ifdef GL_VERSION_1_1
177 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[0]);
178 #elif GL_EXT_texture_object
179 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[0]);
183 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
184 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
185 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
186 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
187 xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)(img));
189 xglMatrixMode(GL_MODELVIEW);
193 void FGPanel::ReInit( int x, int y, int finx, int finy){
198 o = ¤t_options;
200 xglDisable(GL_DEPTH_TEST);
202 Xzoom = (float)((float)(current_view.get_winWidth())/1024);
203 Yzoom = (float)((float)(current_view.get_winHeight())/768);
205 // save the current buffer state
206 xglGetIntegerv(GL_DRAW_BUFFER, &buffer);
208 // and enable both buffers for writing
209 xglDrawBuffer(GL_FRONT_AND_BACK);
211 xglMatrixMode(GL_PROJECTION);
214 xglViewport(0, 0, 640, 480);
215 xglOrtho(0, 640, 0, 480, 1, -1);
216 xglMatrixMode(GL_MODELVIEW);
219 xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
220 xglPixelZoom(Xzoom, Yzoom);
221 xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
222 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
223 xglPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
224 xglPixelStorei(GL_UNPACK_SKIP_ROWS, y);
225 xglRasterPos2i(x, y);
226 xglPixelZoom(Xzoom, Yzoom);
227 xglDrawPixels(finx - x, finy - y, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)(background));
229 // restore original buffer state
230 xglDrawBuffer( buffer );
231 xglEnable(GL_DEPTH_TEST);
234 void FGPanel::Update ( void ) {
243 // static bool beech_drawn = false;
244 // char *test = "ALM 100";
246 var[0] = get_speed() /* * 1.4 */; // We have to multiply the airspeed by a
247 // factor, to simulate flying a Bonanza
248 var[1] = get_altitude();
249 var[2] = get_climb_rate() / 1000.0;
250 var[3] = get_throttleval();
252 xglMatrixMode(GL_PROJECTION);
255 xglOrtho(0, 640, 0, 480, 10, -10);
256 xglMatrixMode(GL_MODELVIEW);
259 xglDisable(GL_DEPTH_TEST);
260 xglEnable(GL_LIGHTING);
261 xglEnable(GL_TEXTURE_2D);
262 xglDisable(GL_BLEND);
264 xglMatrixMode(GL_MODELVIEW);
268 xglDisable(GL_LIGHTING);
269 test_instr[3]->Render();
270 test_instr[4]->Render();
271 test_instr[5]->Render();
272 test_instr[6]->Render();
276 test_instr[1]->Render();
277 test_instr[2]->Render();
279 // DrawBeechcraftLogo(230, 235, 30, 10);
280 // DrawScale(144.375, 166.875, 38, 41.0, 18, 340, 44, 2.0, 1.0, 1.0, 1.0);
282 xglEnable(GL_LIGHTING);
284 test_instr[0]->Render();
287 xglDisable(GL_TEXTURE_2D);
289 xglEnable(GL_DEPTH_TEST);
290 xglEnable(GL_LIGHTING);
291 xglDisable(GL_TEXTURE_2D);
292 xglDisable(GL_BLEND);
293 xglMatrixMode(GL_PROJECTION);
295 xglMatrixMode(GL_MODELVIEW);
299 // horizon - Let's draw an artificial horizon using both texture mapping and
302 void FGHorizon::Render(void){
305 float shifted, alpha, theta;
306 float epsi = 360 / 180;
310 static int n, dn, rot, tmp1, tmp2;
313 GLfloat material[] = { 0.714844, 0.265625, 0.056875 ,1.0};
314 GLfloat material2[] = {0.6640625, 0.921875, 0.984375, 1.0};
315 GLfloat material3[] = {0.2, 0.2, 0.2, 1.0};
316 GLfloat material4[] = {0.8, 0.8, 0.8, 1.0};
317 GLfloat material5[] = {0.0, 0.0, 0.0, 1.0};
318 GLfloat direction[] = {0.0, 0.0, 0.0};
319 GLfloat light_position[4];
320 GLfloat light_ambient[] = {0.7, 0.7, 0.7, 1.0};
321 GLfloat light_ambient2[] = {0.7, 0.7, 0.7, 1.0};
322 GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
323 GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
325 pitch = get_pitch() * RAD_TO_DEG;
332 roll = get_roll() * RAD_TO_DEG;
334 xglEnable(GL_NORMALIZE);
335 xglEnable(GL_LIGHTING);
336 xglEnable(GL_TEXTURE_2D);
337 xglEnable(GL_LIGHT1);
338 xglDisable(GL_LIGHT2);
339 xglDisable(GL_LIGHT0);
340 xglMatrixMode(GL_MODELVIEW);
342 xglTranslatef(XPos, YPos, 0);
343 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
344 xglMatrixMode(GL_TEXTURE);
347 // computations for the non-textured parts of the AH
349 shifted = -((pitch / 10) * 7.0588235);
351 if(shifted > (bottom - radius)){
352 theta = (180 - (acos((bottom - shifted) / radius)*RAD_TO_DEG));
353 n = (int)(theta / epsi) - 1;
357 rot = (int)(roll / epsi);
362 if(shifted < (-top + radius)){
363 theta = ((acos((-top - shifted) / radius)*RAD_TO_DEG));
364 n = (int)(theta / epsi) + 1;
368 rot = (int)(roll / epsi);
371 if(n1 < 0){ n1 += 180; n2 +=180;}
374 // end of computations
376 light_position[0] = 0.0;
377 light_position[1] = 0.0;
378 light_position[2] = 1.5;
379 light_position[3] = 0.0;
380 xglLightfv(GL_LIGHT1, GL_POSITION, light_position);
381 xglLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
382 xglLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
383 xglLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
384 xglLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction);
386 #ifdef GL_VERSION_1_1
387 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[1]);
388 #elif GL_EXT_texture_object
389 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[1]);
395 xglTranslatef(0.0, ((pitch / 10) * 0.046875), 0.0);
396 xglTranslatef((texXPos/256), (texYPos/256), 0.0);
397 xglRotatef(-roll, 0.0, 0.0, 1.0);
398 xglScalef(1.7, 1.7, 0.0);
400 // the following loop draws the textured part of the AH
402 xglMaterialf(GL_FRONT, GL_SHININESS, 85.0);
404 xglMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material4);
405 xglMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material5);
406 xglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material3);
408 xglMatrixMode(GL_MODELVIEW);
409 xglBegin(GL_TRIANGLES);
411 xglTexCoord2f(0.0, 0.0);
412 xglNormal3f(0.0, 0.0, 0.6);
413 xglVertex3f(0.0, 0.0, 0.0);
414 xglTexCoord2f(texCoord[i % 180][0], texCoord[i % 180][1]);
415 xglNormal3f(normals[i % 180][0], normals[i % 180][1], 0.6);
416 xglVertex3f(vertices[i % 180][0], vertices[i % 180][1], 0.0);
418 xglTexCoord2f(texCoord[n][0], texCoord[n][1]);
419 xglNormal3f(normals[n][0], normals[n][1], 0.6);
420 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
425 if((shifted > (bottom - radius)) && (n1 < 1000) && (n1 > 0)){
427 a = sin(theta * DEG_TO_RAD) * sin(theta * DEG_TO_RAD);
428 light_ambient2[0] = a;
429 light_ambient2[1] = a;
430 light_ambient2[2] = a;
432 xglLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient2);
433 xglLightfv(GL_LIGHT1, GL_DIFFUSE, light_ambient2);
434 xglLightfv(GL_LIGHT1, GL_SPECULAR, light_ambient2);
436 xglBegin(GL_TRIANGLES);
438 tmp1 = n1; tmp2 = n2;
440 for(i = tmp1; i < tmp2 + 1; i++){
442 xglNormal3f(0.0, 0.0, 1.5);
443 xglTexCoord2f((56 / 256), (140 / 256));
444 xglVertex3f(((vertices[n1 % 180][0] + vertices[n2 % 180][0]) / 2), ((vertices[n1 % 180][1] + vertices[n2 % 180][1]) / 2), 0.0);
446 xglTexCoord2f((57 / 256), (139 / 256));
447 xglNormal3f(normals[n][0], normals[n][1], normals[n][3]);
448 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
451 xglTexCoord2f((57 / 256), (139 / 256));
452 xglNormal3f(normals[n][0], normals[n][1], normals[n][3]);
453 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
458 if((shifted < (-top + radius)) && (n1 < 1000) && (n1 > 0)){
459 a = sin(theta * DEG_TO_RAD) * sin(theta * DEG_TO_RAD);
460 light_ambient2[0] = a;
461 light_ambient2[1] = a;
462 light_ambient2[2] = a;
464 xglLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient2);
465 xglLightfv(GL_LIGHT1, GL_DIFFUSE, light_ambient2);
466 xglLightfv(GL_LIGHT1, GL_SPECULAR, light_ambient2);
467 xglMaterialf(GL_FRONT, GL_SHININESS, a * 85);
468 xglBegin(GL_TRIANGLES);
469 tmp1 = n1; tmp2 = n2;
470 for(i = tmp1; i <= tmp2; i++){
472 xglNormal3f(0.0, 0.0, 1.5);
473 xglTexCoord2f((73 / 256), (237 / 256));
474 xglVertex3f(((vertices[n1 % 180][0] + vertices[n2 % 180][0]) / 2), ((vertices[n1 % 180][1] + vertices[n2 % 180][1]) / 2), 0.0);
476 xglTexCoord2f((73 / 256), (236 / 256));
477 xglNormal3f(normals[n][0], normals[n][1], normals[n][2]);
478 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
481 xglTexCoord2f((73 / 256), (236 / 256));
482 xglNormal3f(normals[n][0], normals[n][1], normals[n][2]);
483 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
488 // Now we will have to draw the small triangle indicating the roll value
490 xglDisable(GL_LIGHTING);
491 xglDisable(GL_TEXTURE_2D);
493 xglRotatef(roll, 0.0, 0.0, 1.0);
495 xglBegin(GL_TRIANGLES);
496 xglColor3f(1.0, 1.0, 1.0);
497 xglVertex3f(0.0, radius, 0.0);
498 xglVertex3f(-3.0, (radius - 7.0), 0.0);
499 xglVertex3f(3.0, (radius - 7.0), 0.0);
504 xglBegin(GL_POLYGON);
505 xglColor3f(0.2109375, 0.23046875, 0.203125);
506 xglVertex2f(275.625, 138.0);
507 xglVertex2f(275.625, 148.125);
508 xglVertex2f(258.125, 151.25);
509 xglVertex2f(246.875, 151.25);
510 xglVertex2f(226.875, 147.5);
511 xglVertex2f(226.875, 138.0);
512 xglVertex2f(275.625, 138.0);
517 xglMatrixMode(GL_TEXTURE);
519 xglMatrixMode(GL_PROJECTION);
521 xglDisable(GL_TEXTURE_2D);
522 xglDisable(GL_NORMALIZE);
523 xglDisable(GL_LIGHTING);
524 xglDisable(GL_LIGHT1);
525 xglEnable(GL_LIGHT0);
528 // fgHorizonInit - initialize values for the AH
530 void FGHorizon::Init(void){
538 float step = (360*DEG_TO_RAD)/180;
541 vertices[n][0] = cos(n * step) * radius;
542 vertices[n][1] = sin(n * step) * radius;
543 texCoord[n][0] = (cos(n * step) * radius)/256;
544 texCoord[n][1] = (sin(n * step) * radius)/256;
545 normals[n][0] = cos(n * step) * radius + sin(n * step);
546 normals[n][1] = sin(n * step) * radius + cos(n * step);
551 void FGTexInstrument::UpdatePointer(void){
556 glEnableClientState(GL_VERTEX_ARRAY);
557 glVertexPointer(2, GL_FLOAT, 0, vertices);
559 alpha=((((float)((var[variable]) - (value1))) / (value2 - value1))* (alpha2 - alpha1) + alpha1);
565 xglMatrixMode(GL_MODELVIEW);
568 xglDisable(GL_TEXTURE_2D);
569 xglTranslatef(XPos, YPos, 0);
570 xglRotatef(-alpha, 0.0, 0.0, 1.0);
571 xglColor4f(1.0, 1.0, 1.0, 1.0);
572 glDrawArrays(GL_POLYGON, 0, 10);
575 xglEnable(GL_TEXTURE_2D);
576 glDisableClientState(GL_VERTEX_ARRAY);
579 // fgEraseArea - 'Erases' a drawn Polygon by overlaying it with a textured
580 // area. Shall be a method of a panel class once.
582 void fgEraseArea(GLfloat *array, int NumVerti, GLfloat texXPos, GLfloat texYPos, GLfloat XPos, GLfloat YPos, int Texid, float ScaleFactor){
588 xglEnable(GL_TEXTURE_2D);
589 xglEnable(GL_TEXTURE_GEN_S);
590 xglEnable(GL_TEXTURE_GEN_T);
591 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
592 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
593 xglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
594 xglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
595 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
596 xglMatrixMode(GL_TEXTURE);
599 #ifdef GL_VERSION_1_1
600 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[Texid]);
601 #elif GL_EXT_texture_object
602 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[Texid]);
607 xglMatrixMode(GL_TEXTURE);
609 xglTranslatef(-((float)((XPos/0.625)/256)), -((float)((YPos/0.625)/256)), 0.0);
610 xglTranslatef(texXPos/256 , texYPos/256, 0.0);
611 xglScalef(0.00625, 0.00625, 1.0);
613 xglBegin(GL_POLYGON);
614 for(n=0;n<NumVerti;n += 2){
615 xglVertex2f(array[n] * ScaleFactor, array[n + 1] * ScaleFactor);
620 xglMatrixMode(GL_MODELVIEW);
621 xglPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
622 xglPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
623 xglDisable(GL_TEXTURE_2D);
624 xglDisable(GL_TEXTURE_GEN_S);
625 xglDisable(GL_TEXTURE_GEN_T);
629 // CreatePointer - calculate the vertices of a pointer
631 void FGTexInstrument::CreatePointer(void){
638 vertices[1] = length;
639 vertices[2] = -(width/2);
640 vertices[3] = length - ((width/2)/(tan(angle*DEG_TO_RAD/2)));
641 vertices[4] = -(width/2);
642 vertices[5] = cos(asin((width/2)/r))*r;
644 alphastep = (asin((width/2)/r)+asin((width/2)/r))/5;
645 alpha = asin(-(width/2)/r);
649 vertices[(i*2)+6] = sin(alpha)*r;
652 alpha = asin(-(width/2)/r);
656 vertices[(i*2)+7]= cos(alpha)*r;
659 vertices[16] = - vertices[4];
660 vertices[17] = vertices[5];
661 vertices[18] = - vertices[2];
662 vertices[19] = vertices[3];
666 // fgUpdateTurnCoordinator - draws turn coordinator related stuff
668 void FGTurnCoordinator::Render(void){
671 xglDisable(GL_LIGHTING);
672 xglDisable(GL_BLEND);
673 xglEnable(GL_TEXTURE_2D);
675 alpha = (get_sideslip() / 1.5) * 560;
683 PlaneAlpha = get_roll();
685 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
686 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
687 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
689 xglMatrixMode(GL_MODELVIEW);
691 xglTranslatef(BallXPos, BallYPos, 0.0);
692 xglTranslatef(0.75 * sin(alphahist[0] * DEG_TO_RAD) * 31, 0.3 * (39 - (cos(alphahist[0] * DEG_TO_RAD) * 39)), 0.0);
693 fgEraseArea(vertices, 72, BallTexXPos + ((0.75 * sin(alphahist[0] * DEG_TO_RAD) * 31) / 0.625), BallTexYPos + ((0.3 * (39 - (cos(alphahist[0] * DEG_TO_RAD) * 39))) / 0.625), BallXPos + (0.75 * sin(alphahist[0] * DEG_TO_RAD) * 31), BallYPos + (0.3 * (39 - (cos(alphahist[0] * DEG_TO_RAD) * 39))), 1, 1);
694 xglDisable(GL_TEXTURE_2D);
696 xglBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
697 xglMatrixMode(GL_MODELVIEW);
699 xglTranslatef(BallXPos, BallYPos, 0.0);
700 xglTranslatef(0.75 * sin(alpha * DEG_TO_RAD) * 31, 0.3 * (39 - (cos(alpha * DEG_TO_RAD) * 39)), 0.0);
701 xglBegin(GL_POLYGON);
702 xglColor3f(0.8, 0.8, 0.8);
704 xglVertex2f(vertices[2 * i], vertices[(2 * i) + 1]);
708 xglDisable(GL_TEXTURE_2D);
709 xglDisable(GL_BLEND);
711 xglMatrixMode(GL_MODELVIEW);
713 xglTranslatef(XPos, YPos, 0.0);
714 xglRotatef(rollhist[0] * RAD_TO_DEG + 90, 0.0, 0.0, 1.0);
716 fgEraseArea(Wings, 8, PlaneTexXPos, PlaneTexYPos, XPos, YPos, 1, 1);
717 fgEraseArea(Elevator, 8, PlaneTexXPos, PlaneTexYPos, XPos, YPos, 1, 1);
718 fgEraseArea(Rudder, 8, PlaneTexXPos, PlaneTexYPos, XPos, YPos, 1, 1);
721 xglTranslatef(XPos, YPos, 0.0);
722 xglRotatef(-get_roll() * RAD_TO_DEG + 90, 0.0, 0.0, 1.0);
724 xglBegin(GL_POLYGON);
725 xglColor3f(1.0, 1.0, 1.0);
727 xglVertex2f(cos(i * 4 * DEG_TO_RAD) * 5, sin(i * 4 * DEG_TO_RAD) * 5);
731 xglBegin(GL_POLYGON);
732 xglVertex2f(Wings[0], Wings[1]);
733 xglVertex2f(Wings[2], Wings[3]);
734 xglVertex2f(Wings[4], Wings[5]);
735 xglVertex2f(Wings[6], Wings[7]);
736 xglVertex2f(Wings[0], Wings[1]);
739 xglBegin(GL_POLYGON);
740 xglVertex2f(Elevator[0], Elevator[1]);
741 xglVertex2f(Elevator[2], Elevator[3]);
742 xglVertex2f(Elevator[4], Elevator[5]);
743 xglVertex2f(Elevator[6], Elevator[7]);
744 xglVertex2f(Elevator[0], Elevator[1]);
747 xglBegin(GL_POLYGON);
748 xglVertex2f(Rudder[0], Rudder[1]);
749 xglVertex2f(Rudder[2], Rudder[3]);
750 xglVertex2f(Rudder[4], Rudder[5]);
751 xglVertex2f(Rudder[6], Rudder[7]);
752 xglVertex2f(Rudder[0], Rudder[1]);
756 alphahist[0] = alphahist[1];
757 alphahist[1] = alpha;
758 rollhist[0] = rollhist[1];
759 rollhist[1] = -get_roll();
761 xglDisable(GL_BLEND);
764 void FGTurnCoordinator::Init(void){
767 PlaneTexYPos = 59.75;
775 vertices[2 * n] = cos(10 * n * DEG_TO_RAD) * BallRadius;
776 vertices[(2 * n) + 1] = sin(10 * n * DEG_TO_RAD) * BallRadius;
780 void DrawScale(float XPos, float YPos, float InnerRadius, float OuterRadius, float alpha1, float alpha2, int steps, float LineWidth, float red, float green, float blue, bool filled){
782 float diff = (alpha2 - alpha1) / (float)(steps - 1);
784 #define ANTIALIASED_INSTRUMENTS
786 #ifdef ANTIALIASED_INSTRUMENTS
787 xglEnable(GL_LINE_SMOOTH);
789 xglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
792 xglMatrixMode(GL_MODELVIEW);
795 xglTranslatef(XPos, YPos, 0.0);
796 xglRotatef(-alpha1, 0.0, 0.0, 1.0);
798 xglLineWidth(LineWidth);
799 xglColor3f(red, green, blue);
805 xglBegin(GL_QUAD_STRIP);
808 for(i=0;i < steps; i++){
809 xglVertex3f(sin(i * diff * DEG_TO_RAD) * OuterRadius, cos(i * diff * DEG_TO_RAD) * OuterRadius, 0.0);
810 xglVertex3f(sin(i * diff * DEG_TO_RAD) * InnerRadius, cos(i * diff * DEG_TO_RAD) * InnerRadius, 0.0);
815 xglDisable(GL_LINE_SMOOTH);
816 xglDisable(GL_BLEND);
819 void DrawBeechcraftLogo(float XPos, float YPos, float width, float height){
820 xglMatrixMode(GL_MODELVIEW);
822 xglTranslatef(XPos, YPos, 0.0);
824 xglEnable(GL_TEXTURE_2D);
825 // xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
826 // xglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
828 #ifdef GL_VERSION_1_1
829 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[1]);
830 #elif GL_EXT_texture_object
831 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[1]);
836 xglBegin(GL_POLYGON);
838 xglTexCoord2f(.39844, .01953);
839 xglVertex2f(0.0, 0.0);
840 xglTexCoord2f(.58594, .01953);
841 xglVertex2f(width, 0.0);
842 xglTexCoord2f(.58594, .074219);
843 xglVertex2f(width, height);
844 xglTexCoord2f(.39844, .074219);
845 xglVertex2f(0.0, height);
849 xglDisable(GL_BLEND);
850 xglDisable(GL_TEXTURE_2D);
854 // PrintMatrix - routine to print the current modelview matrix.
856 void PrintMatrix( void){
857 xglGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
858 printf("matrix2 = %f %f %f %f \n", mvmatrix[0], mvmatrix[1], mvmatrix[2], mvmatrix[3]);
859 printf(" %f %f %f %f \n", mvmatrix[4], mvmatrix[5], mvmatrix[6], mvmatrix[7]);
860 printf(" %f %f %f %f \n", mvmatrix[8], mvmatrix[9], mvmatrix[10], mvmatrix[11]);
861 printf(" %f %f %f %f \n", mvmatrix[12], mvmatrix[13], mvmatrix[14], mvmatrix[15]);
864 void FGRpmGauge::Init(void){
865 list = xglGenLists (1);
868 xglNewList(list, GL_COMPILE);
870 xglColor3f(.26, .289, .3281);
871 xglBegin(GL_POLYGON);
872 for(n = 0; n < 180; n++){
873 xglVertex2f(cos(n * 0.0349066) * 24.5, sin(n * 0.0349066) * 24.5);
877 DrawScale(XPos, YPos, 22.5, 25.625, 50, 135, 10, 1.0, 0.0, 0.7, 0.0,FILLED);
878 DrawScale(XPos, YPos, 21.0, 25.625, -70, 180, 8, 1.8, 0.88, 0.88, 0.88, false);
879 DrawScale(XPos, YPos, 22.5, 25.0, -70, 180, 40, 0.6, 0.5, 0.5, 0.5, false);
884 void FGRpmGauge::Render(void){
885 xglMatrixMode(GL_MODELVIEW);
887 xglTranslatef(XPos, YPos, 0.0);
893 void FGPanel::DrawTestLetter(float X, float Y){
894 xglEnable(GL_TEXTURE_2D);
897 xglMatrixMode(GL_TEXTURE);
899 xglTranslatef(X, Y, 0.0);
903 xglMatrixMode(GL_MODELVIEW);
904 xglTranslatef(6.0, 0.0, 0.0);
905 xglDisable(GL_TEXTURE_2D);
906 xglDisable(GL_BLEND);
909 void FGPanel::InitLists(void){
910 xglNewList(FontList + 'A', GL_COMPILE);
911 DrawTestLetter(0.391625, 0.29296875);
914 xglNewList(FontList + 'B', GL_COMPILE);
915 DrawTestLetter(0.391625 + 1 * LETTER_OFFSET, 0.29296875);
918 xglNewList(FontList + 'C', GL_COMPILE);
919 DrawTestLetter(0.391625 + 2 * LETTER_OFFSET, 0.29296875);
922 xglNewList(FontList + 'D', GL_COMPILE);
923 DrawTestLetter(0.391625 + 3 * LETTER_OFFSET, 0.29296875);
926 xglNewList(FontList + 'E', GL_COMPILE);
927 DrawTestLetter(0.391625 + 4 * LETTER_OFFSET, 0.29296875);
930 xglNewList(FontList + 'F', GL_COMPILE);
931 DrawTestLetter(0.391625 + 5 * LETTER_OFFSET, 0.29296875);
934 xglNewList(FontList + 'G', GL_COMPILE);
935 DrawTestLetter(0.391625 + 6 * LETTER_OFFSET, 0.29296875);
938 xglNewList(FontList + 'H', GL_COMPILE);
939 DrawTestLetter(0.391625 + 7 * LETTER_OFFSET, 0.29296875);
942 xglNewList(FontList + 'I', GL_COMPILE);
943 DrawTestLetter(0.391625 + 8 * LETTER_OFFSET, 0.29296875);
946 xglNewList(FontList + 'J', GL_COMPILE);
947 DrawTestLetter(0.391625 + 9 * LETTER_OFFSET, 0.29296875);
950 xglNewList(FontList + 'K', GL_COMPILE);
951 DrawTestLetter(0.391625 + 9.7 * LETTER_OFFSET, 0.29296875);
954 xglNewList(FontList + 'L', GL_COMPILE);
955 DrawTestLetter(0.399625 + 10.6 * LETTER_OFFSET, 0.29296875);
958 xglNewList(FontList + 'M', GL_COMPILE);
959 DrawTestLetter(0.80459375, 0.29296875);
962 xglNewList(FontList + 'N', GL_COMPILE);
963 DrawTestLetter(0.83975, 0.29296875);
966 xglNewList(FontList + 'O', GL_COMPILE);
967 DrawTestLetter(0.871, 0.29296875);
970 xglNewList(FontList + 'P', GL_COMPILE);
971 DrawTestLetter(0.90715625, 0.29296875);
974 xglNewList(FontList + 'Q', GL_COMPILE);
975 DrawTestLetter(0.9413125, 0.29296875);
978 xglNewList(FontList + '1', GL_COMPILE);
979 DrawTestLetter(0.390625, 0.35546875);
982 xglNewList(FontList + '2', GL_COMPILE);
983 DrawTestLetter(0.390625 + 1*LETTER_OFFSET, 0.3515625);
986 xglNewList(FontList + '3', GL_COMPILE);
987 DrawTestLetter(0.390625 + 2*LETTER_OFFSET, 0.3515625);
990 xglNewList(FontList + '4', GL_COMPILE);
991 DrawTestLetter(0.390625 + 3*LETTER_OFFSET, 0.3515625);
994 xglNewList(FontList + '5', GL_COMPILE);
995 DrawTestLetter(0.390625 + 4*LETTER_OFFSET, 0.3515625);
998 xglNewList(FontList + '6', GL_COMPILE);
999 DrawTestLetter(0.390625 + 5*LETTER_OFFSET, 0.3515625);
1002 xglNewList(FontList + '7', GL_COMPILE);
1003 DrawTestLetter(0.390625 + 6*LETTER_OFFSET, 0.3515625);
1006 xglNewList(FontList + '8', GL_COMPILE);
1007 DrawTestLetter(0.390625 + 7*LETTER_OFFSET, 0.3515625);
1010 xglNewList(FontList + '9', GL_COMPILE);
1011 DrawTestLetter(0.390625 + 8*LETTER_OFFSET, 0.3515625);
1014 xglNewList(FontList + '0', GL_COMPILE);
1015 DrawTestLetter(0.383625 + 9*LETTER_OFFSET, 0.3515625);
1018 xglNewList(FontList + ' ', GL_COMPILE);
1019 xglTranslatef(8.0, 0.0, 0.0);
1023 void FGPanel::TexString(char *s, float XPos, float YPos, float size){
1024 xglMatrixMode(GL_MODELVIEW);
1026 xglTranslatef(XPos, YPos, 0.0);
1027 xglScalef(size, size, 1.0);
1029 #ifdef GL_VERSION_1_1
1030 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[1]);
1031 #elif GL_EXT_texture_object
1032 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[1]);
1037 while((*s) != '\0'){
1038 xglCallList(FontList + (*s));
1044 void FGTexInstrument::Init(void){
1048 void FGTexInstrument::Render(void){
1049 xglEnable(GL_TEXTURE_2D);
1051 xglTranslatef(XPos, YPos, 0.0);
1052 xglRotatef(-tape[0], 0.0, 0.0, 1.0);
1053 fgEraseArea(vertices, 20, (GLfloat)(teXpos), (GLfloat)(texYpos), (GLfloat)(XPos), (GLfloat)(YPos), 0, 1);
1057 xglDisable(GL_TEXTURE_2D);