当前位置:网站首页>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教程
边栏推荐
- 环境配置篇
- 如何将 @Transactional 事务注解运用到炉火纯青?
- Steps of building SSM framework
- 2022 polymerization process test question simulation test question bank and online simulation test
- 飞桨EasyDL实操范例:工业零件划痕自动识别
- 智云健康上市:市值150亿港元 SIG经纬与京新基金是股东
- File operation command
- Visual stdio 2017 about the environment configuration of opencv4.1
- 有什么类方法或是函数可以查看某个项目的Laravel版本的?
- 抓细抓实抓好安全生产各项工作 全力确保人民群众生命财产安全
猜你喜欢

Image pixel read / write operation

Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)

Awk of three swordsmen in text processing

如何将 @Transactional 事务注解运用到炉火纯青?

Leetcode skimming: binary tree 22 (minimum absolute difference of binary search tree)

leecode3. 无重复字符的最长子串

2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)

明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东

【无标题】

滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
随机推荐
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
HZOJ #235. Recursive implementation of exponential enumeration
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
【Presto Profile系列】Timeline使用
【学习笔记】AGC010
Practical case: using MYCAT to realize read-write separation of MySQL
Day21 multithreading
飞桨EasyDL实操范例:工业零件划痕自动识别
Awk of three swordsmen in text processing
[difficult and miscellaneous]pip running suddenly appears modulenotfounderror: no module named 'pip‘
2022-07-07 Daily: Ian Goodfellow, the inventor of Gan, officially joined deepmind
初学XML
ip2long之后有什么好处?
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
Creation and assignment of graphic objects
Grep of three swordsmen in text processing
事务的七种传播行为
.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
Sed of three swordsmen in text processing
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作