home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / system_glut.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-13  |  2.3 KB  |  125 lines  |  [TEXT/CWIE]

  1. /* system specific functions (basically, an SDL wrapper) */
  2.  
  3. #include "system.h"
  4.  
  5. static int win_x, win_y;
  6. static int width, height;
  7. static int flags;
  8. static unsigned char fullscreen;
  9. static callbacks *current = 0;
  10.  
  11. void SystemExit() {
  12.   exit(0);
  13. }
  14.  
  15. void SystemInit(int *argc, char **argv) {
  16.   glutInit(argc, argv);
  17.   /* atexit(SystemExit()); */
  18. }
  19.  
  20. void SystemPostRedisplay() {
  21.   glutPostRedisplay();
  22. }
  23.  
  24. int SystemGetElapsedTime() {
  25. #ifdef WIN32
  26.     return timeGetTime();
  27. #else
  28.   return glutGet(GLUT_ELAPSED_TIME);
  29. #endif
  30. }
  31.  
  32. void SystemSwapBuffers() {
  33.   glutSwapBuffers();
  34. }
  35.  
  36. void SystemWarpPointer(int x, int y) {
  37.   glutWarpPointer(x, y);
  38. }
  39.  
  40. void SystemHidePointer() {
  41.   glutSetCursor(GLUT_CURSOR_NONE);
  42. }
  43.  
  44. void SystemUnhidePointer() {
  45.   glutSetCursor(GLUT_CURSOR_INHERIT);
  46. }
  47.  
  48. void SystemMainLoop() {
  49.   glutMainLoop();
  50. }
  51.  
  52. void SystemMouse(int buttons, int state, int x, int y) {
  53.   if(current)
  54.     if(current->mouse != NULL)
  55.       current->mouse(buttons, state, x, y);
  56. }
  57.  
  58. void SystemMouseMotion(int x, int y) {
  59.   if(current)
  60.     if(current->mouseMotion != NULL)
  61.       current->mouseMotion(x, y);
  62. }
  63.  
  64. void SystemKeyboard(unsigned char key, int x, int y) {
  65.   if(current)
  66.     current->keyboard(key, x, y);
  67. }
  68.  
  69. void SystemSpecial(int key, int x, int y) {
  70.   if(current)
  71.     current->keyboard(key, x, y);
  72. }
  73.   
  74. void SystemRegisterCallbacks(callbacks *cb) {
  75.   current = cb;
  76.   glutIdleFunc(cb->idle);
  77.   glutDisplayFunc(cb->display);
  78.   glutKeyboardFunc(SystemKeyboard);
  79.   glutSpecialFunc(SystemKeyboard);
  80.   glutMouseFunc(SystemMouse);
  81.   glutMotionFunc(SystemMouseMotion);
  82.   glutPassiveMotionFunc(SystemMouseMotion);
  83. }
  84.  
  85. void SystemInitWindow(int x, int y, int w, int h) {
  86.   win_x = x;
  87.   win_y = y;
  88.   width = w;
  89.   height = h;
  90. }
  91.  
  92. void SystemInitDisplayMode(int f, unsigned char full) {
  93.   flags = f;
  94.   fullscreen = full;
  95. }
  96.  
  97. int SystemCreateWindow(char *name) {
  98.   if(fullscreen) {
  99.     // do glut game mode stuff
  100.   } else {
  101.     glutInitWindowPosition(win_x, win_y);  
  102.     glutInitWindowSize(width, height);
  103.     glutInitDisplayMode(flags);
  104.     return glutCreateWindow(name);
  105.   }
  106.   return 0;
  107. }
  108.  
  109. void SystemDestroyWindow(int id) {
  110.   glutDestroyWindow(id);
  111. }
  112.  
  113. void SystemReshapeFunc(void(*reshape)(int, int)) {
  114.   glutReshapeFunc(reshape);
  115. }
  116.  
  117. extern char* SystemGetKeyName(int key) {
  118.   char *buf;
  119.  
  120.   buf = malloc(2);
  121.   buf[0] = (char)key;
  122.   buf[1] = 0;
  123.   return buf;
  124. }  
  125.