started macos port by adapting the old SGL code
[miniglut] / miniglut.h
1 /*
2 MiniGLUT - minimal GLUT subset without dependencies
3 Copyright (C) 2020-2022  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef MINIGLUT_H_
19 #define MINIGLUT_H_
20
21 #ifdef _WIN32
22 #define WIN32_LEAN_AND_MEAN 1
23 #include <windows.h>
24
25 #ifdef _MSC_VER
26 #pragma comment (lib, "opengl32")
27 #ifndef MINIGLUT_NO_WINMM
28 #pragma comment (lib, "winmm")
29 #endif
30 #endif  /* MSVC */
31
32 #endif
33
34 #ifdef __APPLE__
35 #include <OpenGL/gl.h>
36 #else
37 #include <GL/gl.h>
38 #endif
39
40 /* mode flags for glutInitDisplayMode */
41 #define GLUT_RGB                        0
42 #define GLUT_RGBA                       0
43 #define GLUT_INDEX                      0x001
44 #define GLUT_SINGLE                     0
45 #define GLUT_DOUBLE                     0x002
46 #define GLUT_ACCUM                      0x004
47 #define GLUT_ALPHA                      0x008
48 #define GLUT_DEPTH                      0x010
49 #define GLUT_STENCIL            0x020
50 #define GLUT_STEREO                     0x040
51 #define GLUT_MULTISAMPLE        0x100
52 #define GLUT_SRGB                       0x200
53
54 enum { GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON };
55 enum { GLUT_UP, GLUT_DOWN };
56 enum { GLUT_NOT_VISIBLE, GLUT_VISIBLE };
57 enum { GLUT_LEFT, GLUT_ENTERED };
58
59 /* cursors */
60 enum {
61         GLUT_CURSOR_INHERIT,
62         GLUT_CURSOR_LEFT_ARROW,
63         GLUT_CURSOR_NONE
64 };
65
66 /* glutGet */
67 enum {
68         GLUT_WINDOW_X,
69         GLUT_WINDOW_Y,
70         GLUT_WINDOW_WIDTH,
71         GLUT_WINDOW_HEIGHT,
72         GLUT_WINDOW_BUFFER_SIZE,
73         GLUT_WINDOW_STENCIL_SIZE,
74         GLUT_WINDOW_DEPTH_SIZE,
75         GLUT_WINDOW_RED_SIZE,
76         GLUT_WINDOW_GREEN_SIZE,
77         GLUT_WINDOW_BLUE_SIZE,
78         GLUT_WINDOW_ALPHA_SIZE,
79         GLUT_WINDOW_DOUBLEBUFFER,
80         GLUT_WINDOW_RGBA,
81         GLUT_WINDOW_NUM_SAMPLES,
82         GLUT_WINDOW_STEREO,
83         GLUT_WINDOW_SRGB,
84         GLUT_WINDOW_CURSOR,
85         GLUT_SCREEN_WIDTH,
86         GLUT_SCREEN_HEIGHT,
87         GLUT_INIT_DISPLAY_MODE,
88         GLUT_INIT_WINDOW_X,
89         GLUT_INIT_WINDOW_Y,
90         GLUT_INIT_WINDOW_WIDTH,
91         GLUT_INIT_WINDOW_HEIGHT,
92         GLUT_ELAPSED_TIME,
93         GLUT_WINDOW_COLORMAP_SIZE
94 };
95
96 enum {
97         GLUT_RED,
98         GLUT_GREEN,
99         GLUT_BLUE
100 };
101
102 enum {
103         GLUT_KEY_HOME = 0xff50,
104         GLUT_KEY_LEFT = 0xff51,
105         GLUT_KEY_UP,
106         GLUT_KEY_RIGHT,
107         GLUT_KEY_DOWN,
108         GLUT_KEY_PAGE_UP,
109         GLUT_KEY_PAGE_DOWN,
110         GLUT_KEY_END = 0xff57,
111         GLUT_KEY_INSERT = 0xff63,
112         GLUT_KEY_F1 = 0xffbe,
113         GLUT_KEY_F2,
114         GLUT_KEY_F3,
115         GLUT_KEY_F4,
116         GLUT_KEY_F5,
117         GLUT_KEY_F6,
118         GLUT_KEY_F7,
119         GLUT_KEY_F8,
120         GLUT_KEY_F9,
121         GLUT_KEY_F10,
122         GLUT_KEY_F11,
123         GLUT_KEY_F12
124 };
125
126 /* returned by glutGetModifiers */
127 #define GLUT_ACTIVE_SHIFT       1
128 #define GLUT_ACTIVE_CTRL        4
129 #define GLUT_ACTIVE_ALT         8
130
131 enum {
132         GLUT_KEY_REPEAT_OFF,
133         GLUT_KEY_REPEAT_ON
134 };
135 #define GLUT_KEY_REPEAT_DEFAULT GLUT_KEY_REPEAT_ON
136
137 typedef void (*glut_cb)(void);
138 typedef void (*glut_cb_reshape)(int x, int y);
139 typedef void (*glut_cb_state)(int state);
140 typedef void (*glut_cb_keyb)(unsigned char key, int x, int y);
141 typedef void (*glut_cb_special)(int key, int x, int y);
142 typedef void (*glut_cb_mouse)(int bn, int state, int x, int y);
143 typedef void (*glut_cb_motion)(int x, int y);
144 typedef void (*glut_cb_sbmotion)(int x, int y, int z);
145 typedef void (*glut_cb_sbbutton)(int bn, int state);
146
147 #ifdef __cplusplus
148 extern "C" {
149 #endif
150
151 void glutInit(int *argc, char **argv);
152 void glutInitWindowPosition(int x, int y);
153 void glutInitWindowSize(int xsz, int ysz);
154 void glutInitDisplayMode(unsigned int mode);
155 void glutCreateWindow(const char *title);
156
157 void glutExit(void);
158 void glutMainLoop(void);
159 void glutMainLoopEvent(void);
160
161 void glutPostRedisplay(void);
162 void glutSwapBuffers(void);
163 void glutPositionWindow(int x, int y);
164 void glutReshapeWindow(int xsz, int ysz);
165 void glutFullScreen(void);
166 void glutSetWindowTitle(const char *title);
167 void glutSetIconTitle(const char *title);
168 void glutSetCursor(int cursor);
169 void glutSetColor(int idx, float r, float g, float b);
170 void glutWarpPointer(int x, int y);
171 float glutGetColor(int idx, int comp);
172
173 void glutIgnoreKeyRepeat(int ignore);
174 void glutSetKeyRepeat(int repmode);
175
176 void glutIdleFunc(glut_cb func);
177 void glutDisplayFunc(glut_cb func);
178 void glutReshapeFunc(glut_cb_reshape func);
179 void glutVisibilityFunc(glut_cb_state func);
180 void glutEntryFunc(glut_cb_state func);
181 void glutKeyboardFunc(glut_cb_keyb func);
182 void glutKeyboardUpFunc(glut_cb_keyb func);
183 void glutSpecialFunc(glut_cb_special func);
184 void glutSpecialUpFunc(glut_cb_special func);
185 void glutMouseFunc(glut_cb_mouse func);
186 void glutMotionFunc(glut_cb_motion func);
187 void glutPassiveMotionFunc(glut_cb_motion func);
188 void glutSpaceballMotionFunc(glut_cb_sbmotion func);
189 void glutSpaceballRotateFunc(glut_cb_sbmotion func);
190 void glutSpaceballButtonFunc(glut_cb_sbbutton func);
191
192 int glutGet(unsigned int s);
193 int glutGetModifiers(void);
194 int glutExtensionSupported(char *ext);
195
196 void glutSolidSphere(float rad, int slices, int stacks);
197 void glutWireSphere(float rad, int slices, int stacks);
198 void glutSolidCube(float sz);
199 void glutWireCube(float sz);
200 void glutSolidCone(float base, float height, int slices, int stacks);
201 void glutWireCone(float base, float height, int slices, int stacks);
202 void glutSolidCylinder(float rad, float height, int slices, int stacks);
203 void glutSolidTorus(float inner_rad, float outer_rad, int sides, int rings);
204 void glutWireTorus(float inner_rad, float outer_rad, int sides, int rings);
205 void glutSolidTeapot(float size);
206 void glutWireTeapot(float size);
207
208 #ifdef __cplusplus
209 }       /* extern "C" */
210 #endif
211
212 #endif  /* MINIGLUT_H_ */