#ifdef _WIN32 # include # include # include # define pthread_t int #else # ifdef OSX_ # include # else # include # endif # include // for threads in linux # include # include # include # include #endif #include #include #include "config.h" #include "pixel.h" #include "programm.h" #include "menu.h" #include "tetris/logic.h" #include "trackball.h" #include "snake.h" #include "stonefly.h" #include "scrolltext.h" unsigned char fakeport; jmp_buf newmode_jmpbuf; volatile unsigned char oldMode, oldOldmode, mode; extern unsigned char waitForFire; int WindWidth, WindHeight; unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES]; unsigned char joystick; float view_rotx = 0, view_roty = 0, view_rotz = 0; int win; pthread_t simthread; GLUquadric* quad; void drawLED(int color, float pos_x, float pos_y, float pos_z) { glPushMatrix(); glTranslatef(pos_x, pos_y, pos_z); glCallList(color); glPopMatrix(); } void display(void){ int x, y, z, level, color; tbReshape(WindWidth, WindHeight); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(NUM_COLS*2., 0., NUM_ROWS*2.); tbMatrix(); glRotatef(view_rotx, 1.0, 0.0, 0.0); glRotatef(view_roty, 0.0, 1.0, 0.0); glRotatef(view_rotz, 0.0, 0.0, 1.0); glTranslatef(-NUM_COLS*2, 0., -NUM_ROWS*2.); for (x = 0; x < 1; x++) { for (y = 0; y < NUM_COLS; y++) { for (z = 0; z < NUM_ROWS; z++) { color = 0; for (level = 0; level < NUMPLANE; level++) { if (pixmap[level][z%NUM_ROWS][y/8] & (1 << y % 8)) { color = level+1; } } drawLED(color, (float)y*4.0, (float)x*4.0, (float)(NUM_ROWS-1-z)*4.0); } } } glPopMatrix(); glutSwapBuffers(); #ifdef _WIN32 Sleep(10); #else usleep(20000); #endif joystick = 255; } void keyboard(unsigned char key, int x, int y){ switch (key) { case 'q': printf("Quit\n"); glutDestroyWindow(win); exit(0); break; case ' ': fakeport |= 0x01; break; case 'a': fakeport |= 0x02; break; case 'd': fakeport |= 0x04; break; case 's': fakeport |= 0x08; break; case 'w': fakeport |= 0x10; break; } } void keyboardup(unsigned char key, int x, int y){ switch (key) { case ' ': fakeport &= ~0x01; break; case 'a': fakeport &= ~0x02; break; case 'd': fakeport &= ~0x04; break; case 's': fakeport &= ~0x08; break; case 'w': fakeport &= ~0x10; break; } } void mouse(int button, int state, int x, int y) { tbMouse(button, state, x, y); } void motion(int x, int y) { tbMotion(x, y); } void reshape(int width, int height) { tbReshape(width, height); glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (float)WindWidth/(float)WindWidth, 5., 1000.); gluLookAt(NUM_ROWS*2., NUM_ROWS*2.+50., NUM_COLS*2., NUM_ROWS*2., NUM_ROWS*2., NUM_COLS*2., 0.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); WindWidth = width; WindHeight = height; } /* change view angle */ static void special(int k, int x, int y) { switch (k) { case GLUT_KEY_UP: view_rotx += 5.0; break; case GLUT_KEY_DOWN: view_rotx -= 5.0; break; case GLUT_KEY_LEFT: view_rotz += 5.0; break; case GLUT_KEY_RIGHT: view_rotz -= 5.0; break; default: return; } glutPostRedisplay(); } /* void timf(int value) { glutPostRedisplay(); glutTimerFunc(1, timf, 0); }*/ void *display_loop(void * unused) { unsigned char mode;;; mode = setjmp(newmode_jmpbuf); oldOldmode = oldMode; waitForFire = 1; scrolltext("