osgearth3.2配合osgQOpenGL在qt中显示地球

 

主要借助osgQOpenGL,将osg的窗口嵌入qt,osgQopenGL库的编译方法,可以参考参考链接

main.cpp

#include "osgQOpenGL_osgearth.h"
#include <QtWidgets/QApplication>
#pragma execution_character_set("utf-8")

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    osgQOpenGL_osgearth w;
	//设置初始窗口大小
	w.setGeometry(200, 100, 1200, 800);
	//设置窗口标题名称
	w.setWindowTitle(QString("osgearth三维可视化"));
    w.show();
    return a.exec();
}

 osgQOpenGL_osg.h

#pragma once
#pragma execution_character_set("utf-8")
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/Node>
#include <osgEarth/EarthManipulator>
#include <osgViewer/ViewerEventHandlers>

#include <QtWidgets/QMainWindow>
#include <qDebug>
#include "ui_osgQOpenGL_osgearth.h"

#include"osg365oe32.h"

class osgQOpenGL_osgearth : public QMainWindow
{
    Q_OBJECT

public:
    osgQOpenGL_osgearth(QWidget *parent = nullptr);
    ~osgQOpenGL_osgearth();

protected slots:
	void initWindow();

private:
    Ui::osgQOpenGL_osgearthClass					ui;
	osgViewer::Viewer*								viewer;					//场景
	osgQOpenGLWidget*								_osgQOpenGLWidget;		//osg窗体
	osg::ref_ptr<osg::Group>						root;					//根节点
	osg::ref_ptr<osg::Node>							earth;					//地球节点
	osg::ref_ptr<osgEarth::Util::EarthManipulator>	em;						//相机操作器
};

osgQOpenGL_osg.cpp 

#include "osgQOpenGL_osgearth.h"

osgQOpenGL_osgearth::osgQOpenGL_osgearth(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

	_osgQOpenGLWidget = new osgQOpenGLWidget(this);
	//设置显示尺寸
	//_osgQOpenGLWidget->setGeometry(100,100,800,600);
	_osgQOpenGLWidget->setGeometry(this->geometry());
	this->setCentralWidget(_osgQOpenGLWidget);

	root = new osg::Group;
	em = new osgEarth::Util::EarthManipulator;
	earth = osgDB::readNodeFile("simple.earth");
	root->addChild(earth.get());

	connect(_osgQOpenGLWidget, SIGNAL(initialized()), this, SLOT(initWindow()));
}

osgQOpenGL_osgearth::~osgQOpenGL_osgearth()
{
	if (_osgQOpenGLWidget != NULL)
		delete _osgQOpenGLWidget;
}


void osgQOpenGL_osgearth::initWindow()
{
	osgEarth::initialize();
	viewer = _osgQOpenGLWidget->getOsgViewer();
	viewer->setCameraManipulator(em);
	viewer->setSceneData(root.get());
	viewer->addEventHandler(new osgViewer::StatsHandler);//添加s键帧率显示事件
	unsigned int windowWidth; //显示器宽度
	unsigned int windowHeight; //显示器高度
	//获取系统分辨率
	osg::GraphicsContext::WindowingSystemInterface *wsInterface = osg::GraphicsContext::getWindowingSystemInterface();
	wsInterface->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), windowWidth, windowHeight);
	qDebug() << windowWidth << "  " << windowHeight;
	//放置窗口变扁
	viewer->getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(1200) / static_cast<double>(800), 1.0f, 10000.0f);
}

 osg365oe32.h

#pragma once
#include <Windows.h>
#include <osgGA/CameraManipulator>
#include <osg/LineSegment>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Matrixd>
#include <osg/Matrix>
#include <osg/Material>
#include <osg/MatrixTransform>
#include <osg/Group>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/PositionAttitudeTransform>
#include <memory>
#include <osg/StateAttribute>
#include <osg/Point>
#include <osgDB/Registry>
#include <osgUtil/Optimizer>
#include <osgUtil/Simplifier>
#include <osgUtil/SmoothingVisitor>
#include <osgUtil/IntersectVisitor>
#include <osg/TextureCubeMap>
#include <osg/TexGen>
#include <osg/ShapeDrawable>

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osgDB/WriteFile>
#include <osgDB/ReadFile>
#include <osg/CullFace>
#include <osgParticle/PrecipitationEffect>
#include <osgParticle/ExplosionEffect>
#include <osgParticle/ExplosionDebrisEffect>
#include <osgParticle/FireEffect>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>

#include <osgQOpenGL/osgQOpenGLWidget>

using namespace std;


#ifdef _DEBUG
//osg库一共19个
#pragma comment(lib, "osgd.lib")
#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "osgFXd.lib")
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgVolumed.lib")
#pragma comment(lib, "OpenThreadsd.lib")
#pragma comment(lib, "osgGAd.lib")
#pragma comment(lib, "osgUtild.lib")
#pragma comment(lib, "osgManipulatord.lib")
#pragma comment(lib, "osgTextd.lib")
#pragma comment(lib, "osgSimd.lib")
#pragma comment(lib, "osgTerraind.lib")
#pragma comment(lib, "osgWidgetd.lib")
#pragma comment(lib, "osgUId.lib")
#pragma comment(lib, "osgShadowd.lib")
#pragma comment(lib, "osgAnimationd.lib")
#pragma comment(lib, "osgParticled.lib")
#pragma comment(lib, "osgPresentationd.lib")
#pragma comment(lib, "osgQOpenGLd.lib")
//osgearth库1个
#pragma comment(lib, "osgEarthd.lib")
//其他库2个
#pragma comment(lib, "glu32.lib") 
#pragma comment(lib, "opengl32.lib")
#else
#pragma comment(lib, "osg.lib")
#pragma comment(lib, "osgDB.lib")
#pragma comment(lib, "osgFX.lib")
#pragma comment(lib, "osgViewer.lib")
#pragma comment(lib, "osgVolume.lib")
#pragma comment(lib, "OpenThreads.lib")
#pragma comment(lib, "osgGA.lib")
#pragma comment(lib, "osgUtil.lib")
#pragma comment(lib, "osgManipulator.lib")
#pragma comment(lib, "osgText.lib")
#pragma comment(lib, "osgSim.lib")
#pragma comment(lib, "osgTerrain.lib")
#pragma comment(lib, "osgWidget.lib")
#pragma comment(lib, "osgUI.lib")
#pragma comment(lib, "osgShadow.lib")
#pragma comment(lib, "osgAnimation.lib")
#pragma comment(lib, "osgParticle.lib")
#pragma comment(lib, "osgPresentation.lib")
#pragma comment(lib, "osgQOpenGL.lib")

#pragma comment(lib, "osgEarth.lib")

#pragma comment(lib, "glu32.lib") 
#pragma comment(lib, "opengl32.lib")
#endif;

vs2017osg3.6.5osgearth3.2库,包含osgQOpenGL库-C++文档类资源-CSDN下载

  • 2
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aspiretop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值