在VS-Qt-CMake基础上,打开mainwindow.ui,添加一个QWidget,然后在widget上右键-提升,选择SceneViewWidget

CMakeLists.txt中添加了OSG相关配置

cmake_minimum_required(VERSION 3.0)

SET(PRODUCT_NAME ReadS3C)

SET(PRODUCT_HEADER_FILES
mainwindow.h
SceneViewWidget.h
) SET(PRODUCT_UI_FILES
mainwindow.ui
) SET(PRODUCT_FILES
main.cpp
mainwindow.cpp
SceneViewWidget.cpp
${PRODUCT_HEADER_FILES}
) SET(PRODUCT_DATA_FILES
data/axes.osgt
data/arial.ttf
) FIND_PATH(OSG_INCLUDE_DIR osg/Referenced
PATHS
$ENV{OSG_ROOT}/include
$ENV{OSG_DIR}/include
/usr/include
/usr/local/include
)
FIND_PATH(OSG_LIB_DIR libosg.so osg.lib
PATHS
$ENV{OSG_ROOT}/lib
$ENV{OSG_DIR}/lib
/usr/lib
/usr/local/lib
)
SET(OSG_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows")
SET(OSG_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
SET(QT_FOUND FALSE)
IF(${CMAKE_VERSION} VERSION_LESS "3.2.0")
FIND_PACKAGE(Qt5Widgets)
IF(Qt5Widgets_FOUND)
ADD_DEFINITIONS(-DUSE_QT_VERSION=)
SET(QT_FOUND TRUE)
ELSE(Qt5Widgets_FOUND)
MESSAGE("*** Qt5 not found, which may be caused by missing/wrong CMake module files. "
"You should set Qt5Widgets_DIR to $(QT_DIR)/lib/cmake/Qt5Widgets/ to find variables.")
ENDIF(Qt5Widgets_FOUND)
ELSE()
FIND_PACKAGE(Qt5 COMPONENTS Widgets)
IF(Qt5_FOUND)
ADD_DEFINITIONS(-DUSE_QT_VERSION=)
SET(QT_FOUND TRUE)
ENDIF(Qt5_FOUND)
ENDIF() QT5_WRAP_UI(UI_FILES ${PRODUCT_UI_FILES})
QT5_WRAP_CPP(MOC_FILES ${PRODUCT_HEADER_FILES}) SET(PRODUCT_FILES ${PRODUCT_FILES} ${UI_FILES} ${MOC_FILES})
IF(WIN32)
#SET(PRODUCT_FILES ${PRODUCT_FILES} my.rc)
ENDIF(WIN32) IF(QT_FOUND)
#QT5_ADD_RESOURCES(RES_FILES skin/qdarkstyle/style.qrc)
ENDIF()
SET(PRODUCT_FILES ${PRODUCT_FILES} ${RES_FILES}) SOURCE_GROUP("auto generated files" FILES ${UI_FILES} ${MOC_FILES} ${RES_FILES})
SOURCE_GROUP("ui files" FILES ${PRODUCT_UI_FILES}) SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES}
debug osgQt${OSG_DEBUG_POSTFIX} optimized osgQt${OSG_RELEASE_POSTFIX}
) INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
LINK_DIRECTORIES(${OSG_LIB_DIR}) SET(WITH_CONSOLE )
IF(${WITH_CONSOLE})
ADD_EXECUTABLE(${PRODUCT_NAME} ${PRODUCT_FILES})
ELSE(${WITH_CONSOLE})
ADD_EXECUTABLE(${PRODUCT_NAME} WIN32 ${PRODUCT_FILES})
ENDIF(${WITH_CONSOLE}) SET_TARGET_PROPERTIES(${PRODUCT_NAME} PROPERTIES DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}") TARGET_LINK_LIBRARIES(${PRODUCT_NAME}
debug osg${OSG_DEBUG_POSTFIX} optimized osg${OSG_RELEASE_POSTFIX}
debug osgAnimation${OSG_DEBUG_POSTFIX} optimized osgAnimation${OSG_RELEASE_POSTFIX}
debug osgParticle${OSG_DEBUG_POSTFIX} optimized osgParticle${OSG_RELEASE_POSTFIX}
debug osgDB${OSG_DEBUG_POSTFIX} optimized osgDB${OSG_RELEASE_POSTFIX}
debug osgGA${OSG_DEBUG_POSTFIX} optimized osgGA${OSG_RELEASE_POSTFIX}
debug osgText${OSG_DEBUG_POSTFIX} optimized osgText${OSG_RELEASE_POSTFIX}
debug osgTerrain${OSG_DEBUG_POSTFIX} optimized osgTerrain${OSG_RELEASE_POSTFIX}
debug osgUtil${OSG_DEBUG_POSTFIX} optimized osgUtil${OSG_RELEASE_POSTFIX}
debug osgViewer${OSG_DEBUG_POSTFIX} optimized osgViewer${OSG_RELEASE_POSTFIX}
debug OpenThreads${OSG_DEBUG_POSTFIX} optimized OpenThreads${OSG_RELEASE_POSTFIX}
${OPENGL_LIBRARIES} ${THIRD_PARTY_LIBRARIES} ${EXTERNAL_LIBRARIES}
) SET_TARGET_PROPERTIES(${PRODUCT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/bin") INSTALL(TARGETS ${PRODUCT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
INSTALL(FILES ${PRODUCT_DATA_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/data) IF(QT_FOUND)
QT5_USE_MODULES(${PRODUCT_NAME} Widgets Network OpenGL)
ENDIF(QT_FOUND)

SceneViewWidget.h

#pragma once
#include <QWidget>
#include <QGridLayout>
#include <QTimer>
#include "osgViewer\CompositeViewer"
#include "osgDB\ReadFile"
#include "osgQt\GraphicsWindowQt" class SceneViewWidget : public QWidget, public osgViewer::CompositeViewer
{
public:
SceneViewWidget(QWidget* parent = , Qt::WindowFlags f = , osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::CompositeViewer::SingleThreaded); QWidget* addViewWidget(osgQt::GraphicsWindowQt* gw, osg::Node* scene); osgQt::GraphicsWindowQt* createGraphicsWindow(int x, int y, int w, int h, const std::string& name = "", bool windowDecoration = false); virtual void paintEvent(QPaintEvent* event); protected:
virtual void initScene();
protected:
osg::ref_ptr<osg::Group> sceneRoot;
QTimer _timer;
};

SceneViewWidget.cpp

#include "SceneViewWidget.h"
#include "osgViewer\ViewerEventHandlers"
#include "osgGA\TrackballManipulator" SceneViewWidget::SceneViewWidget(QWidget* parent /*= 0*/, Qt::WindowFlags f /*= 0*/, osgViewer::ViewerBase::ThreadingModel threadingModel /*= osgViewer::CompositeViewer::SingleThreaded*/) : QWidget(parent, f)
{
setThreadingModel(threadingModel); // disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone(); initScene(); QWidget* widget1 = addViewWidget(createGraphicsWindow(, , , ), sceneRoot); QGridLayout* grid = new QGridLayout;
grid->addWidget(widget1, , );
setLayout(grid); connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
_timer.start();
} QWidget* SceneViewWidget::addViewWidget(osgQt::GraphicsWindowQt* gw, osg::Node* scene)
{
osgViewer::View* view = new osgViewer::View;
addView(view); osg::Camera* camera = view->getCamera();
camera->setGraphicsContext(gw); const osg::GraphicsContext::Traits* traits = gw->getTraits(); //camera->setClearColor(osg::Vec4(0.2, 0.2, 0.2, 1.0));
camera->setViewport(new osg::Viewport(, , traits->width, traits->height));
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits->width) / static_cast<double>(traits->height), 1.0f, 10000.0f); view->setSceneData(scene);
view->addEventHandler(new osgViewer::StatsHandler);
view->setCameraManipulator(new osgGA::TrackballManipulator);
gw->setTouchEventsEnabled(true);
return gw->getGLWidget();
} osgQt::GraphicsWindowQt* SceneViewWidget::createGraphicsWindow(int x, int y, int w, int h, const std::string& name /*= ""*/, bool windowDecoration /*= false*/)
{
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();//抗锯齿 return new osgQt::GraphicsWindowQt(traits.get());
} void SceneViewWidget::paintEvent(QPaintEvent* event)
{
frame();
}
void SceneViewWidget::initScene()
{
sceneRoot = new osg::Group(); osg::Node* axesModel = osgDB::readNodeFile("data/axes.osgt.(0.5,0.5,0.5).scale");
if(axesModel)
sceneRoot->addChild(axesModel); osg::ref_ptr<osgText::Font> font = osgText::readRefFontFile("data/arial.ttf");
osgText::Text* text = new osgText::Text();
text->setPosition(osg::Vec3(0.0, 0.0, 0.5));
text->setFont(font);
text->setAutoRotateToScreen(true);
text->setColor(osg::Vec4(1.0, 1.0, 0.0, 1.0));
text->setCharacterSize(0.1);
text->getOrCreateStateSet()->setRenderBinDetails(, "RenderBin");
text->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
text->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
text->getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
text->setText("OSG");
sceneRoot->addChild(text);
}

VS-Qt-OSG-CMake基本项目框架的更多相关文章

  1. 项目实战:Qt手机模拟器拉伸旋转框架

    若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...

  2. 基于Cmake+QT+VS的C++项目构建开发编译简明教程

    目录 一.工具下载与安装 1.     Qt 2.     Visual Studio 2015 3.     Cmake 二.C++及Qt项目构建 1.     基于VS构建Qt项目 2.     ...

  3. 《Play for Java》学习笔记(一)项目框架

    从今天开始认真复习<Play for JAVA>,该书以一个案例为主线,以前为应付项目马马虎虎看了一遍,好多地方都不明白!现在跟着这本书再走一遍,认真模拟,当做一个项目啦!! 一.Play ...

  4. MinGW32 +QT4.8.6+QT Creator+CMAKE的安装

    参考网址: http://www.360doc.com/content/15/0813/09/7256015_491331699.shtml http://m.fx114.net/qa-196-213 ...

  5. Angular企业级开发(5)-项目框架搭建

    1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...

  6. 2_MVC+EF+Autofac(dbfirst)轻型项目框架_用户权限验证

    前言 接上面两篇 0_MVC+EF+Autofac(dbfirst)轻型项目框架_基本框架 与 1_MVC+EF+Autofac(dbfirst)轻型项目框架_core层(以登陆为例) .在第一篇中介 ...

  7. 1_MVC+EF+Autofac(dbfirst)轻型项目框架_core层(以登陆为例)

    前言 在上一篇0_MVC+EF+Autofac(dbfirst)轻型项目框架_基本框架中,我已经介绍了这个轻型框架的层次结构,在下面的这篇文章中,我将以教师登陆功能为例,具体来扩充下我的core层的代 ...

  8. 0_MVC+EF+Autofac(dbfirst)轻型项目框架_基本框架

    前言 原来一直使用他人的开源项目框架,异常的定位会很麻烦,甚至不知道这个异常来自我的代码还是这个框架本身.他人的框架有一定的制约性,也有可能是我对那些框架并没深入了解,因为这些开源框架在网上也很难找到 ...

  9. ASP.NET MVC5 网站开发实践(一) - 项目框架

    前几天算是开题了,关于怎么做自己想了很多,但毕竟没做过项目既不知道这些想法有无必要,也不知道能不能实现,不过邓爷爷说过"摸着石头过河"吧.这段时间看了一些博主的文章收获很大,特别是 ...

  10. iOS通用的MVC模式项目框架MobileProject

    最近项目比较不赶的情况下,决定把一些通用.常用的内容集成在一个项目框架中,意在新项目中可以快速搭建:其实经过几个项目后,总是有一些重复的创建工作,可以使用本项目的内容直接进行开发:采用的是MVC的分层 ...

随机推荐

  1. ubuntu怎用使用命令搜索软件源中的软件

    转自:http://jingyan.baidu.com/article/6d704a13f6bf1b28da51ca69.html ubuntu中是用apt-get来进行软件安装的,我们首先打开终端来 ...

  2. java 多线程11:volatile关键字

    直接先举一个例子普通的线程实例变量的非可见性: public class MyThread28 extends Thread { private boolean isRunning = true; p ...

  3. show global status和show variables mysql 优化

    mysql> show global status; 可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%'; 一.慢查询 mysql> ...

  4. JavaScript高级 面向对象(7)--深拷贝与浅拷贝

    说明(2017.3.31): 1. 画图: var car = {name:"法拉利"}; var p = {name: "张三", age: "19 ...

  5. R ggplot2 线性回归

    摘自  http://f.dataguru.cn/thread-278300-1-1.html library(ggplot2) x=1:10y=rnorm(10)a=data.frame(x= x, ...

  6. BSD Socket~TCP~Example Code

    TCP 协议实现 C版本号,可用于Mac OS X机器上执行 Server: /* Setting up a simple TCP server involves the following step ...

  7. PKU OJ Exponentiation

    ExponentiationTime Limit: 500MS                      Memory Limit: 10000KTotal Submissions: 155886   ...

  8. Android——数据存储:手机外部存储 SD卡存储

    xml <EditText android:layout_width="match_parent" android:layout_height="wrap_cont ...

  9. win10无法访问局域网共享文件?(因微软账户和本地账户登陆问题导致)

    1 笔记本系统win10 X64企业版,其中一文件夹已设置为“共享”.本地帐号登录系统. 2 平板电脑系统win8.1 X64专业版,可以顺畅的访问笔记本的共享文件.微软帐号登录系统. 3 平板电脑系 ...

  10. Linux下如何查看tomcat是否启动/系统日志等

    Linux下如何查看tomcat是否启动/系统日志等 查看tomcat是否启动 ps -ef | grep tomcat  或者  ps -ef | grep java 启动tomcat(在tomca ...