MiniGLUT initial commit
[miniglut] / miniglut.h
1 /*
2 MiniGLUT - minimal GLUT subset without dependencies
3 Copyright (C) 2020  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 #endif
25 #include <GL/gl.h>
26
27 /* mode flags for glutInitDisplayMode */
28 #define GLUT_RGB                        0
29 #define GLUT_RGBA                       0
30 #define GLUT_INDEX                      0x001
31 #define GLUT_SINGLE                     0
32 #define GLUT_DOUBLE                     0x002
33 #define GLUT_ACCUM                      0x004
34 #define GLUT_ALPHA                      0x008
35 #define GLUT_DEPTH                      0x010
36 #define GLUT_STENCIL            0x020
37 #define GLUT_STEREO                     0x040
38 #define GLUT_MULTISAMPLE        0x100
39 #define GLUT_SRGB                       0x200
40
41 enum { GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON };
42 enum { GLUT_UP, GLUT_DOWN };
43 enum { GLUT_NOT_VISIBLE, GLUT_VISIBLE };
44 enum { GLUT_LEFT, GLUT_ENTERED };
45
46 /* cursors */
47 enum {
48         GLUT_CURSOR_INHERIT,
49         GLUT_CURSOR_LEFT_ARROW,
50         GLUT_CURSOR_NONE
51 };
52
53 /* glutGet */
54 enum {
55         GLUT_WINDOW_X,
56         GLUT_WINDOW_Y,
57         GLUT_WINDOW_WIDTH,
58         GLUT_WINDOW_HEIGHT,
59         GLUT_WINDOW_BUFFER_SIZE,
60         GLUT_WINDOW_STENCIL_SIZE,
61         GLUT_WINDOW_DEPTH_SIZE,
62         GLUT_WINDOW_RED_SIZE,
63         GLUT_WINDOW_GREEN_SIZE,
64         GLUT_WINDOW_BLUE_SIZE,
65         GLUT_WINDOW_ALPHA_SIZE,
66         GLUT_WINDOW_DOUBLEBUFFER,
67         GLUT_WINDOW_RGBA,
68         GLUT_WINDOW_NUM_SAMPLES,
69         GLUT_WINDOW_STEREO,
70         GLUT_WINDOW_SRGB,
71         GLUT_WINDOW_CURSOR,
72         GLUT_SCREEN_WIDTH,
73         GLUT_SCREEN_HEIGHT,
74         GLUT_INIT_DISPLAY_MODE,
75         GLUT_INIT_WINDOW_X,
76         GLUT_INIT_WINDOW_Y,
77         GLUT_INIT_WINDOW_WIDTH,
78         GLUT_INIT_WINDOW_HEIGHT,
79         GLUT_ELAPSED_TIME
80 };
81
82 /* returned by glutGetModifiers */
83 #define GLUT_ACTIVE_SHIFT       1
84 #define GLUT_ACTIVE_CTRL        2
85 #define GLUT_ACTIVE_ALT         4
86
87 typedef void (*glut_cb)(void);
88 typedef void (*glut_cb_reshape)(int x, int y);
89 typedef void (*glut_cb_state)(int state);
90 typedef void (*glut_cb_keyb)(unsigned char key, int x, int y);
91 typedef void (*glut_cb_special)(int key, int x, int y);
92 typedef void (*glut_cb_mouse)(int bn, int state, int x, int y);
93 typedef void (*glut_cb_motion)(int x, int y);
94 typedef void (*glut_cb_sbmotion)(int x, int y, int z);
95 typedef void (*glut_cb_sbbutton)(int bn, int state);
96
97
98 void glutInit(int *argc, char **argv);
99 void glutInitWindowPosition(int x, int y);
100 void glutInitWindowSize(int xsz, int ysz);
101 void glutInitDisplayMode(unsigned int mode);
102 void glutCreateWindow(const char *title);
103
104 void glutExit(void);
105 void glutMainLoop(void);
106 void glutMainLoopEvent(void);
107
108 void glutPostRedisplay(void);
109 void glutSwapBuffers(void);
110 void glutPositionWindow(int x, int y);
111 void glutReshapeWindow(int xsz, int ysz);
112 void glutFullScreen(void);
113 void glutSetWindowTitle(const char *title);
114 void glutSetIconTitle(const char *title);
115 void glutSetCursor(int cursor);
116
117 void glutIdleFunc(glut_cb func);
118 void glutDisplayFunc(glut_cb func);
119 void glutReshapeFunc(glut_cb_reshape func);
120 void glutVisibilityFunc(glut_cb_state func);
121 void glutEntryFunc(glut_cb_state func);
122 void glutKeyboardFunc(glut_cb_keyb func);
123 void glutKeyboardUpFunc(glut_cb_keyb func);
124 void glutSpecialFunc(glut_cb_special func);
125 void glutSpecialUpFunc(glut_cb_special func);
126 void glutMouseFunc(glut_cb_mouse func);
127 void glutMotionFunc(glut_cb_motion func);
128 void glutPassiveMotionFunc(glut_cb_motion func);
129 void glutSpaceballMotionFunc(glut_cb_sbmotion func);
130 void glutSpaceballRotateFunc(glut_cb_sbmotion func);
131 void glutSpaceballBittonFunc(glut_cb_sbbutton func);
132
133 int glutGet(unsigned int s);
134 int glutGetModifiers(void);
135 int glutExtensionSupported(char *ext);
136
137 void glutSolidSphere(float rad);
138 void glutWireSphere(float rad);
139 void glutSolidCube(float sz);
140 void glutWireCube(float sz);
141 void glutSolidTorus(float inner_rad, float outer_rad, float sides, float rings);
142 void glutWireTorus(float inner_rad, float outer_rad, float sides, float rings);
143 void glutSolidTeapot(float size);
144 void glutWireTeapot(float size);
145
146 #endif  /* MINIGLUT_H_ */