VS-Qt-OSG-CMake基本项目框架
在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基本项目框架的更多相关文章
- 项目实战:Qt手机模拟器拉伸旋转框架
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- 基于Cmake+QT+VS的C++项目构建开发编译简明教程
目录 一.工具下载与安装 1. Qt 2. Visual Studio 2015 3. Cmake 二.C++及Qt项目构建 1. 基于VS构建Qt项目 2. ...
- 《Play for Java》学习笔记(一)项目框架
从今天开始认真复习<Play for JAVA>,该书以一个案例为主线,以前为应付项目马马虎虎看了一遍,好多地方都不明白!现在跟着这本书再走一遍,认真模拟,当做一个项目啦!! 一.Play ...
- 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 ...
- Angular企业级开发(5)-项目框架搭建
1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...
- 2_MVC+EF+Autofac(dbfirst)轻型项目框架_用户权限验证
前言 接上面两篇 0_MVC+EF+Autofac(dbfirst)轻型项目框架_基本框架 与 1_MVC+EF+Autofac(dbfirst)轻型项目框架_core层(以登陆为例) .在第一篇中介 ...
- 1_MVC+EF+Autofac(dbfirst)轻型项目框架_core层(以登陆为例)
前言 在上一篇0_MVC+EF+Autofac(dbfirst)轻型项目框架_基本框架中,我已经介绍了这个轻型框架的层次结构,在下面的这篇文章中,我将以教师登陆功能为例,具体来扩充下我的core层的代 ...
- 0_MVC+EF+Autofac(dbfirst)轻型项目框架_基本框架
前言 原来一直使用他人的开源项目框架,异常的定位会很麻烦,甚至不知道这个异常来自我的代码还是这个框架本身.他人的框架有一定的制约性,也有可能是我对那些框架并没深入了解,因为这些开源框架在网上也很难找到 ...
- ASP.NET MVC5 网站开发实践(一) - 项目框架
前几天算是开题了,关于怎么做自己想了很多,但毕竟没做过项目既不知道这些想法有无必要,也不知道能不能实现,不过邓爷爷说过"摸着石头过河"吧.这段时间看了一些博主的文章收获很大,特别是 ...
- iOS通用的MVC模式项目框架MobileProject
最近项目比较不赶的情况下,决定把一些通用.常用的内容集成在一个项目框架中,意在新项目中可以快速搭建:其实经过几个项目后,总是有一些重复的创建工作,可以使用本项目的内容直接进行开发:采用的是MVC的分层 ...
随机推荐
- IWDG—独立看门狗
本章参考资料:<STM32F4XX 中文参考手册> IWDG 章节.学习本章时,配合<STM32F4XX 中文参考手册> IWDG 章节一起阅读,效果会更佳,特别是涉及到寄存器 ...
- VC 与Matlab混合编程之引擎操作详解
Visual C++ 是当前主流的应用程序开发环境之一,开发环境强大,开发的程序执行速度快.但在科学计算方面函数库显得不够丰富.读取.显示数据图形不方便. Matlab 是一款将数值分析.矩阵计算.信 ...
- ThreadStart中如何带参数
1.ThreadStart 线程执行带参数的方法,new Thread(new ThreadStart(delegate { ThreadTask(firstPage, lastPage); })); ...
- [uart]3.tty驱动分析
转自:http://www.wowotech.net/linux_kenrel/183.html 目录: 1 首先分析设备驱动的注册 1.1 uart_register_driver分析 1.2 tt ...
- MongoDB 集群搭建(主从复制、副本及)(五)
六:架构管理 mongodb的主从集群分为两种: 1:master-Slave 复制(主从) --从server不会主动变成主server,须要设置才行 2:replica Sets 复制(副本 ...
- MongoDB(三):MongoDB概念解析
在上一篇文章中讲解了如何安装MongoDB,这篇文章中讲解一些有关MongoDB的概念. 不管我们要学习什么数据库,都应该学习其中的基础概念,在MongoDB中基本的概念是文档.集合.数据库,下面挨个 ...
- Java-jdbc工具类DBUtils
创建项目: 导入相应jar包: 看上图. JDBCUtil.java获取数据库连接文件: package com.gordon.jdbcutil; import java.io.InputStream ...
- 【这特么是个坑。。。】iOS 10.3下解决Charles抓包ssl证书信任问题
针对近期iOS 10.3以上的系统charles抓https信任问题 前言 最近iPhone系统更新到ios 10.3后,在公司里用Charles抓包竟然出现了一些问题,https的请求都会失败,提示 ...
- 【转】java基本数据类型vs封装数据类型
1.基本概念 说java是面向对象的语言是正确的,但是她不纯,基本数据类型就不是对象. 基本数据类型可以大致分为三类:数据型:int.short.long.byte.float.double字符型:c ...
- Qt中Pro文件变量详细说明
学习Qt时,发现有些知识看了不经常用就忘了,以下是书本上写的一些关于qmake的相关知识,自己看后,打算把一些经常用到的记下来,整理整理. Qt程序一般使用Qt提供的qmake工具来编译. qmake ...