OGRE 开源项目使用教程
1. 项目的目录结构及介绍
OGRE(Open Graphics Engine)是一个开源的3D图形渲染引擎。以下是OGRE项目的主要目录结构及其介绍:
ogre/
├── CMake/
│ ├── Toolchains/
│ └── Utils/
├── Components/
│ ├── Bites/
│ ├── Hlms/
│ ├── Overlay/
│ ├── Paging/
│ ├── Property/
│ ├── RTShaderSystem/
│ ├── Terrain/
│ └── Volume/
├── Docs/
│ ├── Manual/
│ └── API/
├── PlugIns/
│ ├── CgProgramManager/
│ ├── OctreeSceneManager/
│ ├── ParticleFX/
│ └── STBICodec/
├── Samples/
│ ├── 2.0/
│ └── 1.12/
├── Tools/
│ ├── OgreXMLConverter/
│ └── ParticleEditor/
├── CMakeLists.txt
├── LICENSE
├── README.md
└── ogre.sln
目录介绍
CMake/
: 包含CMake构建系统的工具链和实用程序。Components/
: 包含OGRE的各种组件,如Bites(输入处理)、Hlms(高级材质系统)等。Docs/
: 包含OGRE的手册和API文档。PlugIns/
: 包含OGRE的插件,如Cg程序管理器、Octree场景管理器等。Samples/
: 包含OGRE的示例项目。Tools/
: 包含OGRE的工具,如OgreXMLConverter和ParticleEditor。CMakeLists.txt
: CMake构建文件。LICENSE
: 项目许可证。README.md
: 项目自述文件。ogre.sln
: Visual Studio解决方案文件。
2. 项目的启动文件介绍
OGRE项目的启动文件通常是示例项目中的一个可执行文件。以Samples/2.0/ExampleApplication
为例,启动文件为ExampleApplication.cpp
。
ExampleApplication.cpp
#include "Ogre.h"
#include "OgreApplicationContext.h"
#include "OgreInput.h"
#include "OgreRTShaderSystem.h"
#include <iostream>
class ExampleApplication : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
public:
ExampleApplication();
void setup();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
};
ExampleApplication::ExampleApplication() : OgreBites::ApplicationContext("OgreExample")
{
}
void ExampleApplication::setup()
{
OgreBites::ApplicationContext::setup();
addInputListener(this);
Ogre::Root* root = getRoot();
Ogre::SceneManager* scnMgr = root->createSceneManager();
Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);
Ogre::SceneNode* node = scnMgr->createSceneNode("Node1");
scnMgr->getRootSceneNode()->addChild(node);
Ogre::Entity* ent = scnMgr->createEntity("Sinbad.mesh");
node->attachObject(ent);
Ogre::Light* light = scnMgr->createLight("MainLight");
Ogre::SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(0, 10, 15);
lightNode->attachObject(light);
Ogre::Camera* cam = scnMgr->createCamera("myCam");
cam->setNearClipDistance(5);
cam->setAutoAspectRatio(true);
Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
camNode->setPosition(0, 0, 15);
camNode->lookAt(Ogre::Vector3(0, 0, -1), Ogre::Node::TS_PARENT);
camNode->attachObject(cam);
OgreBites::InputContext inputContext = getInputContext();
OgreBites::NativeWindowPair window = createWindow("
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考