This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Example.cpp
94 lines (73 loc) · 2.79 KB
/
Example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <Ogre.h>
#include <OgreApplicationContext.h>
#include "ImguiManager.h"
class ImguiExample : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
public:
ImguiExample() : OgreBites::ApplicationContext("OgreImguiExample")
{
}
bool frameStarted(const Ogre::FrameEvent& evt)
{
OgreBites::ApplicationContext::frameStarted(evt);
Ogre::ImguiManager::getSingleton().newFrame(
evt.timeSinceLastFrame,
Ogre::Rect(0, 0, getRenderWindow()->getWidth(), getRenderWindow()->getHeight()));
ImGui::ShowDemoWindow();
return true;
}
#ifndef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
void locateResources()
{
OgreBites::ApplicationContext::locateResources();
// we have to manually specify the shaders
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"../resources", "FileSystem", Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
}
#endif
void setup()
{
OgreBites::ApplicationContext::setup();
addInputListener(this);
Ogre::ImguiManager::createSingleton();
addInputListener(Ogre::ImguiManager::getSingletonPtr()->getInputListener());
// get a pointer to the already created root
Ogre::Root* root = getRoot();
Ogre::SceneManager* scnMgr = root->createSceneManager();
Ogre::ImguiManager::getSingleton().init(scnMgr);
// register our scene with the RTSS
Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);
Ogre::Light* light = scnMgr->createLight("MainLight");
Ogre::SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(0, 10, 15);
lightNode->attachObject(light);
Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
camNode->setPosition(0, 0, 15);
camNode->lookAt(Ogre::Vector3(0, 0, -1), Ogre::Node::TS_PARENT);
Ogre::Camera* cam = scnMgr->createCamera("myCam");
cam->setNearClipDistance(5); // specific to this sample
cam->setAutoAspectRatio(true);
camNode->attachObject(cam);
getRenderWindow()->addViewport(cam);
Ogre::Entity* ent = scnMgr->createEntity("Sinbad.mesh");
Ogre::SceneNode* node = scnMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject(ent);
}
bool keyPressed(const OgreBites::KeyboardEvent& evt)
{
if (evt.keysym.sym == 27)
{
getRoot()->queueEndRendering();
}
return true;
}
};
int main(int argc, char *argv[])
{
ImguiExample app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
return 0;
}