]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_os.cxx
Add the alpha test back in so the instruments won't disappear after changing the...
[flightgear.git] / src / Main / fg_os.cxx
index 27360a0615bf15a4425b2814f172fafc22afc5c2..dfce9b2aaad59e61957e7b334271683764f90d6d 100644 (file)
@@ -7,13 +7,17 @@
 #  include <config.h>
 #endif
 
+#include <osg/Matrix>
 #include <osgViewer/Viewer>
 #include <osgViewer/ViewerEventHandlers>
 
 #include <simgear/compiler.h>
 
-#include SG_GLUT_H
-
+#if defined( __APPLE__)
+# include <GLUT/glut.h>
+#else
+# include <GL/glut.h>
+#endif
 #include <plib/pu.h>
 
 #include <Scenery/scenery.hxx>
 #include "globals.hxx"
 #include "renderer.hxx"
 #include "fg_props.hxx"
+#include "WindowSystemAdapter.hxx"
+#include "CameraGroup.hxx"
+
+using namespace flightgear;
 
 //
 // Native glut callbacks.
@@ -28,7 +36,6 @@
 //
 
 static osg::ref_ptr<osgViewer::Viewer> viewer;
-static osg::ref_ptr<osg::Camera> mainCamera;
 static osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> gw;
 
 static int GlutModifiers = 0;
@@ -153,6 +160,7 @@ static void GLUTreshape(int w, int h)
 void fgOSInit(int* argc, char** argv)
 {
     glutInit(argc, argv);
+    WindowSystemAdapter::setWSA(new WindowSystemAdapter);
 }
 
 void fgOSFullScreen()
@@ -216,10 +224,16 @@ static unsigned int getOSGModifiers(int glutModifiers)
     return result;
 }
 
-void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
-                    bool stencil, bool fullscreen)
+void fgOSOpenWindow(bool stencil)
 {
+    int w = fgGetInt("/sim/startup/xsize");
+    int h = fgGetInt("/sim/startup/ysize");
+    int bpp = fgGetInt("/sim/rendering/bits-per-pixel");
+    bool alpha = fgGetBool("/sim/rendering/clouds3d-enable");
+    bool fullscreen = fgGetBool("/sim/startup/fullscreen");
+    WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
     int mode = GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE;
+
     if(alpha) mode |= GLUT_ALPHA;
     if(stencil && bpp > 16) mode |= GLUT_STENCIL;
 
@@ -256,18 +270,22 @@ void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
     int realh = h;
     viewer = new osgViewer::Viewer;
     gw = viewer->setUpViewerAsEmbeddedInWindow(0, 0, realw, realh);
+    GraphicsWindow* window = wsa->registerWindow(gw.get(), string("main"));
+    window->flags |= GraphicsWindow::GUI;
+    viewer->setDatabasePager(FGScenery::getPagerSingleton());
     // now the main camera ...
-    //osg::ref_ptr<osg::Camera> camera = new osg::Camera;
-    osg::ref_ptr<osg::Camera> camera = viewer->getCamera();
-    mainCamera = camera;
-    osg::Camera::ProjectionResizePolicy rsp = osg::Camera::VERTICAL;
+    osg::Camera* camera = new osg::Camera;
     // If a viewport isn't set on the camera, then it's hard to dig it
     // out of the SceneView objects in the viewer, and the coordinates
     // of mouse events are somewhat bizzare.
     camera->setViewport(new osg::Viewport(0, 0, realw, realh));
-    camera->setProjectionResizePolicy(rsp);
-    //viewer->addSlave(camera.get());
-    globals->get_renderer()->getManipulator()->setUseEventModifiers(true);
+    camera->setProjectionResizePolicy(osg::Camera::FIXED);
+    CameraGroup* cgroup = new CameraGroup(viewer.get());
+    cgroup->addCamera(CameraGroup::DO_INTERSECTION_TEST, camera,
+                      osg::Matrixd::identity(), osg::Matrixd::identity(),
+                      true);
+    cgroup->buildGUICamera(0, window);
+    CameraGroup::setDefault(cgroup);
     viewer->setCameraManipulator(globals->get_renderer()->getManipulator());
     // Let FG handle the escape key with a confirmation
     viewer->setKeyEventSetsDone(0);
@@ -279,18 +297,3 @@ void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
     viewer->setSceneData(new osg::Group);
     globals->get_renderer()->setViewer(viewer.get());
 }
-
-// Noop; the graphics context is always current
-void fgMakeCurrent()
-{
-}
-
-bool fgOSIsMainCamera(const osg::Camera*)
-{
-  return true;
-}
-
-bool fgOSIsMainContext(const osg::GraphicsContext*)
-{
-  return true;
-}