使用osgearth使渲染地球中间被黑色遮挡

osg系列文章目录

前言

我使用的是osg3.6.5,osgearth3.2版本,使用osgearth使渲染地球,运行效果中间被黑色遮挡,不知道具体原因,请看下图
在这里插入图片描述

一、代码

#pragma once

#include <osg/Group>
#include <osgviewer/Viewer>
#include <osgDB/ReadFile>
#include <osgviewer/api/Win32/GraphicsWindowWin32>
#include <osgGA/TrackballManipulator>
#include <osgEarth/MapNode>
#include <osgEarth/Utils>
#include <osgEarth/EarthManipulator>
#include <osgEarth/SkyView>
#include <osgEarth/Units>
//#include <osgEarth/Util/SkyNode> // 确保包含 SkyNode 的定义

using namespace osgEarth;
using namespace osgEarth::Util;

class COSGObject
{
   
public:
	COSGObject(HWND hWnd);
	~COSGObject();

	void InitOSG();
	void InitSceneGraph();
	void InitCameraConfig();
	void PreFrameUpdate();
	void PostFrameUpdate();
	static void Render(void* ptr);
	void InitOsgEarth();

	osgViewer::Viewer* GetViewer();
private:
	HWND m_hWnd;
	osg::ref_ptr<osgViewer::Viewer> m_viewer;
	osg::ref_ptr<osg::Group> m_root;
	osg::ref_ptr<osgEarth::MapNode> m_mapNode;
	osg::ref_ptr<osgEarth::EarthManipulator> m_em;
};


#include "pch.h"
#include "COSGObject.h"

COSGObject::COSGObject(HWND hWnd)
{
   
	m_hWnd = hWnd;
	m_viewer = NULL;
	m_root = NULL;
}

COSGObject::~COSGObject()
{
   

}

void COSGObject::InitOSG()
{
   
	InitSceneGraph();
	InitCameraConfig();	
	InitOsgEarth();
}

void COSGObject::InitSceneGraph()
{
   
	//osg::ref_ptr<osg::Group> rr = new osg::Group;

	try {
   
		osgEarth::initialize();
		m_root = new osg::Group;
		m_root->addChild(osgDB::readNodeFile("../../vs2022_64bit_3rdParty_osg365_oe32/runtime/test/earthFile/china-simple.earth"));
	}

	catch(const std::exception& e) {
   
		AfxMessageBox(CString("Failed to create osg::Group in constructor: ") + CString(e.what()));
		throw std::runtime_error(std::string("Failed to create osg::Group in constructor: ") + e.what());
	}
}

void COSGObject::InitCameraConfig()
{
   
	RECT rect;
	m_viewer = new osgViewer::Viewer;
	//osg::ref_ptr<osgViewer::View> viewer = new osgViewer::Viewer;
	//osg::ref_ptr<osgViewer::Viewer> m_vv = new osgViewer::Viewer;
	::GetWindowRect(m_hWnd, &rect);
	osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
	osg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值