当前位置:网站首页>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教程
边栏推荐
- 免费手机号码归属地API查询接口
- HZOJ #235. Recursive implementation of exponential enumeration
- .Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
- 2022 examination questions and online simulation examination for safety production management personnel of hazardous chemical production units
- Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)
- 《开源圆桌派》第十一期“冰与火之歌”——如何平衡开源与安全间的天然矛盾?
- @What is the difference between resource and @autowired?
- [untitled]
- 【学习笔记】zkw 线段树
- Four functions of opencv
猜你喜欢
[untitled]
ISPRS2021/遥感影像云检测:一种地理信息驱动的方法和一种新的大规模遥感云/雪检测数据集
聊聊Redis缓存4种集群方案、及优缺点对比
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
【Presto Profile系列】Timeline使用
基于NeRF的三维内容生成
Star Enterprise Purdue technology layoffs: Tencent Sequoia was a shareholder who raised more than 1billion
Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)
Analysis of DHCP dynamic host setting protocol
Go language learning notes - structure
随机推荐
【学习笔记】AGC010
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
test
Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)
The difference between cache and buffer
HZOJ #235. 递归实现指数型枚举
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
聊聊Redis缓存4种集群方案、及优缺点对比
PHP calls the pure IP database to return the specific address
PHP调用纯真IP数据库返回具体地址
飞桨EasyDL实操范例:工业零件划痕自动识别
Ip2long and long2ip analysis
Blog recommendation | Apache pulsar cross regional replication scheme selection practice
File operation command
学习突围2 - 关于高效学习的方法
Differences between MySQL storage engine MyISAM and InnoDB
[untitled]
@What is the difference between resource and @autowired?
ip2long与long2IP 分析