File: system_glut.c

package info (click to toggle)
gltron 0.61-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,948 kB
  • ctags: 1,175
  • sloc: ansic: 7,580; perl: 168; makefile: 149; sh: 15
file content (124 lines) | stat: -rw-r--r-- 2,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* system specific functions (basically, an SDL wrapper) */

#include "system.h"

static int win_x, win_y;
static int width, height;
static int flags;
static unsigned char fullscreen;
static callbacks *current = 0;

void SystemExit() {
  exit(0);
}

void SystemInit(int *argc, char **argv) {
  glutInit(argc, argv);
  /* atexit(SystemExit()); */
}

void SystemPostRedisplay() {
  glutPostRedisplay();
}

int SystemGetElapsedTime() {
#ifdef WIN32
	return timeGetTime();
#else
  return glutGet(GLUT_ELAPSED_TIME);
#endif
}

void SystemSwapBuffers() {
  glutSwapBuffers();
}

void SystemWarpPointer(int x, int y) {
  glutWarpPointer(x, y);
}

void SystemHidePointer() {
  glutSetCursor(GLUT_CURSOR_NONE);
}

void SystemUnhidePointer() {
  glutSetCursor(GLUT_CURSOR_INHERIT);
}

void SystemMainLoop() {
  glutMainLoop();
}

void SystemMouse(int buttons, int state, int x, int y) {
  if(current)
    if(current->mouse != NULL)
      current->mouse(buttons, state, x, y);
}

void SystemMouseMotion(int x, int y) {
  if(current)
    if(current->mouseMotion != NULL)
      current->mouseMotion(x, y);
}

void SystemKeyboard(unsigned char key, int x, int y) {
  if(current)
    current->keyboard(key, x, y);
}

void SystemSpecial(int key, int x, int y) {
  if(current)
    current->keyboard(key, x, y);
}
  
void SystemRegisterCallbacks(callbacks *cb) {
  current = cb;
  glutIdleFunc(cb->idle);
  glutDisplayFunc(cb->display);
  glutKeyboardFunc(SystemKeyboard);
  glutSpecialFunc(SystemKeyboard);
  glutMouseFunc(SystemMouse);
  glutMotionFunc(SystemMouseMotion);
  glutPassiveMotionFunc(SystemMouseMotion);
}

void SystemInitWindow(int x, int y, int w, int h) {
  win_x = x;
  win_y = y;
  width = w;
  height = h;
}

void SystemInitDisplayMode(int f, unsigned char full) {
  flags = f;
  fullscreen = full;
}

int SystemCreateWindow(char *name) {
  if(fullscreen) {
    // do glut game mode stuff
  } else {
    glutInitWindowPosition(win_x, win_y);  
    glutInitWindowSize(width, height);
    glutInitDisplayMode(flags);
    return glutCreateWindow(name);
  }
  return 0;
}

void SystemDestroyWindow(int id) {
  glutDestroyWindow(id);
}

void SystemReshapeFunc(void(*reshape)(int, int)) {
  glutReshapeFunc(reshape);
}

extern char* SystemGetKeyName(int key) {
  char *buf;

  buf = malloc(2);
  buf[0] = (char)key;
  buf[1] = 0;
  return buf;
}