当前位置:网站首页>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教程
边栏推荐
- Guangzhou held work safety conference
- Master formula. (used to calculate the time complexity of recursion.)
- 关于 appium 启动 app 后闪退的问题 - (已解决)
- 【无标题】
- Aosikang biological sprint scientific innovation board of Hillhouse Investment: annual revenue of 450million yuan, lost cooperation with kangxinuo
- [untitled]
- Day26 IP query items
- Go language learning notes - structure
- [untitled]
- Leetcode skimming: binary tree 21 (verifying binary search tree)
猜你喜欢
博文推荐|Apache Pulsar 跨地域复制方案选型实践
2022a special equipment related management (boiler, pressure vessel and pressure pipeline) simulated examination question bank simulated examination platform operation
关于 appium 如何关闭 app (已解决)
Leetcode skimming: binary tree 27 (delete nodes in the binary search tree)
- Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
Sequoia China completed the new phase of $9billion fund raising
3D content generation based on nerf
How to continue after handling chain interruption / sub chain error removed from scheduling
Analysis of DHCP dynamic host setting protocol
Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
随机推荐
基于NeRF的三维内容生成
.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
Creation and assignment of graphic objects
达晨与小米投的凌云光上市:市值153亿 为机器植入眼睛和大脑
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
API query interface for free mobile phone number ownership
Sed of three swordsmen in text processing
Four functions of opencv
PACP学习笔记一:使用 PCAP 编程
日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
【学习笔记】AGC010
[learn microservice from 0] [01] what is microservice
PHP调用纯真IP数据库返回具体地址
MySQL importing SQL files and common commands
test
关于 appium 启动 app 后闪退的问题 - (已解决)
HZOJ #240. 图形打印四
【无标题】
国泰君安证券开户怎么开的?开户安全吗?
Practical example of propeller easydl: automatic scratch recognition of industrial parts