sgl

view include/sgl.h @ 40:f7de32814f34

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