project config: Debug support added.
[mines3d.git] / opengl / runGlutMainLoop.cpp
blob02810e2c3d2982dd3b07b98e15d5213d5a3ba7ab
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(int x,int y,int z);
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);
54 int * minesX;
55 int * minesY;
56 int * minesZ;
58 int w_width;
59 int w_height;
61 int win, subWin;
63 byte mode = 1;
64 float zoom = 1.0f;
66 int cropX_min = 0,cropX_max;
67 int cropY_min = 0,cropY_max;
68 int cropZ_min = 0,cropZ_max;
69 int last_x,last_y,last_z;
71 float mouse_old_x = 0, mouse_old_y = 0;
73 //Board * board;
74 Thread_controller * thc;
76 float curQuat[4], incQuat[4];
78 const char * strX = "X: min max";
79 const char * strY = "Y: min max";
80 const char * strZ = "Z: min max";
82 int selectXYZ = -1;
84 GLfloat ambient [] = { 1.0f, 1.0f, 1.0f, 1.0f };
86 GLfloat diffuse [][4] =
88 { 0.9f, 0.9f, 0.9f, 1.0f }, // 0 light grey
89 { 0.0f, 0.0f, 1.0f, 1.0f }, // 1 blue
90 { 0.0f, 1.0f, 0.0f, 1.0f }, // 2 green
91 { 1.0f, 0.0f, 0.0f, 1.0f }, // 3 red
92 { 0.0f, 0.0f, 0.5f, 1.0f }, // 4 dark blue
93 { 0.7f, 0.0f, 0.7f, 1.0f }, // 5 purple
94 { 0.0f, 0.5f, 0.0f, 1.0f }, // 6 dark green
95 { 0.5f, 0.0f, 0.0f, 1.0f }, // 7 dark red
96 { 0.32f, 0.32f, 0.32f, 1.0f }, // 8 grey
97 { 0.0f, 0.0f, 0.0f, 0.0f } // 9 black
100 GLfloat sunDirection [] = { 0.0f, -1.0f, 0.0f };
101 GLfloat sunPosition [3];
103 //void runGlutMainLoop(int x,int y,int z )
105 void forceRedraw(void)
107 glutPostRedisplay();
110 void * runGlutMainLoop( void * args )
112 char *argval = new char [1];
113 char **argv = new char* [1];
114 argv[0] = argval;
115 argval[0] = '\0';
116 int argc = 1;
118 thc = (Thread_controller *)args;
120 glutInit(&argc,argv);
121 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA | GLUT_DEPTH);
122 glutInitWindowSize(glut_WINDOW_SIZE,glut_WINDOW_SIZE);
123 glutInitWindowPosition(glut_WINDOW_POS_X,glut_WINDOW_POS_Y);
124 win = glutCreateWindow(glut_WINDOW_TITLE);
125 w_height = w_width = glut_WINDOW_SIZE;
127 drawMines = drawMines1;
129 init(thc->dim[0],thc->dim[1],thc->dim[2]);
130 initLights();
131 glutDisplayFunc(display);
132 glutReshapeFunc(reshape);
133 glutIdleFunc(idle);
134 glutMotionFunc(motion);
135 glutSpecialFunc(keyboard_input);
137 trackball(curQuat,0.0,0.0,0.0,0.0);
139 subWin = glutCreateSubWindow(win, 0, 0, 340, 60);
140 glutDisplayFunc(displaySub);
141 glutMouseFunc(mouse_input);
142 glutPassiveMotionFunc(motion_pas);
144 thc->ptf = &forceRedraw;
146 glutMainLoop();
147 return 0;
150 void init(int x,int y,int z)
154 glPolygonMode( GL_FRONT, GL_FILL );
155 glPolygonMode( GL_BACK, GL_LINE );
156 glCullFace( GL_BACK );
158 minesX = &thc->dim[0];
159 minesY = &thc->dim[1];
160 minesZ = &thc->dim[2];
162 sunPosition[0] = 0.0f;
163 sunPosition[1] = 0.0f;
164 sunPosition[2] = (*minesY) * 8 * glut_CUBE_SIZE;
166 cropX_max = last_x = *minesX;
167 cropY_max = last_y = *minesY;
168 cropZ_max = last_z = *minesZ;
170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
173 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
174 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
176 if(!LoadRGBMipmapsUserAlpha(TEXTURE_FILE, GL_RGBA,ALPHA_CONST)) {
177 printf("Error: couldn't load texture image\n");
180 glEnable(GL_TEXTURE_2D);
181 glEnable(GL_LIGHTING);
182 glEnable(GL_DEPTH_TEST);
185 void initLights(void)
187 glEnable(GL_LIGHT0);
188 glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,180);
190 glLightfv(GL_LIGHT0,GL_POSITION, sunPosition );
191 glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,sunDirection);
195 void displaySub(void)
197 glClearColor(0.2, 0.2, 0.2, 1.0);
198 glClear(GL_COLOR_BUFFER_BIT);
199 glColor3f(1, 1, 1);
200 glRasterPos2f(-0.95,0.5);
201 int i,len;
202 char * pom = (char*)malloc(25*sizeof(char));
203 if (cropX_min <= 9) sprintf(pom," %i",cropX_min);
204 else sprintf(pom,"%i",cropX_min);
205 len = strlen(pom);
206 for(i=0;i<7;i++)
207 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strX[i]);
208 for(i=0;i<len;i++)
209 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
211 if (cropX_max <= 9) sprintf(pom," %i",cropX_max);
212 else sprintf(pom,"%i",cropX_max);
213 len = strlen(pom);
215 for(i=7;i<14;i++)
216 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strX[i]);
217 for(i=0;i<len;i++)
218 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
220 glRasterPos2f(-0.95,-0.1);
221 if (cropY_min <= 9) sprintf(pom," %i",cropY_min);
222 else sprintf(pom,"%i",cropY_min);
223 len = strlen(pom);
224 for(i=0;i<7;i++)
225 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strY[i]);
226 for(i=0;i<len;i++)
227 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
229 if (cropY_max <= 9) sprintf(pom," %i",cropY_max);
230 else sprintf(pom,"%i",cropY_max);
231 len = strlen(pom);
232 for(i=7;i<14;i++)
233 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strY[i]);
234 for(i=0;i<len;i++)
235 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
237 glRasterPos2f(-0.95,-0.7);
238 if (cropZ_min <= 9) sprintf(pom," %i",cropZ_min);
239 else sprintf(pom,"%i",cropZ_min);
240 len = strlen(pom);
241 for(i=0;i<7;i++)
242 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strZ[i]);
243 for(i=0;i<len;i++)
244 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
246 if (cropZ_max <= 9) sprintf(pom," %i",cropZ_max);
247 else sprintf(pom,"%i",cropZ_max);
248 len = strlen(pom);
249 for(i=7;i<14;i++)
250 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, strZ[i]);
251 for(i=0;i<len;i++)
252 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
257 if (selectXYZ == 8) glColor3f(1, 0, 0);
258 else glColor3f(1, 1, 0);
259 glRasterPos2f(-0.45,0.5);
260 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
262 if (selectXYZ == 9) glColor3f(1, 0, 0);
263 else glColor3f(1, 1, 0);
264 glRasterPos2f(-0.38,0.5);
265 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
267 if (selectXYZ == 10) glColor3f(1, 0, 0);
268 else glColor3f(1, 1, 0);
269 glRasterPos2f(0.03,0.5);
270 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
272 if (selectXYZ == 11) glColor3f(1, 0, 0);
273 else glColor3f(1, 1, 0);
274 glRasterPos2f(0.10,0.5);
275 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
278 if (selectXYZ == 4) glColor3f(1, 0, 0);
279 else glColor3f(1, 1, 0);
280 glRasterPos2f(-0.45,-0.1);
281 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
283 if (selectXYZ == 5) glColor3f(1, 0, 0);
284 else glColor3f(1, 1, 0);
285 glRasterPos2f(-0.38,-0.1);
286 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
288 if (selectXYZ == 6) glColor3f(1, 0, 0);
289 else glColor3f(1, 1, 0);
290 glRasterPos2f(0.03,-0.1);
291 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
293 if (selectXYZ == 7) glColor3f(1, 0, 0);
294 else glColor3f(1, 1, 0);
295 glRasterPos2f(0.10,-0.1);
296 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
299 if (selectXYZ == 0) glColor3f(1, 0, 0);
300 else glColor3f(1, 1, 0);
301 glRasterPos2f(-0.45,-0.7);
302 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
304 if (selectXYZ == 1) glColor3f(1, 0, 0);
305 else glColor3f(1, 1, 0);
306 glRasterPos2f(-0.38,-0.7);
307 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
309 if (selectXYZ == 2) glColor3f(1, 0, 0);
310 else glColor3f(1, 1, 0);
311 glRasterPos2f(0.03,-0.7);
312 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'+');
314 if (selectXYZ == 3) glColor3f(1, 0, 0);
315 else glColor3f(1, 1, 0);
316 glRasterPos2f(0.10,-0.7);
317 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'-');
319 if (selectXYZ == 12) glColor3f(1, 0, 0);
320 else glColor3f(1, 1, 0);
321 glRasterPos2f(0.25,0.5);
322 sprintf(pom,"SWITCH MODE %i",mode);
323 len = strlen(pom);
324 for(i=0;i<len;i++)
325 glutBitmapCharacter(GLUT_BITMAP_9_BY_15,pom[i]);
329 free(pom);
331 glutSwapBuffers();
334 void display(void)
337 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
339 thc->mutex_lock();
341 if ( last_x != *minesX || last_y != *minesY || last_z != *minesZ )
343 cropX_max = last_x = *minesX;
344 cropY_max = last_y = *minesY;
345 cropZ_max = last_z = *minesZ;
346 glutPostWindowRedisplay(win);
349 glMatrixMode(GL_MODELVIEW);
350 glLoadIdentity();
351 int m = *minesX;
352 if (*minesY > m) m = *minesY;
353 if (*minesZ > m) m = *minesZ;
357 gluLookAt( 0.0, 0.0 , glut_CUBE_SIZE * 6 * m * zoom,
358 0.0,0.0,0.0,
359 0.0, 1.0, 0.0
362 glPushMatrix();
364 if (thc->b != 0) drawMines();
368 glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
369 glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse[0]);
371 glPopMatrix();
373 thc->mutex_unlock();
375 glutSwapBuffers();
380 void reshape(int width,int height)
383 w_width = width;
384 w_height = height;
386 glViewport(0,0,width,height);
388 glMatrixMode(GL_PROJECTION);
389 glLoadIdentity();
390 gluPerspective(60.0,(GLdouble)width/height,0.1,200.0);
392 thc->mutex_lock();
394 glMatrixMode(GL_MODELVIEW);
395 glLoadIdentity();
396 int m = *minesX;
397 if (*minesY > m) m = *minesY;
398 if (*minesZ > m) m = *minesZ;
400 thc->mutex_unlock();
402 gluLookAt( 0.0, 0.0 , glut_CUBE_SIZE * 6 * m * zoom,
403 0.0,0.0,0.0,
404 0.0, 1.0, 0.0
409 void idle(void)
411 glutPostRedisplay();
414 void keyboard_input(int key,int x,int y)
416 if (key == GLUT_KEY_LEFT) zoom += 0.025f;
417 if (key == GLUT_KEY_RIGHT) zoom -= 0.025f;
421 void mouse_input(int button,int state,int x,int y)
424 if( button == GLUT_LEFT_BUTTON )
426 if (state == GLUT_DOWN)
428 switch( selectXYZ )
430 case 12:
431 ++(mode %= 4);
432 break;
433 case 8:
434 if (cropX_min < *minesX-1) cropX_min += 1;
435 break;
436 case 9:
437 if (cropX_min > 0) cropX_min -= 1;
438 break;
439 case 10:
440 if (cropX_max < *minesX) cropX_max += 1;
441 break;
442 case 11:
443 if (cropX_max > 0) cropX_max -= 1;
444 break;
445 case 4:
446 if (cropY_min < *minesY-1) cropY_min += 1;
447 break;
448 case 5:
449 if (cropY_min > 0) cropY_min -= 1;
450 break;
451 case 6:
452 if (cropY_max < *minesY) cropY_max += 1;
453 break;
454 case 7:
455 if (cropY_max > 0) cropY_max -= 1;
456 break;
457 case 0:
458 if (cropZ_min < *minesZ-1) cropZ_min += 1;
459 break;
460 case 1:
461 if (cropZ_min > 0) cropZ_min -= 1;
462 break;
463 case 2:
464 if (cropZ_max < *minesZ) cropZ_max += 1;
465 break;
466 case 3:
467 if (cropZ_max > 0) cropZ_max -= 1;
468 break;
474 glutPostWindowRedisplay(win);
478 void motion(int x, int y)
480 int x1,y1;
481 x1 = x;
482 y1 = y;
483 if (mouse_old_x - x > w_width / 100 ) x = (int)mouse_old_x - w_width / 100;
484 if (mouse_old_x - x < -w_width / 100) x = (int)mouse_old_x + w_width / 100;
486 if (mouse_old_y - y > w_height / 100) y = (int)mouse_old_y - w_height/ 100;
487 if (mouse_old_y - y < -w_height / 100) y = (int)mouse_old_y + w_height / 100;
489 trackball(incQuat, (2.0 * mouse_old_x - w_width) / w_width,
490 (w_height - 2.0 * mouse_old_y) / w_height,
491 (2.0 * x - w_width) / w_width,
492 (w_height - 2.0 * y) / w_height );
495 add_quats(incQuat,curQuat,curQuat);
497 mouse_old_x = x1;
498 mouse_old_y = y1;
500 //glutPostRedisplay();
505 void drawMines1(void)
507 int i,j,k;
508 float m[4][4];
510 glPushMatrix();
514 build_rotmatrix(m,curQuat);
515 glMultMatrixf(&m[0][0]);
517 glDisable(GL_LIGHTING);
518 glDisable(GL_TEXTURE_2D);
520 glBegin(GL_LINES);
521 glColor3f(1.0, 0.0, 0.0);
522 glVertex3f(0.0,0.0,0.0);
523 glVertex3f(glut_CUBE_SIZE * 4 * *minesX,0.0,0.0);
525 glVertex3f(glut_CUBE_SIZE * 4 * *minesX,0.0,0.0);
526 glVertex3f(glut_CUBE_SIZE * 4 * *minesX - 2,2.0,0.0);
527 glVertex3f(glut_CUBE_SIZE * 4 * *minesX,0.0,0.0);
528 glVertex3f(glut_CUBE_SIZE * 4 * *minesX - 2,-2.0,0.0);
530 glColor3f(0.0, 1.0, 0.0);
531 glVertex3f(0.0,0.0,0.0);
532 glVertex3f(0.0,glut_CUBE_SIZE * 4 * *minesY,0.0);
534 glVertex3f(0.0,glut_CUBE_SIZE * 4 * *minesY,0.0);
535 glVertex3f(2.0,glut_CUBE_SIZE * 4 * *minesY-2,0.0);
536 glVertex3f(0.0,glut_CUBE_SIZE * 4 * *minesY,0.0);
537 glVertex3f(-2.0,glut_CUBE_SIZE * 4 * *minesY-2,0.0);
539 glColor3f(0.0, 0.0, 1.0);
540 glVertex3f(0.0,0.0,0.0);
541 glVertex3f(0.0,0.0,glut_CUBE_SIZE * 4 * *minesZ);
543 glVertex3f(0.0,0.0,glut_CUBE_SIZE * 4 * *minesZ);
544 glVertex3f(2.0,0.0,glut_CUBE_SIZE * 4 * *minesZ-2);
545 glVertex3f(0.0,0.0,glut_CUBE_SIZE * 4 * *minesZ);
546 glVertex3f(-2.0,0.0,glut_CUBE_SIZE * 4 * *minesZ-2);
549 glEnd();
551 glEnable(GL_LIGHTING);
552 glEnable(GL_TEXTURE_2D);
554 glEnable (GL_BLEND);
555 glDepthMask (GL_FALSE);
556 glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR);
558 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] );
559 else glTranslated( -2 * (*minesX-1) * glut_CUBE_SIZE,-2 * (*minesY-1) * glut_CUBE_SIZE,-2 * (*minesZ-1) * glut_CUBE_SIZE );
561 glPushAttrib(GL_ALL_ATTRIB_BITS);
563 for (i = 0;i < *minesX ;i++ )
565 if ((i < thc->selected[1]-2 || i > thc->selected[1]+2) && mode > 2 ) continue;
567 if (i < cropX_min || i > cropX_max) continue;
569 for ( j = 0;j < *minesZ; j++ )
571 if ((j < thc->selected[0]-2 || j > thc->selected[0]+2) && mode > 2 ) continue;
572 if (j < cropZ_min || j > cropZ_max) continue;
573 for ( k = 0;k < *minesY; k++ )
575 if ((k < thc->selected[2]-2 || k > thc->selected[2]+2) && mode > 2 ) continue;
576 if (k < cropY_min || k > cropY_max) continue;
577 glPushMatrix();
579 glTranslated( 4 * i * glut_CUBE_SIZE, 4 * k * glut_CUBE_SIZE, 4 * j * glut_CUBE_SIZE );
580 glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
581 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse[0]);
583 if ((thc->selected[0] == j && thc->selected[1] == i && thc->selected[2] == k) || thc->selected[0] == -1 || mode % 2 == 1)
585 glDepthMask (GL_TRUE);
586 glDisable (GL_BLEND);
588 if ((thc->selected[3] == j && thc->selected[4] == i && thc->selected[5] == k) )
589 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse[8]);
590 drawMine(j,i,k);
591 glEnable (GL_BLEND);
592 glDepthMask (GL_FALSE);
593 glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR);
596 else
598 drawMine(j,i,k);
600 glPopMatrix();
606 glPopAttrib();
608 glDepthMask (GL_TRUE);
609 glDisable (GL_BLEND);
611 glPopMatrix();
612 glFlush();
617 void drawMine(int x,int y,int z)
619 int val;
621 //glEnable(GL_TEXTURE_2D);
622 //glDisable( GL_LIGHTING );
624 Field f = thc->b->getField(x,y,z);
626 val = 28;
627 int total_offsetX = 0;
628 int total_offsetY = 3;
630 if ( f.hasMark() )
632 val = 26;
633 goto calc_offset;
635 if ( !f.isCovered() )
637 if ( f.hasMine() )
639 val = 27;
640 goto calc_offset;
642 val = f.getNeighboursCnt() - 1;
643 if (val == -1 ) return;
646 calc_offset:
648 total_offsetX = val % 8;
649 total_offsetY -= (val / 8) % 4;
652 glBegin(GL_QUADS);
654 // front
656 glNormal3f(0.0f, 0.0f, 1.0f);
658 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
659 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
661 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
662 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
664 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
665 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
667 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
668 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
670 // back
671 glNormal3f(0.0f, 0.0f, -1.0f);
673 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
674 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
676 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
677 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
679 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
680 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
682 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
683 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
685 // left
686 glNormal3f(-1.0f, 0.0f, 0.0f);
688 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
689 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
691 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
692 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
694 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
695 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
697 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
698 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
700 // right
701 glNormal3f(1.0f, 0.0f, 0.0f);
703 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
704 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
706 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
707 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
709 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
710 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
712 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
713 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
715 // bottom
716 glNormal3f(0.0f, -1.0f, 0.0f);
718 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
719 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
721 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
722 glVertex3f( -glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
724 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
725 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, -glut_CUBE_SIZE );
727 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
728 glVertex3f( glut_CUBE_SIZE,-glut_CUBE_SIZE, glut_CUBE_SIZE );
730 // top
731 glNormal3f(0.0f, 1.0f, 0.0f);
733 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
734 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
736 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY );
737 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, glut_CUBE_SIZE );
739 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X + TEXTURE_OFFSET_UNIT_X, TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
740 glVertex3f( glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
742 glTexCoord2f(total_offsetX * TEXTURE_OFFSET_UNIT_X,TEXTURE_OFFSET_UNIT_Y * total_offsetY + TEXTURE_OFFSET_UNIT_Y);
743 glVertex3f( -glut_CUBE_SIZE,glut_CUBE_SIZE, -glut_CUBE_SIZE );
748 glEnd();
750 //glDisable(GL_TEXTURE_2D);
751 //glEnable( GL_LIGHTING );
756 void motion_pas(int x,int y)
759 if (y < 54 && y > 37)
761 if (x < 196)
763 if (x > 184 )
765 selectXYZ = 3;
766 return;
768 if (x > 174 )
770 selectXYZ = 2;
771 return;
774 if (x < 115)
776 if (x > 104 )
778 selectXYZ = 1;
779 return;
781 if (x > 94 )
783 selectXYZ = 0;
784 return;
790 if (y < 37 && y > 19)
792 if (x < 196)
794 if (x > 184 )
796 selectXYZ = 7;
797 return;
799 if (x > 174 )
801 selectXYZ = 6;
802 return;
805 if (x < 115)
807 if (x > 104 )
809 selectXYZ = 5;
810 return;
812 if (x > 94 )
814 selectXYZ = 4;
815 return;
821 if (y < 19 && y > 2)
823 if (x < 320 && x > 210)
825 selectXYZ = 12;
826 return;
829 if (x < 196)
831 if (x > 184 )
833 selectXYZ = 11;
834 return;
836 if (x > 174 )
838 selectXYZ = 10;
839 return;
842 if (x < 115)
844 if (x > 104 )
846 selectXYZ = 9;
847 return;
849 if (x > 94 )
851 selectXYZ = 8;
852 return;
857 selectXYZ = -1;