sgl

view include/sgl.h @ 34:9841c90ec769

added some comments in the header file
author John Tsiombikas <nuclear@mutantstargoat.com>
date Mon, 25 Jun 2012 00:39:46 +0300
parents edbfc96fe80d
children e1a27aa24956
line source
1 #ifndef SGL_H_
2 #define SGL_H_
4 #define SGL_DOUBLE 1
5 #define SGL_DEPTH 2
6 #define SGL_STENCIL 4
7 #define SGL_STEREO 8
8 #define SGL_MULTISAMPLE 16
10 /* --- callback types ---
11 * All event callbacks are entered with the corresponding OpenGL context being current.
12 * It is safe to issue OpenGL commands in all callbacks functions, unless explicitly
13 * stated otherwise below.
14 */
16 /* Create callback is called just after a window and its OpenGL context is created */
17 typedef void (*sgl_create_callback_t)(int window);
18 /* Close callback is called before the window and its OpenGL context is destroyed */
19 typedef void (*sgl_close_callback_t)(int window);
20 /* The display callback is called whenever the window needs repainting. This is
21 * the only place you should perform drawing.
22 */
23 typedef void (*sgl_display_callback_t)(void);
24 /* Reshape is called whenever the window size changes, and at least once for
25 * each newly created window, just after the call to the create callback. */
26 typedef void (*sgl_reshape_callback_t)(int width, int height);
27 /* The keyboard callback is called whenever a key is pressed or released */
28 typedef void (*sgl_keyboard_callback_t)(int key, int pressed);
29 /* The mouse callback is called whenever a mouse button is pressed or released
30 * over the window. The first argument is the touch id for multitouch devices.
31 * For regular mouse events it is always 0. */
32 typedef void (*sgl_mouse_callback_t)(int id, int button, int pressed, int x, int y);
33 /* The motion callback is called when the user drags the mouse around with any
34 * mouse buttons held down. The first argument is the touch id for multitouch
35 * devices. */
36 typedef void (*sgl_motion_callback_t)(int id, int x, int y);
37 /* Passive gets called whenever the mouse is moved without any button being
38 * held. The first argument is the touch id for multitouch devices.
39 *
40 * Avoid setting this callback unless absolutely necessary, because it will
41 * generate a huge volume of events whenever the mouse moves over the window. */
42 typedef void (*sgl_passive_callback_t)(int id, int x, int y);
43 /* Setting the idle callback will change the behaviour of the library. Instead
44 * of blocking, to wait for events from the window system, it will poll for
45 * events and after processing them will call this idle callback.
46 *
47 * Avoid setting this callback unless absolutely necessary, because it will
48 * turn your program into busy-looping mode, consuming all possible CPU time
49 * allocated to it by the system. */
50 typedef void (*sgl_idle_callback_t)(void);
52 /* symbolic names for each callback */
53 enum {
54 SGL_CREATE,
55 SGL_CLOSE,
56 SGL_DISPLAY,
57 SGL_RESHAPE,
58 SGL_KEYBOARD,
59 SGL_MOUSE,
60 SGL_MOTION,
61 SGL_PASSIVE,
62 SGL_IDLE,
64 SGL_NUM_CALLBACKS
65 };
67 enum {
68 SGL_LEFT_BUTTON,
69 SGL_MIDDLE_BUTTON,
70 SGL_RIGHT_BUTTON
71 };
73 /* these values happen to coincide with X11 keysyms */
74 #define SGL_KEY_LSHIFT 0xffe1
75 #define SGL_KEY_RSHIFT 0xffe2
76 #define SGL_KEY_LCONTROL 0xffe3
77 #define SGL_KEY_RCONTROL 0xffe4
78 #define SGL_KEY_LALT 0xffe9
79 #define SGL_KEY_RALT 0xffea
81 /* for the sgl_modifiers bitmask */
82 #define SGL_MOD_SHIFT 1
83 #define SGL_MOD_CONTROL 2
84 #define SGL_MOD_ALT 4
86 int sgl_init(void);
87 void sgl_quit(void);
89 int sgl_set_video_mode(int xsz, int ysz);
90 int sgl_get_video_mode(int *xsz, int *ysz);
92 int sgl_create_window(int xsz, int ysz, unsigned int mode);
93 void sgl_close_window(int win);
95 int sgl_set_active(int id);
96 int sgl_set_title(const char *str);
98 void sgl_redisplay(void);
99 void sgl_swap_buffers(void);
101 int sgl_modifiers(void);
103 int sgl_process_events(void);
104 void sgl_event_loop(void);
106 int sgl_push_callbacks(void);
107 int sgl_pop_callbacks(void);
108 void sgl_clear_callbacks(void);
109 void sgl_set_callback(int idx, void (*func)());
110 void (*sgl_get_callback(int idx))();
112 void sgl_create_callback(sgl_create_callback_t func);
113 void sgl_close_callback(sgl_close_callback_t func);
114 void sgl_display_callback(sgl_display_callback_t func);
115 void sgl_reshape_callback(sgl_reshape_callback_t func);
116 void sgl_keyboard_callback(sgl_keyboard_callback_t func);
117 void sgl_mouse_callback(sgl_mouse_callback_t func);
118 void sgl_motion_callback(sgl_motion_callback_t func);
119 void sgl_passive_callback(sgl_passive_callback_t func);
120 void sgl_idle_callback(sgl_idle_callback_t func);
122 #endif /* SGL_H_ */