]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_os.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Main / fg_os.cxx
index beaea1bee11a925e86549d44c7be17c5614b557f..a9fcf86c9ad358e5188fc6c2a40bc66f922b0eff 100644 (file)
@@ -1,12 +1,16 @@
-// The mac puts this in a weird location (GLUT/glut.h), so the
-// configure script detects the location and defines it as a macro.
+#ifndef _MSC_VER // MSVC really needs a definition for wchar_t
+#define _WCHAR_T_DEFINED 1 // Glut needs this, or else it tries to
+                           // redefine it
+#endif
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
-#  include FG_GLUT_H
-#else
-#  include <GL/glut.h>
 #endif
 
+#include <simgear/compiler.h>
+
+#include SG_GLUT_H
+
 #include <plib/pu.h>
 
 #include "fg_props.hxx"
@@ -24,6 +28,13 @@ static fgKeyHandler KeyHandler = 0;
 static fgMouseClickHandler MouseClickHandler = 0;
 static fgMouseMotionHandler MouseMotionHandler = 0;
 
+// We need to flush all pending mouse move events past a mouse warp to avoid
+// a race condition ending in warping twice and having huge increments for the
+// second warp.
+// I am not aware of such a flush function in glut. So we emulate that by
+// ignoring mouse move events between a warp mouse and the next frame.
+static bool mouseWarped = false;
+
 void fgRegisterIdleHandler(fgIdleHandler func)
 {
     IdleHandler = func;
@@ -71,13 +82,15 @@ static void callKeyHandler(int k, int mods, int x, int y)
 
 static void GLUTmotion (int x, int y)
 {
+    if (mouseWarped)
+        return;
     if(MouseMotionHandler) (*MouseMotionHandler)(x, y);
 }
 
 static void GLUTmouse (int button, int updown, int x, int y)
 {
     GlutModifiers = glutGetModifiers();
-    if(MouseClickHandler) (*MouseClickHandler)(button, updown, x, y);
+    if(MouseClickHandler) (*MouseClickHandler)(button, updown, x, y, true, 0);
 }
 
 static void GLUTspecialkeyup(int k, int x, int y)
@@ -107,12 +120,14 @@ static void GLUTkey(unsigned char k, int x, int y)
 static void GLUTidle()
 {
     if(IdleHandler) (*IdleHandler)();
+    mouseWarped = false;
 }
 
 static void GLUTdraw()
 {
     if(DrawHandler) (*DrawHandler)();
     glutSwapBuffers();
+    mouseWarped = false;
 }
 
 static void GLUTreshape(int w, int h)
@@ -165,6 +180,7 @@ void fgSetMouseCursor(int cursor)
 
 void fgWarpMouse(int x, int y)
 {
+    mouseWarped = true;
     glutWarpPointer(x, y);
 }
 
@@ -187,15 +203,21 @@ void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
 {
     int mode = GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE;
     if(alpha) mode |= GLUT_ALPHA;
-    if(stencil) mode |= GLUT_STENCIL;
+    if(stencil && bpp > 16) mode |= GLUT_STENCIL;
 
     glutInitDisplayMode(mode);
     glutInitWindowSize(w, h);
     if(!fgGetBool("/sim/startup/game-mode")) {
         glutCreateWindow("FlightGear");
     } else {
-        char game_mode_str[256];
-        sprintf(game_mode_str, "width=%d height=%d bpp=%d", w, h, bpp);
+        char game_mode_str[20];
+        SGPropertyNode *p = fgGetNode("/sim/frame-rate-throttle-hz", false);
+        if (p) {
+            int hz = p->getIntValue();
+            snprintf(game_mode_str, 20, "%dx%d:%d@%d", w, h, bpp, hz);
+        } else {
+            snprintf(game_mode_str, 20, "%dx%d:%d", w, h, bpp);
+        }
         glutGameModeString( game_mode_str );
         glutEnterGameMode();
     }
@@ -212,5 +234,19 @@ void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
     glutIdleFunc(GLUTidle);
     glutDisplayFunc(GLUTdraw);
     glutReshapeFunc(GLUTreshape);
+}
 
+// Noop; the graphics context is always current
+void fgMakeCurrent()
+{
+}
+
+bool fgOSIsMainCamera(const osg::Camera*)
+{
+  return true;
+}
+
+bool fgOSIsMainContext(const osg::GraphicsContext*)
+{
+  return true;
 }