当前位置:网站首页>Ogre入门尝鲜
Ogre入门尝鲜
2022-07-07 11:05:00 【MirrorYuChen】
1.Ogre库编译
1.1 下载安装DIrectX SDK
从下面链接下载和安装DirectX SDK:
下载地址:DirectX SDK
1.2 从git拉取最新代码
>> git clone --recursive [email protected]:OGRECave/ogre.git
>> git checkout v13.4.1
1.3 使用CMake编译Ogre
这里推荐使用cmake-gui,按照我这边的经验,一次就可以编译通过,最后在编译路径下会生成一个sdk文件夹,里面包含所有编译文件。
2.Ogre配置
2.1 将sdk子目录下的bin目录添加到path路径
2.2 新建一个vs工程,配置sdk路径下的include和lib
include路径添加如下:
lib路径添加如下:
添加附加依赖项:
3.添加测试代码
#include <iostream>
#include "Ogre.h"
#include "OgreApplicationContext.h"
#include "OgreInput.h"
#include "OgreRTShaderSystem.h"
using namespace Ogre;
using namespace OgreBites;
class Basic :
public ApplicationContext,
public InputListener {
public:
Basic();
virtual ~Basic() {}
void setup();
bool keyPressed(const KeyboardEvent& evt);
};
Basic::Basic() : ApplicationContext("Ogre") {}
void Basic::setup() {
// 1.调用父类
ApplicationContext::setup();
addInputListener(this);
// 2.获取一个指针指向已经创建的root
Root* root = getRoot();
SceneManager* scnMgr = root->createSceneManager();
// 3.注册我们的scene
RTShader::ShaderGenerator* shadergen = RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);
// 4.调节灯光
scnMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
// 5.新灯光
Light* light = scnMgr->createLight("MainLight");
SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->attachObject(light);
// 6.灯光位置
lightNode->setPosition(20, 80, 50);
// 7.相机
SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
Camera* cam = scnMgr->createCamera("myCam");
cam->setNearClipDistance(5);
cam->setAutoAspectRatio(true);
camNode->attachObject(cam);
camNode->setPosition(0, 0, 140);
// 8.告诉他渲染到主窗口
getRenderWindow()->addViewport(cam);
// 9.Entity
Entity* ogreEntity = scnMgr->createEntity("ogrehead.mesh");
SceneNode* ogreNode = scnMgr->getRootSceneNode()->createChildSceneNode();
ogreNode->attachObject(ogreEntity);
// 10.移动相机
camNode->setPosition(0, 47, 222);
// 11.Entity2
Entity* ogreEntity2 = scnMgr->createEntity("ogrehead.mesh");
SceneNode* ogreNode2 = scnMgr->getRootSceneNode()->createChildSceneNode(Vector3(84, 48, 0));
ogreNode2->attachObject(ogreEntity2);
// 12.Entity3
Entity* ogreEntity3 = scnMgr->createEntity("ogrehead.mesh");
SceneNode* ogreNode3 = scnMgr->getRootSceneNode()->createChildSceneNode();
ogreNode3->setPosition(0, 104, 0);
ogreNode3->setScale(2, 1.2, 1);
ogreNode3->attachObject(ogreEntity3);
// 13.Entity4
Entity* ogreEntity4 = scnMgr->createEntity("ogrehead.mesh");
SceneNode* ogreNode4 = scnMgr->getRootSceneNode()->createChildSceneNode();
ogreNode4->setPosition(-84, 48, 0);
ogreNode4->roll(Degree(-90));
ogreNode4->attachObject(ogreEntity4);
}
bool Basic::keyPressed(const KeyboardEvent& evt) {
if (evt.keysym.sym == SDLK_ESCAPE) {
getRoot()->queueEndRendering();
}
return true;
}
int main(int argc, char** argv) {
try {
Basic app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
}
catch (const std::exception& e) {
std::cerr << "Error occurred during execution: " << e.what() << '\n';
return 1;
}
return 0;
}
4.处理资源加载问题
4.1 将sdk的bin文件夹下面所有.dll文件和.cfg文件拷贝到工程生成的.exe文件夹下
>> E:\vs_project\OgreTest\x64\Release
4.2 修改resources.cfg文件,设置资源加载路径
# Ogre Core Resources
[OgreInternal]
FileSystem=../../Media/Main
FileSystem=../../Media/RTShaderLib/GLSL
FileSystem=../../Media/Terrain/
# Resources required by the sample browser and most samples.
[Essential]
Zip=../../Media/packs/SdkTrays.zip
Zip=../../Media/packs/profiler.zip
FileSystem=../../Media/thumbnails
# Common sample resources needed by many of the samples.
# Rarely used resources should be separately loaded by the
# samples which require them.
[General]
# PBR media must come before the scripts that reference it
FileSystem=../../Media/PBR
FileSystem=../../Media/PBR/filament
FileSystem=../../Media/materials/textures/PBR
FileSystem=../../Media/materials/programs/GLSL
FileSystem=../../Media/materials/programs/GLSL120
FileSystem=../../Media/materials/programs/GLSL150
FileSystem=../../Media/materials/programs/GLSL400
FileSystem=../../Media/materials/programs/GLSLES
FileSystem=../../Media/materials/programs/SPIRV
FileSystem=../../Media/materials/programs/Cg
FileSystem=../../Media/materials/programs/HLSL
FileSystem=../../Media/materials/programs/HLSL_Cg
FileSystem=../../Media/materials/scripts
FileSystem=../../Media/materials/textures
FileSystem=../../Media/materials/textures/terrain
FileSystem=../../Media/models
FileSystem=../../Media/particle
FileSystem=../../Media/DeferredShadingMedia
FileSystem=../../Media/DeferredShadingMedia/DeferredShading/post
FileSystem=../../Media/PCZAppMedia
FileSystem=../../Media/materials/scripts/SSAO
FileSystem=../../Media/materials/textures/SSAO
FileSystem=../../Media/volumeTerrain
FileSystem=../../Media/CSMShadows
Zip=../../Media/packs/cubemap.zip
Zip=../../Media/packs/cubemapsJS.zip
Zip=../../Media/packs/dragon.zip
Zip=../../Media/packs/fresneldemo.zip
Zip=../../Media/packs/ogredance.zip
Zip=../../Media/packs/Sinbad.zip
Zip=../../Media/packs/skybox.zip
Zip=../../Media/volumeTerrain/volumeTerrainBig.zip
Zip=../../Media/packs/DamagedHelmet.zip
Zip=../../Media/packs/filament_shaders.zip
[BSPWorld]
Zip=../../Media/packs/oa_rpg3dm2.pk3
Zip=../../Media/packs/ogretestmap.zip
# Materials for visual tests
[Tests]
FileSystem=../Tests/Media
4.3 将sdk下资源文件Media夹拷贝到设置的路径
4.4 再次运行测试例子
参考资料
- [1] Ogre教程
边栏推荐
猜你喜欢
【无标题】
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
认养一头牛冲刺A股:拟募资18.5亿 徐晓波持股近40%
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
飞桨EasyDL实操范例:工业零件划痕自动识别
基于NeRF的三维内容生成
HZOJ #240. Graphic printing IV
处理链中断后如何继续/子链出错removed from scheduling
【学习笔记】AGC010
随机推荐
leecode3. 无重复字符的最长子串
【无标题】
@What is the difference between resource and @autowired?
测试下摘要
Ip2long and long2ip analysis
Image pixel read / write operation
How to continue after handling chain interruption / sub chain error removed from scheduling
环境配置篇
HZOJ #235. 递归实现指数型枚举
Master formula. (used to calculate the time complexity of recursion.)
[untitled]
2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
怎样重置火狐浏览器
“新红旗杯”桌面应用创意大赛2022
Awk of three swordsmen in text processing
《ASP.NET Core 6框架揭秘》样章[200页/5章]
JS中为什么基础数据类型可以调用方法
How to apply @transactional transaction annotation to perfection?
JNA学习笔记一:概念