Operating System: Linux
Render System: GL3PlusRenderer
I don't use the Samples/2.0/Common/... framework because it's setup to be relied upon by a bunch of tutorials, too complex because of that, and just for my app I'd like to make it easier to distribute. Below is a cutdown example of my code which I hope gives the idea of what I'm doing. It's like this because the user opens a file and when I process the file, I then add it as a scene node. I have a few problems here.
In createScene() I've created a static mesh just as is done in APIUsage/DynamicGeometry samples via createStaticMesh() and it returns an Ogre::MeshPtr which I add to a vector. Then immediately after, I add it to the scene as an item. Somehow I don't believe this is correct because in doing this, I've had to do the following two steps.
1) I have a static 'called' flag in createScene(), and it's there because if I don't add it, I'll rightfully get an 'already exists' error for the item as it would be trying to create the item multiple times.
2) I have a similar mesh_loaded flag (in frameRenderingQueued) just to say the user has already selected a file so call createScene() just once to create the scene items, otherwise, it'll shutdown.
This works, kind of, but I know it's not correct and hence my inexperience in all this. Can anyone help out and tell me how this is wrongly structured?
Code: Select all
class QtOgreWindow : public QWindow, public Ogre::FrameListener
{
// ...
};
void QtOgreWindow::initialize()
{
Ogre::ConfigFile ...
registerHlms();
ogreSceneManager = ...
ogreCamera = ...
ogreRoot->addFrameListener(this);
}
void QtOgreWindow::createScene()
{
static bool called = false;
Ogre::HlmsManager hlmsManager = ...
hlmsPbs->createDatablock( ... );
Ogre::HlmsMacroblock macroblock = ...
Ogre::MeshPtr mp;
if (called == false) {
for ( ; ; ) {
mp = createStaticMesh();
meshes.push_back(mp);
}
for (auto& m : meshes) {
Ogre::Item *item = ogreSceneManager->createItem(m, Ogre::SCENE_DYNAMIC);
item->setDatablock(block);
mSceneNode = ogreSceneManager->getRootSceneNode(Ogre::SCENE_DYNAMIC)->createChildSceneNode(Ogre::SCENE_DYNAMIC);
mSceneNode->attachObject(item);
mSceneNode->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.0f));
mSceneNode->setScale(Ogre::Vector3(2.0f, 2.0f, 2.0f));
}
}
}
QtOgreWindow::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
if (mesh_loaded)
createScene();
return true;
}