added libs and oalist
[mines3d.git] / opengl / runGlutMainLoop.cpp
blob572533e3c6988b1b38054f3e447e0012d043780a
2 #if defined(_WIN32) || defined(__WIN32__)
3 # include <windows.h>
4 #endif
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <GL/gl.h>
10 #include <GL/glut.h>
11 #include "trackball.h"
12 #include "readtex.h"
13 #include "runGlutMainLoop.h"
14 #include "../core/board.h"
15 #include "../threads/thread_controller.h"
17 #ifndef byte
18 # define byte unsigned char
19 #endif
22 #define glut_WINDOW_SIZE 500
23 #define glut_WINDOW_POS_X 500
24 #define glut_WINDOW_POS_Y 200
25 #define glut_WINDOW_TITLE "OpenGL GLUT - 3D miny"
26 #define glut_CUBE_SIZE 0.5f
27 #define glut_ANGLE 1.0f
28 #define TEXTURE_FILE "textury/all.sgi"
29 #define TEXTURE_OFFSET_UNIT_X 0.125f
30 #define TEXTURE_OFFSET_UNIT_Y 0.25f
31 #define ALPHA_CONST 0.8f
33 void (*drawMines)();
35 //void runGlutMainLoop(int x,int y,int z);
37 //void * runGlutMainLoop( void * args);
39 void init();
40 void display(void);
41 void reshape(int width,int height);
42 void keyboard_input(int key,int x,int y);
43 void idle(void);
44 void drawMines1(void);
45 void drawMine(int x,int y,int z);
46 void initLights(void);
47 void mouse_input(int button,int state,int x,int y);
48 void motion(int x,int y);
49 void displaySub(void);
50 void makeTextures(void);
51 void motion_pas(int x,int y);
52 void forceRedraw(void);
53 void app_exiting(void);
56 int * minesX;
57 int * minesY;
58 int * minesZ;
60 int w_width;
61 int w_height;
63 int win, subWin;
65 byte mode = 1;
66 byte update_nums = 0;
67 float zoom = 1.0f;
69 int cropX_min = 0,cropX_max;
70 int cropY_min = 0,cropY_max;
71 int cropZ_min = 0,cropZ_max;
72 int last_x,last_y,last_z;
74 float mouse_old_x = 0, mouse_old_y = 0;
76 //Board * board;
77 Thread_controller * thc;
79 float curQuat[4], incQuat[4];
81 const char * strX = "X: min max";
82 const char * strY = "Y: min max";
83 const char * strZ = "Z: min max";
85 int selectXYZ = -1;
87 char update = 1;
89 GLfloat ambient [] = { 1.0f, 1.0f, 1.0f, 1.0f };
91 GLfloat diffuse [][4] =
93 { 0.9f, 0.9f, 0.9f, 1.0f }, // 0 light grey
94 { 0.0f, 0.0f, 1.0f, 1.0f }, // 1 blue
95 { 0.0f, 1.0f, 0.0f, 1.0f }, // 2 green
96 { 1.0f, 0.0f, 0.0f, 1.0f }, // 3 red
97 { 0.0f, 0.0f, 0.5f, 1.0f }, // 4 dark blue
98 { 0.7f, 0.0f, 0.7f, 1.0f }, // 5 purple
99 { 0.0f, 0.5f, 0.0f, 1.0f }, // 6 dark green
100 { 0.5f, 0.0f, 0.0f, 1.0f }, // 7 dark red
101 { 0.32f, 0.32f, 0.32f, 1.0f }, // 8 grey
102 { 0.0f, 0.0f, 0.0f, 0.0f } // 9 black
105 GLfloat sunDirection [] = { 0.0f, -1.0f, 0.0f };
106 GLfloat sunPosition [3];
108 //void runGlutMainLoop(int x,int y,int z )
110 void forceRedraw(void)
112 glFlush();
113 glutPostRedisplay();
114 //display();
118 void app_exiting(void)
120 update = 0;
123 void * runGlutMainLoop( void * args )
125 char *argval = new char [1];
126 char **argv = new char* [1];
127 argv[0] = argval;
128 argval[0] = '\0';
129 int argc = 1;
131 thc = (Thread_controller *)args;
133 glutInit(&argc,argv);
134 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA | GLUT_DEPTH);
135 glutInitWindowSize(glut_WINDOW_SIZE,glut_WINDOW_SIZE);
136 glutInitWindowPosition(glut_WINDOW_POS_X,glut_WINDOW_POS_Y);
137 win = glutCreateWindow(glut_WINDOW_TITLE);
138 w_height = w_width = glut_WINDOW_SIZE;
140 drawMines = drawMines1;
142 init();
143 initLights();
144 glutDisplayFunc(display);
145 glutReshapeFunc(reshape);
146 glutIdleFunc(idle);
148 glutMotionFunc(motion);
149 glutSpecialFunc(keyboard_input);
151 trackball(curQuat,0.0,0.0,0.0,0.0);
153 subWin = glutCreateSubWindow(win, 0, 0, 340, 60);
154 glutDisplayFunc(displaySub);
155 glutMouseFunc(mouse_input);
156 glutPassiveMotionFunc(motion_pas);
158 thc->ptf = &forceRedraw;
159 thc->ptf_end = &app_exiting;
161 glutMainLoop();
162 return 0;
165 void init()
169 glPolygonMode( GL_FRONT, GL_FILL );
170 glPolygonMode( GL_BACK, GL_LINE );
171 glCullFace( GL_BACK );
173 minesX = &thc->dim[0];
174 minesY = &thc->dim[1];
175 minesZ = &thc->dim[2];
177 sunPosition[0] = 0.0f;
178 sunPosition[1] = 0.0f;
179 sunPosition[2] = (*minesY) * 8 * glut_CUBE_SIZE;
181 cropX_max = last_x = *minesX;
182 cropY_max = last_y = *minesY;
183 cropZ_max = last_z = *minesZ;
185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
188 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
189 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
191 if(!LoadRGBMipmapsUserAlpha(TEXTURE_FILE, GL_RGBA,ALPHA_CONST)) {
192 printf("Error: couldn't load texture image\n");
195 glEnable(GL_TEXTURE_2D);
196 glEnable(GL_LIGHTING);
197 glEnable(GL_DEPTH_TEST);
200 void initLights(void)
202 glEnable(GL_LIGHT0);
203 glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,180);
205 glLightfv(GL_LIGHT0,GL_POSITION, sunPosition );
206 glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,sunDirection);
210 void displaySub(void)
212 glClearColor(0.2, 0.2, 0.2, 1.0);
213 glClear(GL_COLOR_BUFFER_BIT);
214 glColor3f(1, 1, 1);
215 glRasterPos2f(-0.95,0.5);
216 int i,len;
217 char * pom = (char*)malloc(25*sizeof(char));
218 if (cropX_min <= 9) sprintf(pom," %i",cropX_min);
219 else sprintf(pom,"%i",cropX_min);
220 len = strlen(pom);
221 for(i=0;i<7;i++)
222 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strX[i]);
223 for(i=0;i<len;i++)
224 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
226 if (cropX_max <= 9) sprintf(pom," %i",cropX_max);
227 else sprintf(pom,"%i",cropX_max);
228 len = strlen(pom);
230 for(i=7;i<14;i++)
231 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strX[i]);
232 for(i=0;i<len;i++)
233 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
235 glRasterPos2f(-0.95,-0.1);
236 if (cropY_min <= 9) sprintf(pom," %i",cropY_min);
237 else sprintf(pom,"%i",cropY_min);
238 len = strlen(pom);
239 for(i=0;i<7;i++)
240 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strY[i]);
241 for(i=0;i<len;i++)
242 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
244 if (cropY_max <= 9) sprintf(pom," %i",cropY_max);
245 else sprintf(pom,"%i",cropY_max);
246 len = strlen(pom);
247 for(i=7;i<14;i++)
248 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strY[i]);
249 for(i=0;i<len;i++)
250 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
252 glRasterPos2f(-0.95,-0.7);
253 if (cropZ_min <= 9) sprintf(pom," %i",cropZ_min);
254 else sprintf(pom,"%i",cropZ_min);
255 len = strlen(pom);
256 for(i=0;i<7;i++)
257 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strZ[i]);
258 for(i=0;i<len;i++)
259 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
261 if (cropZ_max <= 9) sprintf(pom," %i",cropZ_max);
262 else sprintf(pom,"%i",cropZ_max);
263 len = strlen(pom);
264 for(i=7;i<14;i++)
265 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strZ[i]);
266 for(i=0;i<len;i++)
267 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
272 if (selectXYZ == 8) glColor3f(1, 0, 0);
273 else glColor3f(1, 1, 0);
274 glRasterPos2f(-0.45,0.5);
275 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
277 if (selectXYZ == 9) glColor3f(1, 0, 0);
278 else glColor3f(1, 1, 0);
279 glRasterPos2f(-0.38,0.5);
280 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
282 if (selectXYZ == 10) glColor3f(1, 0, 0);
283 else glColor3f(1, 1, 0);
284 glRasterPos2f(0.03,0.5);
285 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
287 if (selectXYZ == 11) glColor3f(1, 0, 0);
288 else glColor3f(1, 1, 0);
289 glRasterPos2f(0.10,0.5);
290 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
293 if (selectXYZ == 4) glColor3f(1, 0, 0);
294 else glColor3f(1, 1, 0);
295 glRasterPos2f(-0.45,-0.1);
296 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
298 if (selectXYZ == 5) glColor3f(1, 0, 0);
299 else glColor3f(1, 1, 0);
300 glRasterPos2f(-0.38,-0.1);
301 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
303 if (selectXYZ == 6) glColor3f(1, 0, 0);
304 else glColor3f(1, 1, 0);
305 glRasterPos2f(0.03,-0.1);
306 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
308 if (selectXYZ == 7) glColor3f(1, 0, 0);
309 else glColor3f(1, 1, 0);
310 glRasterPos2f(0.10,-0.1);
311 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
314 if (selectXYZ == 0) glColor3f(1, 0, 0);
315 else glColor3f(1, 1, 0);
316 glRasterPos2f(-0.45,-0.7);
317 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
319 if (selectXYZ == 1) glColor3f(1, 0, 0);
320 else glColor3f(1, 1, 0);
321 glRasterPos2f(-0.38,-0.7);
322 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
324 if (selectXYZ == 2) glColor3f(1, 0, 0);
325 else glColor3f(1, 1, 0);
326 glRasterPos2f(0.03,-0.7);
327 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
329 if (selectXYZ == 3) glColor3f(1, 0, 0);
330 else glColor3f(1, 1, 0);
331 glRasterPos2f(0.10,-0.7);
332 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
334 if (selectXYZ == 12) glColor3f(1, 0, 0);
335 else glColor3f(1, 1, 0);
336 glRasterPos2f(0.2,0.5);
337 sprintf(pom,"SWITCH MODE %i",mode);
338 len = strlen(pom);
339 for(i=0;i<len;i++)
340 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
342 if (selectXYZ == 13) glColor3f(1, 0, 0);
343 else glColor3f(1, 1, 0);
344 glRasterPos2f(0.2,-0.1);
345 const char * upn_str;
346 if (update_nums) upn_str = "ON";
347 else upn_str = "OFF";
349 sprintf(pom,"UPDATE NUMS %s",upn_str);
350 len = strlen(pom);
351 for(i=0;i<len;i++)
352 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
356 free(pom);
358 glutSwapBuffers();
361 void display(void)
363 if (update == 0)
365 pthread_exit((void *)0);
367 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
370 thc->mutex_lock();
372 if (update == 0)
374 thc->mutex_unlock();
375 pthread_exit((void *)0);
378 if ( last_x != *minesX || last_y != *minesY || last_z != *minesZ )
380 cropX_max = last_x = *minesX;
381 cropY_max = last_y = *minesY;
382 cropZ_max = last_z = *minesZ;
383 glutPostWindowRedisplay(win);
386 glMatrixMode(GL_MODELVIEW);
387 glLoadIdentity();
388 int m = *minesX;
389 if (*minesY > m) m = *minesY;
390 if (*minesZ > m) m = *minesZ;
394 gluLookAt( 0.0, 0.0 , glut_CUBE_SIZE * 6 * m * zoom,
395 0.0,0.0,0.0,
396 0.0, 1.0, 0.0
399 glPushMatrix();
401 if (thc->b != 0) drawMines();
405 glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
406 glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse[0]);
408 glPopMatrix();
410 thc->mutex_unlock();
413 glutSwapBuffers();
414 glutPostRedisplay();
419 void reshape(int width,int height)
421 if (update == 0)
423 pthread_exit((void *)0);
425 w_width = width;
426 w_height = height;
428 glViewport(0,0,width,height);
430 glMatrixMode(GL_PROJECTION);
431 glLoadIdentity();
432 gluPerspective(60.0,(GLdouble)width/height,0.1,200.0);
434 thc->mutex_lock();
436 if (update == 0)
438 thc->mutex_unlock();
439 pthread_exit((void *)0);
440 return;
443 glMatrixMode(GL_MODELVIEW);
444 glLoadIdentity();
445 int m = *minesX;
446 if (*minesY > m) m = *minesY;
447 if (*minesZ > m) m = *minesZ;
449 thc->mutex_unlock();
451 gluLookAt( 0.0, 0.0 , glut_CUBE_SIZE * 6 * m * zoom,
452 0.0,0.0,0.0,
453 0.0, 1.0, 0.0
458 void idle(void)
460 glutPostRedisplay();
463 void keyboard_input(int key,int x,int y)
465 if (key == GLUT_KEY_LEFT) zoom += 0.025f;
466 if (key == GLUT_KEY_RIGHT) zoom -= 0.025f;
470 void mouse_input(int button,int state,int x,int y)
473 if( button == GLUT_LEFT_BUTTON )
475 if (state == GLUT_DOWN)
477 switch( selectXYZ )
479 case 12:
480 ++(mode %= 4);
481 break;
482 case 13:
483 if (update_nums) update_nums = 0;
484 else update_nums = 1;
485 break;
486 case 8:
487 if (cropX_min < *minesX-1) cropX_min += 1;
488 break;
489 case 9:
490 if (cropX_min > 0) cropX_min -= 1;
491 break;
492 case 10:
493 if (cropX_max < *minesX) cropX_max += 1;
494 break;
495 case 11:
496 if (cropX_max > 0) cropX_max -= 1;
497 break;
498 case 4:
499 if (cropY_min < *minesY-1) cropY_min += 1;
500 break;
501 case 5:
502 if (cropY_min > 0) cropY_min -= 1;
503 break;
504 case 6:
505 if (cropY_max < *minesY) cropY_max += 1;
506 break;
507 case 7:
508 if (cropY_max > 0) cropY_max -= 1;
509 break;
510 case 0:
511 if (cropZ_min < *minesZ-1) cropZ_min += 1;
512 break;
513 case 1:
514 if (cropZ_min > 0) cropZ_min -= 1;
515 break;
516 case 2:
517 if (cropZ_max < *minesZ) cropZ_max += 1;
518 break;
519 case 3:
520 if (cropZ_max > 0) cropZ_max -= 1;
521 break;
527 glutPostWindowRedisplay(win);
531 void motion(int x, int y)
533 int x1,y1;
534 x1 = x;
535 y1 = y;
536 if (mouse_old_x - x > w_width / 100 ) x = (int)mouse_old_x - w_width / 100;
537 if (mouse_old_x - x < -w_width / 100) x = (int)mouse_old_x + w_width / 100;
539 if (mouse_old_y - y > w_height / 100) y = (int)mouse_old_y - w_height/ 100;
540 if (mouse_old_y - y < -w_height / 100) y = (int)mouse_old_y + w_height / 100;
542 trackball(incQuat, (2.0 * mouse_old_x - w_width) / w_width,
543 (w_height - 2.0 * mouse_old_y) / w_height,
544 (2.0 * x - w_width) / w_width,
545 (w_height - 2.0 * y) / w_height );
548 add_quats(incQuat,curQuat,curQuat);
550 mouse_old_x = x1;
551 mouse_old_y = y1;
553 //glutPostRedisplay();
558 void drawMines1(void)
560 int i,j,k;
561 float m[4][4];
563 glPushMatrix();
567 build_rotmatrix(m,curQuat);
568 glMultMatrixf(&m[0][0]);
570 glDisable(GL_LIGHTING);
571 glDisable(GL_TEXTURE_2D);
573 glBegin(GL_LINES);
574 glColor3f(1.0, 0.0, 0.0);
575 glVertex3f(0.0,0.0,0.0);
576 glVertex3f(glut_CUBE_SIZE * 4 * *minesX,0.0,0.0);
578 glVertex3f(glut_CUBE_SIZE * 4 * *minesX,0.0,0.0);
579 glVertex3f(glut_CUBE_SIZE * 4 * *minesX - 2,2.0,0.0);
580 glVertex3f(glut_CUBE_SIZE * 4 * *minesX,0.0,0.0);
581 glVertex3f(glut_CUBE_SIZE * 4 * *minesX - 2,-2.0,0.0);
583 glColor3f(0.0, 1.0, 0.0);
584 glVertex3f(0.0,0.0,0.0);
585 glVertex3f(0.0,glut_CUBE_SIZE * 4 * *minesY,0.0);
587 glVertex3f(0.0,glut_CUBE_SIZE * 4 * *minesY,0.0);
588 glVertex3f(2.0,glut_CUBE_SIZE * 4 * *minesY-2,0.0);
589 glVertex3f(0.0,glut_CUBE_SIZE * 4 * *minesY,0.0);
590 glVertex3f(-2.0,glut_CUBE_SIZE * 4 * *minesY-2,0.0);
592 glColor3f(0.0, 0.0, 1.0);
593 glVertex3f(0.0,0.0,0.0);
594 glVertex3f(0.0,0.0,glut_CUBE_SIZE * 4 * *minesZ);
596 glVertex3f(0.0,0.0,glut_CUBE_SIZE * 4 * *minesZ);
597 glVertex3f(2.0,0.0,glut_CUBE_SIZE * 4 * *minesZ-2);
598 glVertex3f(0.0,0.0,glut_CUBE_SIZE * 4 * *minesZ);
599 glVertex3f(-2.0,0.0,glut_CUBE_SIZE * 4 * *minesZ-2);
602 glEnd();
604 glEnable(GL_LIGHTING);
605 glEnable(GL_TEXTURE_2D);
607 glEnable (GL_BLEND);
608 glDepthMask (GL_FALSE);
609 glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR);
611 //if (mode > 2) glTranslated(-4 * glut_CUBE_SIZE * thc->selected[1], 4 * glut_CUBE_SIZE * thc->selected[2],4 * glut_CUBE_SIZE * thc->selected[0] );
612 //else glTranslated( -2 * (*minesX-1) * glut_CUBE_SIZE,2 * (*minesY-1) * glut_CUBE_SIZE,2 * (*minesZ-1) * glut_CUBE_SIZE );
614 if (mode > 2) glTranslated(-4 * glut_CUBE_SIZE * thc->selected[2], 4 * glut_CUBE_SIZE * thc->selected[1],4 * glut_CUBE_SIZE * thc->selected[0] );
615 else glTranslated( -2 * (*minesX-1) * glut_CUBE_SIZE,2 * (*minesY-1) * glut_CUBE_SIZE,2 * (*minesZ-1) * glut_CUBE_SIZE );
617 glPushAttrib(GL_ALL_ATTRIB_BITS);
619 for (i = 0;i < *minesX ;i++ )
621 if ((i < thc->selected[1]-2 || i > thc->selected[1]+2) && mode > 2 ) continue;
623 if (i < cropX_min || i > cropX_max) continue;
625 for ( j = 0;j < *minesZ; j++ )
627 if ((j < thc->selected[0]-2 || j > thc->selected[0]+2) && mode > 2 ) continue;
628 if (j < cropZ_min || j > cropZ_max) continue;
629 for ( k = 0;k < *minesY; k++ )
631 if ((k < thc->selected[2]-2 || k > thc->selected[2]+2) && mode > 2 ) continue;
632 if (k < cropY_min || k > cropY_max) continue;
633 glPushMatrix();
635 //glTranslated( 4 * i * glut_CUBE_SIZE, 4 * k * glut_CUBE_SIZE, -4 * j * glut_CUBE_SIZE );
637 glTranslated( 4 * k * glut_CUBE_SIZE, -4 * i * glut_CUBE_SIZE, -4 * j * glut_CUBE_SIZE );
639 glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
640 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse[0]);
642 if ((thc->selected[0] == j && thc->selected[1] == i && thc->selected[2] == k) || thc->selected[0] == -1 || mode % 2 == 1)
644 glDepthMask (GL_TRUE);
645 glDisable (GL_BLEND);
647 if ((thc->selected[3] == j && thc->selected[4] == i && thc->selected[5] == k) )
648 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse[8]);
649 drawMine(j,i,k);
650 glEnable (GL_BLEND);
651 glDepthMask (GL_FALSE);
652 glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR);
655 else
657 drawMine(j,i,k);
659 glPopMatrix();
665 glPopAttrib();
667 glDepthMask (GL_TRUE);
668 glDisable (GL_BLEND);
670 glPopMatrix();
671 glFlush();
676 void drawMine(int x,int y,int z)
678 int val;
680 //glEnable(GL_TEXTURE_2D);
681 //glDisable( GL_LIGHTING );
683 const Field & f = thc->b->getField(x,y,z);
685 val = 29;
686 int total_offsetX = 0;
687 int total_offsetY = 3;
689 if ( f.hasMark() )
691 val = 26;
692 goto calc_offset;
694 if ( !f.isCovered() )
696 if ( f.hasMine() )
698 val = 27;
699 goto calc_offset;
701 if (update_nums)
703 val = f.getRemainingNeighboursCnt() - 1;
704 if (val == -1 ) return;
705 if (val < -1 ) val = 28;
707 else
709 val = f.getNeighboursCnt() - 1;
710 if (val == -1 ) return;
714 calc_offset:
716 total_offsetX = val % 8;
717 total_offsetY -= (val / 8) % 4;
720 glBegin(GL_QUADS);
722 // front
724 glNormal3f(0.0f, 0.0f, 1.0f);
726 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
727 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
729 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
730 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
732 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
733 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
735 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
736 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
738 // back
739 glNormal3f(0.0f, 0.0f, -1.0f);
741 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
742 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
744 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
745 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
747 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
748 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
750 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
751 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
753 // left
754 glNormal3f(-1.0f, 0.0f, 0.0f);
756 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
757 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
759 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
760 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
762 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
763 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
765 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
766 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
768 // right
769 glNormal3f(1.0f, 0.0f, 0.0f);
771 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
772 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
774 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
775 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
777 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
778 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
780 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
781 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
783 // bottom
784 glNormal3f(0.0f, -1.0f, 0.0f);
786 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
787 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
789 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
790 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
792 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
793 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
795 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
796 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
798 // top
799 glNormal3f(0.0f, 1.0f, 0.0f);
801 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
802 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
804 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
805 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
807 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
808 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
810 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
811 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
816 glEnd();
818 //glDisable(GL_TEXTURE_2D);
819 //glEnable( GL_LIGHTING );
824 void motion_pas(int x,int y)
827 if (y < 54 && y > 37)
829 if (x < 196)
831 if (x > 184 )
833 selectXYZ = 3;
834 return;
836 if (x > 174 )
838 selectXYZ = 2;
839 return;
842 if (x < 115)
844 if (x > 104 )
846 selectXYZ = 1;
847 return;
849 if (x > 94 )
851 selectXYZ = 0;
852 return;
858 if (y < 37 && y > 19)
860 if (x < 336 && x > 200)
862 selectXYZ = 13;
863 return;
866 if (x < 196)
868 if (x > 184 )
870 selectXYZ = 7;
871 return;
873 if (x > 174 )
875 selectXYZ = 6;
876 return;
879 if (x < 115)
881 if (x > 104 )
883 selectXYZ = 5;
884 return;
886 if (x > 94 )
888 selectXYZ = 4;
889 return;
895 if (y < 19 && y > 2)
897 if (x < 320 && x > 200)
899 selectXYZ = 12;
900 return;
903 if (x < 196)
905 if (x > 184 )
907 selectXYZ = 11;
908 return;
910 if (x > 174 )
912 selectXYZ = 10;
913 return;
916 if (x < 115)
918 if (x > 104 )
920 selectXYZ = 9;
921 return;
923 if (x > 94 )
925 selectXYZ = 8;
926 return;
931 selectXYZ = -1;