1 #include <GL/freeglut.h>
2 #include "nexus3d_impl.h"
5 static void winclose(void);
6 static void display(void);
7 static void idle(void);
8 static void reshape(int x, int y);
9 static void keydown(unsigned char key, int x, int y);
10 static void keyup(unsigned char key, int x, int y);
11 static void skeydown(int key, int x, int y);
12 static void skeyup(int key, int x, int y);
13 static void mouse(int bn, int st, int x, int y);
14 static void motion(int x, int y);
16 static int quit, have_idle;
19 int nex_initgfx(int xsz, int ysz, enum nex_gfxflags flags)
21 static char *fake_argv[] = {"nexus3d", 0};
22 static int fake_argc = 1;
23 unsigned int glut_flags;
25 if(flags & NEX_GFX_DEBUG) {
26 nex_apicfg.gl.flags |= NEX_OPENGL_DEBUG;
29 glut_flags = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_SRGB;
30 if(flags & NEX_GFX_STENCIL) {
31 glut_flags |= GLUT_STENCIL;
33 if(flags & NEX_GFX_FSAA) {
34 glut_flags |= GLUT_MULTISAMPLE;
36 if(flags & NEX_GFX_STEREO) {
37 glut_flags |= GLUT_STEREO;
40 glutInit(&fake_argc, fake_argv);
41 glutInitWindowSize(xsz, ysz);
42 glutInitDisplayMode(glut_flags);
44 if(nex_apicfg.gl.flags & NEX_OPENGL_DEBUG) {
45 glutInitContextFlags(GLUT_DEBUG);
47 if(nex_apicfg.gl.ver_major > 1) {
48 glutInitContextVersion(3, 3);
49 if(nex_apicfg.gl.flags & NEX_OPENGL_COMPAT) {
50 glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
52 glutInitContextProfile(GLUT_CORE_PROFILE);
56 glutCreateWindow("nexus3d engine");
58 glutCloseFunc(winclose);
59 glutDisplayFunc(display);
60 glutReshapeFunc(reshape);
61 glutKeyboardFunc(keydown);
62 glutKeyboardUpFunc(keyup);
63 glutSpecialFunc(skeydown);
64 glutSpecialUpFunc(skeyup);
66 glutMotionFunc(motion);
78 void nex_closegfx(void)
82 int nex_evloop_wait(void)
93 int nex_evloop_poll(void)
104 void nex_swap_buffers(void)
109 void nex_redisplay(void)
114 static void winclose(void)
119 static void display(void)
122 nex_cb.display(nex_cb.display_cls);
126 static void idle(void)
131 static void reshape(int x, int y)
134 nex_cb.reshape(x, y, nex_cb.reshape_cls);
138 static void keydown(unsigned char key, int x, int y)
141 nex_cb.key(key, 1, nex_cb.key_cls);
145 static void keyup(unsigned char key, int x, int y)
148 nex_cb.key(key, 0, nex_cb.key_cls);
152 static int translate_skey(int key)
160 return NEX_KEY_RIGHT;
163 case GLUT_KEY_PAGE_UP:
165 case GLUT_KEY_PAGE_DOWN:
166 return NEX_KEY_PGDOWN;
171 case GLUT_KEY_INSERT:
174 if(key >= GLUT_KEY_F1 && key <= GLUT_KEY_F12) {
175 return NEX_KEY_F1 + (key - GLUT_KEY_F1);
181 static void skeydown(int key, int x, int y)
183 if(nex_cb.key && (key = translate_skey(key)) > 0) {
184 nex_cb.key(key, 1, nex_cb.key_cls);
188 static void skeyup(int key, int x, int y)
190 if(nex_cb.key && (key = translate_skey(key)) > 0) {
191 nex_cb.key(key, 0, nex_cb.key_cls);
195 static void mouse(int bn, int st, int x, int y)
198 int idx = bn - GLUT_LEFT_BUTTON;
199 int press = bn == GLUT_DOWN;
200 nex_cb.mousebn(idx, press, x, y, nex_cb.mousebn_cls);
204 static void motion(int x, int y)
206 if(nex_cb.mousemove) {
207 nex_cb.mousemove(x, y, nex_cb.mousemove_cls);