[solved] Problems with Example Loading Bar with oFusion

kintaro

09-01-2007 15:48:30

Hi, I am building an application that uses oFusion, and my app stops to work when I try to use Example Loading Bar of ogre samples in my own app.

So I tryied to implement the loading in other ogre samples and it worked very well. Next I implemented it in oSceneLoader demo to verify that is really with oFusion that is some imcompatiblity and it gave the same error that my program gaves.

The error is: nothing happens, the app stops, and gaves windows send error report window.

Anyone already tryied to implement the example loading bar with oFusion?

How can I implement example loading bar using oFusion?

Thanks for help

kintaro

14-01-2007 23:32:22

Maybe if I provide a code, it becomes more easy to someone find what I am doing wrong.

#include "ExampleApplication.h"

#include "ExampleLoadingBar.h"


// oScene loader library header file
#include "OgreOSMScene.h"

// Callback handler to post-process created objects
class oSceneCallback : public OSMSceneCallbacks {
public:

// We override the OnCreate method for cameras (See IXMLSceneCallbacks class)
void OnCameraCreate(Ogre::Camera* pCamera, TiXmlElement* pCameraDesc) {

// If a camera of name "FirstCamera" is loaded, it will be set as the default current
if(pCamera->getName() == "FirstCamera")
Ogre::Root::getSingleton().getAutoCreatedWindow()->getViewport(0)->setCamera(pCamera);
}

};


// Event handler to animate
class oSceneLibDemoFrameListener : public ExampleFrameListener
{
protected:

SceneManager* mSceneMgr;

public:
oSceneLibDemoFrameListener(SceneManager* sceneMgr, RenderWindow* win, Camera* cam)
: mSceneMgr(sceneMgr), ExampleFrameListener(win, cam)
{
}


bool frameStarted(const FrameEvent& evt)
{

static Real timeDelay = 0;
static Real currentTime = 0;

timeDelay -= evt.timeSinceLastFrame;

// We can cycle cameras with the 'c' key
if (mInputDevice->isKeyDown(KC_C) && timeDelay <= 0) {

Camera* firstCam;
Camera* currentCam = mWindow->getViewport(0)->getCamera();

Viewport* vp = mWindow->getViewport(0);

SceneManager::CameraIterator it = mSceneMgr->getCameraIterator();

if(it.hasMoreElements())
firstCam = it.peekNextValue();

while(it.hasMoreElements()) {

Ogre::Camera* cam = it.getNext();

if(currentCam == cam) {
Ogre::Camera* camera = it.hasMoreElements() ? it.getNext() : firstCam;
vp->setCamera(camera);
}
}

timeDelay = 0.5f;

}

// We update all loaded animations each frame
SceneManager::AnimationIterator animationIt = mSceneMgr->getAnimationIterator();

while(animationIt.hasMoreElements()) {
Animation* animation = animationIt.getNext();

const Animation::NodeTrackList& trackList = animation->_getNodeTrackList();

Animation::NodeTrackList::const_iterator it = trackList.begin();
Animation::NodeTrackList::const_iterator iend = trackList.end();

for(; it != iend; ++it) {
const Ogre::NodeAnimationTrack* track = it->second;
track->getAssociatedNode()->resetToInitialState();
}

currentTime += evt.timeSinceLastFrame;
animation->apply(currentTime);
}

// Call default
return ExampleFrameListener::frameStarted(evt);

}
};

class oSceneLibApplication : public ExampleApplication {
public:

oSceneLibApplication() {}

protected:

ExampleLoadingBar mLoadingBar;

void loadResources(void)
{
mLoadingBar.start(mWindow, 1, 1, 0.75);

// Turn off rendering of everything except overlays
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);

// Set up the world geometry link
/*ResourceGroupManager::getSingleton().linkWorldGeometryToResourceGroup(
ResourceGroupManager::getSingleton().getWorldResourceGroupName(),
mQuakeLevel, mSceneMgr);*/

// Initialise the rest of the resource groups, parse scripts etc
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
/*ResourceGroupManager::getSingleton().loadResourceGroup(
ResourceGroupManager::getSingleton().getWorldResourceGroupName(),
false, true);*/

// Back to full rendering
mSceneMgr->clearSpecialCaseRenderQueues();
mSceneMgr->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);

mLoadingBar.finish();
}

// Just override the mandatory create scene method
void createScene(void)
{
// Here is the code that will load the scene file
// A fixed filename "scene.osm" is implemented for this demo

// Create the scene loader
OSMScene oScene;

// Create an oE_Loader Callback object to post-process created objects
oSceneCallback oe_Callback;

// Initialises with the scene to be loaded and the callback if requiered
oScene.initialise("apt.osm", &oe_Callback);

// create and setup the scene in the root node
oScene.createScene();


mSceneMgr = oScene.getSceneManager();

// Create a default camera in case no cameras were saved in the scene
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,0,500));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5);

// Create one viewport, entire window
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

}

// The scene manager will be created by the Scene Loader lib
void chooseSceneManager(void) {}
void createCamera(void) {}
void createViewports(void) {}

// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new oSceneLibDemoFrameListener(mSceneMgr, mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}

};


I used the same code of example loading bar in others programs that did'nt use oSceneLoader, and it worked very well.

Do I have to modify something in the code of oSceneLoader in order to get loading bar working?

Thanks for help

Lioric

15-01-2007 16:08:50

You are using an previous version of the loader or the demo, download the latest

Use the "declareResources" method of the scene loader before loading the scene ("createScene"), and probably you need to put the scene loading code in the "LoadResources" method

kintaro

22-01-2007 11:30:19

Hi, thanks very much for your reply Lioric.

Well I have some doubt:

1- when you said that I am using an previous version of the loader, are you refering about oSceneLoader demo?

Case yes, I downloaded the new oSceneLoader and now I am testing loading bar in this new version.

2- I tried to put "declareResources" method before "createScene" method but it gives some errors during compilation.

Whwn you said to use "declareResources" method you mean to put this code below, just before createScene method?


void OSMScene::declareResources(void)
{
if(!mXMLDoc.isNull())
{

TiXmlElement* rootElem = mXMLDoc->RootElement();

try
{
// Get mesh filename from entities
TiXmlElement *pMeshNode = rootElem->FirstChildElement("entities");
if(pMeshNode)
{
// Iterate all meshes, creating them.
for (TiXmlElement* pMeshElem = pMeshNode->FirstChildElement();
pMeshElem != 0; pMeshElem = pMeshElem->NextSiblingElement())
{
// Declare mesh resource
const char *pszFileName = pMeshElem->Attribute("filename");
ResourceGroupManager::getSingleton().declareResource(pszFileName, "Mesh");
}
}
} catch(...)
{
}

}
}


Or you mean to put:

oScene.declareResources();

before:

oScene.createScene();

in "createScene" method? Just like this:

// Just override the mandatory create scene method
void createScene(void)
{
// Here is the code that will load the scene file
// A fixed filename "scene.osm" is implemented for this demo

// Create the scene loader
OSMScene oScene;



// Create an oE_Loader Callback object to post-process created objects
oSceneCallback oe_Callback;

// Initialises with the scene to be loaded and the callback if requiered
oScene.initialise("apt.osm", &oe_Callback);

oScene.declareResources();

// create and setup the scene in the root node
oScene.createScene();


mSceneMgr = oScene.getSceneManager();

// Get the list of cameras loaded with the scene
OSMScene::CameraList camList = oScene.getCameraList();

if(!camList.empty()) {

// If loaded with the scene, set the first camera as the default camera
mCamera = camList[0];

// A viewport has been created and assigned to the first camera automatically
// (The TSM needs it to initialize the terrain world geometry)
}
else {

// Create a default camera in case no cameras were saved in the scene

mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,0,500));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5);

// If a viewport was not automatically created, (no cameras saved in the scene)
// create a default viewport, entire window
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}

}


thanks very much for your help.

Lioric

23-01-2007 16:44:22

I will make some tests with loading bars later, and provide the results

kintaro

24-01-2007 11:35:59

Thanks very much Lioric. :D

kintaro

13-02-2007 16:52:52

Problem solved, this is a simple solution that worked very well for me.

I just create a new sceneManager and camera just to use loading bar with it, and put it in loadindResources function with loading bar code.

Later if you want, you can delete or destroy this new scene manager and new camera.

There are some other little modifications, but every thing I did is in the code below:

#include "ExampleApplication.h"

// oScene loader library header file
#include "OgreOSMScene.h"

#include "ExampleLoadingBar.h"



// Callback handler to post-process created objects
class oSceneCallback : public OSMSceneCallbacks {
public:

// We override the OnCreate method for cameras (See IXMLSceneCallbacks class)
void OnCameraCreate(Ogre::Camera* pCamera, TiXmlElement* pCameraDesc) {

// If a camera of name "FirstCamera" is loaded, it will be set as the default current
if(pCamera->getName() == "FirstCamera")
Ogre::Root::getSingleton().getAutoCreatedWindow()->getViewport(0)->setCamera(pCamera);
}

};


// Event handler to animate
class oSceneLibDemoFrameListener : public ExampleFrameListener
{
protected:

SceneManager* mSceneMgr;

public:
oSceneLibDemoFrameListener(SceneManager* sceneMgr, RenderWindow* win, Camera* cam)
: mSceneMgr(sceneMgr), ExampleFrameListener(win, cam)
{
}



bool frameStarted(const FrameEvent& evt)
{

static Real timeDelay = 0;
static Real currentTime = 0;

timeDelay -= evt.timeSinceLastFrame;

// We can cycle cameras with the 'c' key
if (mInputDevice->isKeyDown(KC_C) && timeDelay <= 0) {

Camera* firstCam;
Camera* currentCam = mWindow->getViewport(0)->getCamera();

Viewport* vp = mWindow->getViewport(0);

SceneManager::CameraIterator it = mSceneMgr->getCameraIterator();

if(it.hasMoreElements())
firstCam = it.peekNextValue();

while(it.hasMoreElements()) {

Ogre::Camera* cam = it.getNext();

if(currentCam == cam) {
Ogre::Camera* camera = it.hasMoreElements() ? it.getNext() : firstCam;
vp->setCamera(camera);
}
}

timeDelay = 0.5f;

}

// We update all loaded animations each frame
SceneManager::AnimationIterator animationIt = mSceneMgr->getAnimationIterator();

while(animationIt.hasMoreElements()) {
Animation* animation = animationIt.getNext();

const Animation::NodeTrackList& trackList = animation->_getNodeTrackList();

Animation::NodeTrackList::const_iterator it = trackList.begin();
Animation::NodeTrackList::const_iterator iend = trackList.end();

for(; it != iend; ++it) {
const Ogre::NodeAnimationTrack* track = it->second;
track->getAssociatedNode()->resetToInitialState();
}

currentTime += evt.timeSinceLastFrame;
animation->apply(currentTime);
}

// Call default
return ExampleFrameListener::frameStarted(evt);

}
};

class oSceneLibApplication : public ExampleApplication {
public:

SceneManager* mSceneMgr_0;

Camera* mCamera_0;

Viewport* vp;

oSceneLibApplication()
{}

protected:

ExampleLoadingBar mLoadingBar;

void loadResources(void)
{
mSceneMgr_0 = mRoot->createSceneManager(ST_GENERIC);

mRoot->_setCurrentSceneManager(mSceneMgr_0);

mCamera_0 = mSceneMgr_0->createCamera("PlayerCam_0");

vp = mWindow->addViewport(mCamera_0);

vp->setBackgroundColour(ColourValue(0,0,0));

vp->setCamera(mCamera_0);

mLoadingBar.start(mWindow, 1, 1, 0.75);

// Turn off rendering of everything except overlays
mSceneMgr_0->clearSpecialCaseRenderQueues();
mSceneMgr_0->addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
mSceneMgr_0->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);

//Initialise the rest of the resource groups, parse scripts etc
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
ResourceGroupManager::getSingleton().loadResourceGroup(
ResourceGroupManager::getSingleton().getWorldResourceGroupName(),
false, true);

// Back to full rendering
mSceneMgr_0->clearSpecialCaseRenderQueues();
mSceneMgr_0->setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);

mLoadingBar.finish();
}


// Just override the mandatory create scene method
void createScene(void)
{
// Here is the code that will load the scene file
// A fixed filename "scene.osm" is implemented for this demo

// Create the scene loader
OSMScene oScene;

// Create an oE_Loader Callback object to post-process created objects
oSceneCallback oe_Callback;

// Initialises with the scene to be loaded and the callback if requiered
oScene.initialise("yourSceneHere.osm", &oe_Callback);

// create and setup the scene in the root node
oScene.createScene();

//mSceneManager = oScene.getSceneManager();
mSceneMgr = oScene.getSceneManager();


// Get the list of cameras loaded with the scene
OSMScene::CameraList camList = oScene.getCameraList();

if(!camList.empty()) {

// If loaded with the scene, set the first camera as the default camera
mCamera = camList[0];

// A viewport has been created and assigned to the first camera automatically
// (The TSM needs it to initialize the terrain world geometry)
}
else {

// Create a default camera in case no cameras were saved in the scene

mCamera = mSceneMgr->createCamera("PlayerCam");
//mCamera = mSceneManager->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,0,500));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5);

// If a viewport was not automatically created, (no cameras saved in the scene)
// create a default viewport, entire window
//Viewport* vp = mWindow->addViewport(mCamera);
vp->setCamera(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}
}

// The scene manager will be created by the Scene Loader lib
void chooseSceneManager(void) {}
void createCamera(void) {}
void createViewports(void) {}

// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new oSceneLibDemoFrameListener(mSceneMgr, mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};

aneuryzma

22-06-2007 10:35:36

hi,

I have your same problem, but it still doesn't work. Can I use the ExampleLoadingBar, without include the exampleApplication.h ?

thank you