rev |
line source |
nuclear@0
|
1 #ifndef SGL_H_
|
nuclear@0
|
2 #define SGL_H_
|
nuclear@0
|
3
|
nuclear@40
|
4 #ifdef __APPLE__
|
nuclear@40
|
5 #include <TargetConditionals.h>
|
nuclear@40
|
6
|
nuclear@40
|
7 #if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
|
nuclear@40
|
8 #include <OpenGLES/ES2/gl.h>
|
nuclear@40
|
9 #else /* !iphone */
|
nuclear@40
|
10 #include <OpenGL/gl.h>
|
nuclear@40
|
11 #endif /* iphone/isim */
|
nuclear@40
|
12
|
nuclear@40
|
13 #else
|
nuclear@40
|
14 /* !__APPLE__ */
|
nuclear@40
|
15 #ifdef WIN32
|
nuclear@40
|
16 #include <windows.h>
|
nuclear@40
|
17 #endif /* WIN32 */
|
nuclear@40
|
18
|
nuclear@40
|
19 #include <GL/gl.h>
|
nuclear@40
|
20 #endif /* __APPLE__ */
|
nuclear@40
|
21
|
nuclear@40
|
22
|
nuclear@40
|
23
|
nuclear@0
|
24 #define SGL_DOUBLE 1
|
nuclear@0
|
25 #define SGL_DEPTH 2
|
nuclear@0
|
26 #define SGL_STENCIL 4
|
nuclear@0
|
27 #define SGL_STEREO 8
|
nuclear@4
|
28 #define SGL_MULTISAMPLE 16
|
nuclear@0
|
29
|
nuclear@34
|
30 /* --- callback types ---
|
nuclear@34
|
31 * All event callbacks are entered with the corresponding OpenGL context being current.
|
nuclear@34
|
32 * It is safe to issue OpenGL commands in all callbacks functions, unless explicitly
|
nuclear@34
|
33 * stated otherwise below.
|
nuclear@34
|
34 */
|
nuclear@34
|
35
|
nuclear@34
|
36 /* Create callback is called just after a window and its OpenGL context is created */
|
nuclear@34
|
37 typedef void (*sgl_create_callback_t)(int window);
|
nuclear@39
|
38
|
nuclear@34
|
39 /* Close callback is called before the window and its OpenGL context is destroyed */
|
nuclear@34
|
40 typedef void (*sgl_close_callback_t)(int window);
|
nuclear@39
|
41
|
nuclear@34
|
42 /* The display callback is called whenever the window needs repainting. This is
|
nuclear@34
|
43 * the only place you should perform drawing.
|
nuclear@34
|
44 */
|
nuclear@6
|
45 typedef void (*sgl_display_callback_t)(void);
|
nuclear@39
|
46
|
nuclear@34
|
47 /* Reshape is called whenever the window size changes, and at least once for
|
nuclear@34
|
48 * each newly created window, just after the call to the create callback. */
|
nuclear@34
|
49 typedef void (*sgl_reshape_callback_t)(int width, int height);
|
nuclear@39
|
50
|
nuclear@34
|
51 /* The keyboard callback is called whenever a key is pressed or released */
|
nuclear@34
|
52 typedef void (*sgl_keyboard_callback_t)(int key, int pressed);
|
nuclear@39
|
53
|
nuclear@34
|
54 /* The mouse callback is called whenever a mouse button is pressed or released
|
nuclear@34
|
55 * over the window. The first argument is the touch id for multitouch devices.
|
nuclear@34
|
56 * For regular mouse events it is always 0. */
|
nuclear@34
|
57 typedef void (*sgl_mouse_callback_t)(int id, int button, int pressed, int x, int y);
|
nuclear@39
|
58
|
nuclear@34
|
59 /* The motion callback is called when the user drags the mouse around with any
|
nuclear@34
|
60 * mouse buttons held down. The first argument is the touch id for multitouch
|
nuclear@34
|
61 * devices. */
|
nuclear@34
|
62 typedef void (*sgl_motion_callback_t)(int id, int x, int y);
|
nuclear@39
|
63
|
nuclear@34
|
64 /* Passive gets called whenever the mouse is moved without any button being
|
nuclear@34
|
65 * held. The first argument is the touch id for multitouch devices.
|
nuclear@34
|
66 *
|
nuclear@34
|
67 * Avoid setting this callback unless absolutely necessary, because it will
|
nuclear@34
|
68 * generate a huge volume of events whenever the mouse moves over the window. */
|
nuclear@34
|
69 typedef void (*sgl_passive_callback_t)(int id, int x, int y);
|
nuclear@39
|
70
|
nuclear@39
|
71 /* The space control callback gets called when we receive input from spatial
|
nuclear@39
|
72 * controllers such as spaceballs, accelerometers, and gyroscopes
|
nuclear@39
|
73 */
|
nuclear@39
|
74 typedef void (*sgl_space_callback_t)(int x, int y, int z, int rx, int ry, int rz);
|
nuclear@39
|
75
|
nuclear@39
|
76 /* The button callback gets called whenever we have button presses/releases
|
nuclear@39
|
77 * from special hardware buttons such as the home button on mobile devices,
|
nuclear@39
|
78 * buttons on spaceballs, etc.
|
nuclear@39
|
79 */
|
nuclear@39
|
80 typedef void (*sgl_button_callback_t)(int bn, int pressed);
|
nuclear@39
|
81
|
nuclear@34
|
82 /* Setting the idle callback will change the behaviour of the library. Instead
|
nuclear@34
|
83 * of blocking, to wait for events from the window system, it will poll for
|
nuclear@34
|
84 * events and after processing them will call this idle callback.
|
nuclear@34
|
85 *
|
nuclear@34
|
86 * Avoid setting this callback unless absolutely necessary, because it will
|
nuclear@34
|
87 * turn your program into busy-looping mode, consuming all possible CPU time
|
nuclear@34
|
88 * allocated to it by the system. */
|
nuclear@6
|
89 typedef void (*sgl_idle_callback_t)(void);
|
nuclear@6
|
90
|
nuclear@34
|
91 /* symbolic names for each callback */
|
nuclear@0
|
92 enum {
|
nuclear@0
|
93 SGL_CREATE,
|
nuclear@0
|
94 SGL_CLOSE,
|
nuclear@0
|
95 SGL_DISPLAY,
|
nuclear@0
|
96 SGL_RESHAPE,
|
nuclear@0
|
97 SGL_KEYBOARD,
|
nuclear@0
|
98 SGL_MOUSE,
|
nuclear@0
|
99 SGL_MOTION,
|
nuclear@0
|
100 SGL_PASSIVE,
|
nuclear@39
|
101 SGL_SPACE,
|
nuclear@39
|
102 SGL_BUTTON,
|
nuclear@0
|
103 SGL_IDLE,
|
nuclear@0
|
104
|
nuclear@0
|
105 SGL_NUM_CALLBACKS
|
nuclear@0
|
106 };
|
nuclear@0
|
107
|
nuclear@5
|
108 enum {
|
nuclear@5
|
109 SGL_LEFT_BUTTON,
|
nuclear@5
|
110 SGL_MIDDLE_BUTTON,
|
nuclear@5
|
111 SGL_RIGHT_BUTTON
|
nuclear@5
|
112 };
|
nuclear@5
|
113
|
nuclear@7
|
114 /* these values happen to coincide with X11 keysyms */
|
nuclear@7
|
115 #define SGL_KEY_LSHIFT 0xffe1
|
nuclear@7
|
116 #define SGL_KEY_RSHIFT 0xffe2
|
nuclear@7
|
117 #define SGL_KEY_LCONTROL 0xffe3
|
nuclear@7
|
118 #define SGL_KEY_RCONTROL 0xffe4
|
nuclear@7
|
119 #define SGL_KEY_LALT 0xffe9
|
nuclear@7
|
120 #define SGL_KEY_RALT 0xffea
|
nuclear@7
|
121
|
nuclear@7
|
122 /* for the sgl_modifiers bitmask */
|
nuclear@7
|
123 #define SGL_MOD_SHIFT 1
|
nuclear@7
|
124 #define SGL_MOD_CONTROL 2
|
nuclear@7
|
125 #define SGL_MOD_ALT 4
|
nuclear@7
|
126
|
nuclear@1
|
127 int sgl_init(void);
|
nuclear@5
|
128 void sgl_quit(void);
|
nuclear@1
|
129
|
nuclear@4
|
130 int sgl_set_video_mode(int xsz, int ysz);
|
nuclear@4
|
131 int sgl_get_video_mode(int *xsz, int *ysz);
|
nuclear@0
|
132
|
nuclear@4
|
133 int sgl_create_window(int xsz, int ysz, unsigned int mode);
|
nuclear@1
|
134 void sgl_close_window(int win);
|
nuclear@0
|
135
|
nuclear@4
|
136 int sgl_set_active(int id);
|
nuclear@4
|
137 int sgl_set_title(const char *str);
|
nuclear@4
|
138
|
nuclear@5
|
139 void sgl_redisplay(void);
|
nuclear@5
|
140 void sgl_swap_buffers(void);
|
nuclear@5
|
141
|
nuclear@7
|
142 int sgl_modifiers(void);
|
nuclear@7
|
143
|
nuclear@4
|
144 int sgl_process_events(void);
|
nuclear@5
|
145 void sgl_event_loop(void);
|
nuclear@4
|
146
|
nuclear@0
|
147 int sgl_push_callbacks(void);
|
nuclear@0
|
148 int sgl_pop_callbacks(void);
|
nuclear@0
|
149 void sgl_clear_callbacks(void);
|
nuclear@4
|
150 void sgl_set_callback(int idx, void (*func)());
|
nuclear@4
|
151 void (*sgl_get_callback(int idx))();
|
nuclear@0
|
152
|
nuclear@6
|
153 void sgl_create_callback(sgl_create_callback_t func);
|
nuclear@6
|
154 void sgl_close_callback(sgl_close_callback_t func);
|
nuclear@6
|
155 void sgl_display_callback(sgl_display_callback_t func);
|
nuclear@6
|
156 void sgl_reshape_callback(sgl_reshape_callback_t func);
|
nuclear@6
|
157 void sgl_keyboard_callback(sgl_keyboard_callback_t func);
|
nuclear@6
|
158 void sgl_mouse_callback(sgl_mouse_callback_t func);
|
nuclear@6
|
159 void sgl_motion_callback(sgl_motion_callback_t func);
|
nuclear@6
|
160 void sgl_passive_callback(sgl_passive_callback_t func);
|
nuclear@39
|
161 void sgl_space_callback(sgl_space_callback_t func);
|
nuclear@39
|
162 void sgl_button_callback(sgl_button_callback_t func);
|
nuclear@6
|
163 void sgl_idle_callback(sgl_idle_callback_t func);
|
nuclear@6
|
164
|
nuclear@0
|
165 #endif /* SGL_H_ */
|