From a311e614208ca99e1a4275d0c8cb72c557d47769 Mon Sep 17 00:00:00 2001 From: rvlander Date: Sat, 8 Jun 2013 13:20:28 +0000 Subject: [PATCH] OSGGRAPH :added HUD DEBUG, an helper for later visual debugging of rendered textures git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5495 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 812c4eb6e6442b079cd96ef821df5c9adb0dbffb Former-commit-id: 91858c3341f459839337e5ebf8d159cefe92bac4 --- src/modules/graphic/osggraph/CMakeLists.txt | 2 + src/modules/graphic/osggraph/OsgMain.cpp | 7 ++++ .../graphic/osggraph/OsgView/OsgDebugHUD.cpp | 29 +++++++++++++ .../graphic/osggraph/OsgView/OsgDebugHUD.h | 41 +++++++++++++++++++ .../graphic/osggraph/OsgView/OsgScreens.cpp | 9 ++++ .../graphic/osggraph/OsgView/OsgScreens.h | 4 ++ 6 files changed, 92 insertions(+) create mode 100755 src/modules/graphic/osggraph/OsgView/OsgDebugHUD.cpp create mode 100755 src/modules/graphic/osggraph/OsgView/OsgDebugHUD.h diff --git a/src/modules/graphic/osggraph/CMakeLists.txt b/src/modules/graphic/osggraph/CMakeLists.txt index 5187c059..48adff95 100644 --- a/src/modules/graphic/osggraph/CMakeLists.txt +++ b/src/modules/graphic/osggraph/CMakeLists.txt @@ -28,6 +28,7 @@ SET(OSGGRAPH_HEADERS OsgUtil/OsgVectorArrayAdapter.h OsgView/OsgView.h OsgView/OsgScreens.h OsgView/OsgCamera.h + OsgView/OsgDebugHUD.h OsgCar/OsgCar.h OsgCar/OsgWheel.h @@ -61,6 +62,7 @@ SET(OSGGRAPH_SOURCES OsgUtil/OsgSphere.cpp OsgView/OsgView.cpp OsgView/OsgScreens.cpp OsgView/OsgCamera.cpp + OsgView/OsgDebugHUD.cpp OsgCar/OsgCar.cpp OsgCar/OsgWheel.cpp diff --git a/src/modules/graphic/osggraph/OsgMain.cpp b/src/modules/graphic/osggraph/OsgMain.cpp index 9a8de4b2..aa32f630 100644 --- a/src/modules/graphic/osggraph/OsgMain.cpp +++ b/src/modules/graphic/osggraph/OsgMain.cpp @@ -182,6 +182,11 @@ void SDChangeScreen(void * vp) screens->changeScreen(t); } +void SDToggleHUD(void * vp) +{ + screens->toggleDebugHUD(); +} + int initView(int x, int y, int width, int height, int /* flag */, void *screen) { //render = new SDRender(); @@ -228,6 +233,8 @@ int initView(int x, int y, int width, int height, int /* flag */, void *screen) GfuiAddKey(screen, GFUIK_F10, "Follow Car Zoomed", (void*)8, SDSelectCamera, NULL); GfuiAddKey(screen, GFUIK_F11, "TV Director View", (void*)9, SDSelectCamera, NULL); + GfuiAddKey(screen, GFUIK_F12, "Activate DEBUG HUD", (void*)9, SDToggleHUD, NULL); + /*GfuiAddKey(screen, '5', "Debug Info", (void*)3, grSelectBoard, NULL); GfuiAddKey(screen, '4', "G/Cmd Graph", (void*)4, grSelectBoard, NULL); GfuiAddKey(screen, '3', "Leaders Board", (void*)2, grSelectBoard, NULL); diff --git a/src/modules/graphic/osggraph/OsgView/OsgDebugHUD.cpp b/src/modules/graphic/osggraph/OsgView/OsgDebugHUD.cpp new file mode 100755 index 00000000..092e928c --- /dev/null +++ b/src/modules/graphic/osggraph/OsgView/OsgDebugHUD.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "OsgDebugHUD.h" + +SDDebugHUD::SDDebugHUD(){ + + osg::Geometry* geom = osg::createTexturedQuadGeometry( + osg::Vec3(), osg::Vec3(0.5f,0.0f,0.0f), osg::Vec3(0.0f,0.7f,0.0f), + 0.0f, 0.0f, -1.0f, 1.0f ); + osg::ref_ptr quad = new osg::Geode; + quad->addDrawable( geom ); + + HUD_camera = new osg::Camera; + HUD_camera->setClearMask( GL_DEPTH_BUFFER_BIT ); + HUD_camera->setRenderOrder( osg::Camera::POST_RENDER ); + HUD_camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1)); + HUD_camera->setReferenceFrame( osg::Camera::ABSOLUTE_RF ); + HUD_camera->addChild( quad ); + HUD_camera->setNodeMask(0); +} + +void SDDebugHUD::toggleHUD(){ + HUD_camera->setNodeMask(1-HUD_camera->getNodeMask()); +} + +SDDebugHUD::~SDDebugHUD(){ +} diff --git a/src/modules/graphic/osggraph/OsgView/OsgDebugHUD.h b/src/modules/graphic/osggraph/OsgView/OsgDebugHUD.h new file mode 100755 index 00000000..1dff916b --- /dev/null +++ b/src/modules/graphic/osggraph/OsgView/OsgDebugHUD.h @@ -0,0 +1,41 @@ +/*************************************************************************** + + file : OsgScreens.h + created : Sat Feb 2013 15:52:19 CEST 2013 + copyright : (C) 2013 by Gaëtan André + email : gaetan.andre@gmail.com + version : $Id$ + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef _OSGDEBUGHUD_H_ +#define _OSGDEBUGHUD_H_ + +#include +#include + +class SDDebugHUD +{ + private: + osg::ref_ptr HUD_camera; + + public: + void toggleHUD(); + SDDebugHUD(); + ~SDDebugHUD(); + + inline osg::ref_ptr getRootCamera(){ + return HUD_camera; + } + +}; + +#endif //_OSGDEBUGHUD_H_ diff --git a/src/modules/graphic/osggraph/OsgView/OsgScreens.cpp b/src/modules/graphic/osggraph/OsgView/OsgScreens.cpp index dcae30f9..db5e19ca 100755 --- a/src/modules/graphic/osggraph/OsgView/OsgScreens.cpp +++ b/src/modules/graphic/osggraph/OsgView/OsgScreens.cpp @@ -32,6 +32,7 @@ SDScreens::SDScreens() :m_CurrentScreenIndex(0) { + debugHUD = new SDDebugHUD(); viewer = new osgViewer::Viewer(); viewer->setSceneData(new osg::Group()); } @@ -108,6 +109,8 @@ void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr root->addChild(mirrorCam.get()); } + root->addChild(debugHUD->getRootCamera()); + viewer->setSceneData(root.get()); viewer->realize(); } @@ -496,6 +499,11 @@ void SDScreens::changeCamera(long p) } } +void SDScreens::toggleDebugHUD(){ + debugHUD->toggleHUD(); +} + + SDScreens::~SDScreens() { root->removeChildren(0, root->getNumChildren()); @@ -510,5 +518,6 @@ SDScreens::~SDScreens() //delete viewer->getSceneData(); delete viewer; + delete debugHUD; viewer = NULL; } diff --git a/src/modules/graphic/osggraph/OsgView/OsgScreens.h b/src/modules/graphic/osggraph/OsgView/OsgScreens.h index 6ac5003d..6c710dc4 100755 --- a/src/modules/graphic/osggraph/OsgView/OsgScreens.h +++ b/src/modules/graphic/osggraph/OsgView/OsgScreens.h @@ -24,6 +24,8 @@ #include #include "OsgView.h" +#include "OsgDebugHUD.h" + #define SD_SPLIT_ADD 0 #define SD_SPLIT_REM 1 #define SD_SPLIT_ARR 2 @@ -39,6 +41,7 @@ class SDScreens osgViewer::Viewer* viewer; std::vector Screens; osg::ref_ptr root; + SDDebugHUD * debugHUD; int m_Winx; int m_Winy; @@ -64,6 +67,7 @@ class SDScreens void splitScreen(long p); void changeScreen(long p); void changeCamera(long p); + void toggleDebugHUD(); inline SDView * getActiveView(){return Screens[m_CurrentScreenIndex];}