在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. java web 中 读取windows图标并显示

    java web中读取windows对应文件名的 系统图标 ....显示 1.获取系统图标工具类 package utils;  import java.awt.Graphics;  import j ...

  2. python学习笔记(12)--爬虫下载煎蛋网图片

    说明: 1. 这个其实是在下载漫画之前写的,比那个稍微简单点,之前忘放到博客备份了. 2. 不想说啥了,总结放到漫画那个里面吧! import urllib.request import re imp ...

  3. ios开发之修改 UITableview 滚动条颜色的方法

    UITableview 的滚动条默认颜色是黑色的,如果 UItableview 背景也是深颜色,则滚动条会变的很不明显.您可以用下面这行代码来改变滚动条的颜色 self.tableView.indic ...

  4. 加载jquery主函数的两种方式

    方式一: $(document).ready(fucntion){ var div1 = document.getElementById("div1"); alert(div1); ...

  5. 【WPF】C#代码动态改变控件的样式

    需求:C#代码生成的一组按钮Button需要设置样式. 如果是在XAML中引入样式: <!-- 引入资源 --> <UserControl.Resources> <Res ...

  6. 机器学习:K-Means聚类算法

    本文来自同步博客. 前面几篇文章介绍了回归或分类的几个算法,它们的共同点是训练数据包含了输出结果,要求算法能够通过训练数据掌握规律,用于预测新输入数据的输出值.因此,回归算法或分类算法被称之为监督学习 ...

  7. oozie中调度mapreduce

    mapreduce可以直接对hdfs进行清洗和计算,这里介绍oozie中如何调度使用. 操作步骤如下: 1. 写一个mapper和reduce类,并且打包成jar包 2. 在workflow中引用ma ...

  8. 记录github 免登陆用户名密码方式

    1.https 代码模式切换为ssh模式: (本博客有文章介绍) 2.~/.ssh/github_rsa.pub 内容添加到github “config“ 目录下面 3.配置~/.ssh/config ...

  9. Game publishing request was abnormally terminated (ID 27492).

    本地可以正常发布:远程发布报错.怀疑跟直接删除数据库记录有关,wp_myarcadegames/wp_posts Game publishing request was abnormally term ...

  10. SpringMVC拦截器简单使用

    一.拦截器的配置 1.传统的配置 Xml代码   <bean class="org.springframework.web.servlet.mvc.annotation.Default ...