- Update OsgGraph

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6131 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 1ec2df46ddbef667bdb0924c54a8d2df96be99af
Former-commit-id: e3c43bc04961646610f4f37a718340c7e558aeae
This commit is contained in:
torcs-ng 2015-09-16 23:45:26 +00:00
parent dcf1cf6a5b
commit ee575d7ebd
3 changed files with 25 additions and 18 deletions

View file

@ -67,6 +67,7 @@ bool OsgGraphicsWindowSDL2::setWindowDecorationImplementation(bool flag)
if(!m_Window) return false; if(!m_Window) return false;
SDL_SetWindowBordered(m_Window, flag ? SDL_TRUE : SDL_FALSE); SDL_SetWindowBordered(m_Window, flag ? SDL_TRUE : SDL_FALSE);
return true; return true;
} }
@ -96,7 +97,8 @@ void OsgGraphicsWindowSDL2::setCursor(MouseCursor mouseCursor)
void OsgGraphicsWindowSDL2::init() void OsgGraphicsWindowSDL2::init()
{ {
if(m_Valid) return; if(m_Valid)
return;
if(!_traits.valid()) if(!_traits.valid())
return; return;

View file

@ -19,6 +19,8 @@
#include <tgfclient.h> #include <tgfclient.h>
#include <stdexcept>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <osgViewer/GraphicsWindow> #include <osgViewer/GraphicsWindow>
#include <osg/GraphicsContext> #include <osg/GraphicsContext>
@ -29,15 +31,12 @@
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
#include "OsgGraphicsWindow.h" #include "OsgGraphicsWindow.h"
#endif #endif
#include "OsgDebugHUD.h" #include "OsgDebugHUD.h"
#include "OsgReflectionMapping.h" #include "OsgReflectionMapping.h"
#include "OsgMain.h" #include "OsgMain.h"
#include "OsgCar.h" #include "OsgCar.h"
//#if SDL_MAJOR_VERSION >= 2
//extern SDL_Window* GfuiWindow;
//#endif
SDScreens::SDScreens() : SDScreens::SDScreens() :
root(NULL), root(NULL),
mirrorScene(NULL), mirrorScene(NULL),
@ -62,21 +61,18 @@ public:
} }
}; };
void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr<osg::Node> m_sceneroot, osg::Vec3f fogcolor) void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr<osg::Node> m_sceneroot, osg::Vec3f fogcolor)
{ {
//intialising main screen //intialising main screen
viewer = new osgViewer::Viewer; viewer = new osgViewer::Viewer;
#if SDL_MAJOR_VERSION < 2 #if SDL_MAJOR_VERSION < 2
//viewer->setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext);
//SDView * view = new SDView(viewer->getCamera(),0,0, m_Winw, m_Winh, mirrorCam.get());
//osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> gw = viewer->setUpViewerAsEmbeddedInWindow(0, 0, m_Winw, m_Winh);
//viewer->getCamera()->setViewport(new osg::Viewport(0, 0, m_Winw, m_Winh));
//viewer->getCamera()->setGraphicsContext(gw);
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> gw = viewer->setUpViewerAsEmbeddedInWindow(0, 0, width, height); osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> gw = viewer->setUpViewerAsEmbeddedInWindow(0, 0, width, height);
viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); osg::ref_ptr<osg::Camera> Camera = viewer->getCamera();
viewer->getCamera()->setPreDrawCallback(new CameraDrawnCallback); //Camera->setGraphicsContext(gw);
//Camera->setViewport(new osg::Viewport(0, 0, width, height));
Camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
Camera->setPreDrawCallback(new CameraDrawnCallback);
#else #else
SDL_Window* GfuiWindow = GfScrGetMainWindow(); SDL_Window* GfuiWindow = GfScrGetMainWindow();
viewer->setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); viewer->setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext);
@ -86,16 +82,24 @@ void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr<osg::Node>
traits->windowName = SDL_GetWindowTitle(GfuiWindow); traits->windowName = SDL_GetWindowTitle(GfuiWindow);
traits->windowDecoration = !(SDL_GetWindowFlags(GfuiWindow)&SDL_WINDOW_BORDERLESS); traits->windowDecoration = !(SDL_GetWindowFlags(GfuiWindow)&SDL_WINDOW_BORDERLESS);
traits->screenNum = SDL_GetWindowDisplayIndex(GfuiWindow); traits->screenNum = SDL_GetWindowDisplayIndex(GfuiWindow);
traits->red = 8;
traits->green = 8;
traits->blue = 8;
traits->alpha = 0; // set to 0 to stop ScreenCaptureHandler reading the alpha channel
traits->depth = 24;
traits->stencil = 8;
traits->vsync = true; traits->vsync = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->inheritedWindowData = new OSGUtil::OsgGraphicsWindowSDL2::WindowData(GfuiWindow); traits->inheritedWindowData = new OSGUtil::OsgGraphicsWindowSDL2::WindowData(GfuiWindow);
osg::ref_ptr<OSGUtil::OsgGraphicsWindowSDL2> gw = new OSGUtil::OsgGraphicsWindowSDL2(traits); osg::ref_ptr<OSGUtil::OsgGraphicsWindowSDL2> gw = new OSGUtil::OsgGraphicsWindowSDL2(traits.get());
viewer->getCamera()->setGraphicsContext(gw);
viewer->getCamera()->setViewport(new osg::Viewport(0, 0, width, height));
viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
viewer->getCamera()->setPreDrawCallback(new CameraDrawnCallback); viewer->getCamera()->setPreDrawCallback(new CameraDrawnCallback);
if(!gw->valid()) throw if(!gw->valid())
std::runtime_error("Failed to create GraphicsContext"); throw std::runtime_error("Failed to create GraphicsContext");
#endif #endif
osg::ref_ptr<osg::Camera> mirrorCam = new osg::Camera; osg::ref_ptr<osg::Camera> mirrorCam = new osg::Camera;

View file

@ -18,6 +18,7 @@
***************************************************************************/ ***************************************************************************/
#include <osg/Camera> #include <osg/Camera>
#include <tgfclient.h> #include <tgfclient.h>
#include <graphic.h> #include <graphic.h>