+ glClear( GL_COLOR_BUFFER_BIT );
+ swap_gl_buffers();
+
+ // clear all states
+ glDisable( GL_ALPHA_TEST);
+ glDisable( GL_BLEND);
+ glDisable( GL_DEPTH_TEST);
+ //glDisable( GL_DITHER);
+ glDisable( GL_FOG);
+ glDisable( GL_LIGHTING);
+ glDisable( GL_LOGIC_OP);
+ glDisable( GL_TEXTURE_1D);
+ glDisable( GL_TEXTURE_2D);
+ glPixelTransferi( GL_MAP_COLOR, GL_FALSE);
+ glPixelTransferi( GL_RED_SCALE, 1);
+ glPixelTransferi( GL_RED_BIAS, 0);
+ glPixelTransferi( GL_GREEN_SCALE, 1);
+ glPixelTransferi( GL_GREEN_BIAS, 0);
+ glPixelTransferi( GL_BLUE_SCALE, 1);
+ glPixelTransferi( GL_BLUE_BIAS, 0);
+ glPixelTransferi( GL_ALPHA_SCALE, 1);
+ glPixelTransferi( GL_ALPHA_BIAS, 0);
+
+ // set initial rendering states
+ glShadeModel( GL_SMOOTH);
+ glClearDepth( 1.0f);
+ glDepthFunc( GL_LEQUAL);
+ glDepthMask( GL_TRUE);
+ //glDepthRange( FRONT_CLIP, BACK_CLIP);
+ glEnable( GL_DEPTH_TEST);
+ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+ glCullFace( GL_FRONT);
+ glEnable( GL_CULL_FACE);
+ glEnable( GL_LIGHTING);
+ //glEnable( GL_LIGHT_MODEL_AMBIENT);
+ glEnable( GL_DITHER);
+ glEnable( GL_COLOR_MATERIAL);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glAlphaFunc( GL_GREATER, 0.5f);
+
+ if ( CanInitStereo(stereomode) ) {
+ InitStereo(stereomode);
+ } else {
+ fprintf(stderr, "Failed to initialize stereo, disabling.\n");
+ stereomode = stereoNone;
+ }
+}
+
+static void toggleFullscreen()
+{
+ Uint32 flags = SDL_GetWindowFlags(sdlwindow);
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ flags &= ~SDL_WINDOW_FULLSCREEN;
+ } else {
+ flags |= SDL_WINDOW_FULLSCREEN;
+ }
+ SDL_SetWindowFullscreen(sdlwindow, flags);
+}
+
+static SDL_bool sdlEventProc(const SDL_Event &e)
+{
+ switch (e.type) {
+ case SDL_QUIT:
+ return SDL_FALSE;
+
+ case SDL_WINDOWEVENT:
+ if (e.window.event == SDL_WINDOWEVENT_CLOSE) {
+ return SDL_FALSE;
+ }
+ break;
+