Blender2Ogre
19-07-2012 21:37:53
Hi dude,
thx for replying...ive been trying to use ur solution but i cant get it to work..
i got the code here ,can u modify it to get it to work?
any help is greatly appreciated dude..
heres the code:
main.cpp ->
#include <iostream>
#include "main.h"
ProperOgreApp::ProperOgreApp()
:mRoot(0),
cam(0),
sceneMgr(0),
mWindow(0),
mResourcesCfg(Ogre::StringUtil::BLANK),
mPluginsCfg(Ogre::StringUtil::BLANK),
mInputMgr(0),
mMouse(0),
mKeyboard(0),
mShouldChangeRS(false),
mNextRS(RSC_NONE)
{
}
ProperOgreApp::~ProperOgreApp()
{
}
bool ProperOgreApp::initOgre(bool shouldChangeRS = false, Ogre::String rsName = "")
{
if (shouldChangeRS && rsName.length() == NULL)
std::cout << "WHAT THE HECK ARE YOU DOING ? \n";
mRoot = OGRE_NEW Ogre::Root("plugins_d.cfg");
if (!shouldChangeRS && rsName.length() == NULL)
{
//bool shouldContinue = mRoot->showConfigDialog() || mRoot->restoreConfig();
bool shouldContinue = mRoot->showConfigDialog();
if (!shouldContinue)
{
exit(0);
}else
mRoot->initialise(false);
mWindow = mRoot->createRenderWindow("Main Wnd", 1024, 768, false);
}
else if (shouldChangeRS && rsName.length() != NULL)
{
// Restores configuration from saved state
// Returns true if a valid saved configuration is
// available, and false if no saved config is
// stored, or if there has been a problem
Ogre::ConfigFile cfg;
try
{
// Don't trim whitespace
cfg.load("ogre.cfg", "\t:=", false);
}
catch (Ogre::Exception& e)
{
if (e.getNumber() == Ogre::Exception::ERR_FILE_NOT_FOUND)
{
return false;
}
else
{
throw;
}
}
Ogre::ConfigFile::SectionIterator iSection = cfg.getSectionIterator();
Ogre::RenderSystem* rs = mRoot->getRenderSystemByName(rsName);
while (iSection.hasMoreElements())
{
const Ogre::String& renderSystem = iSection.peekNextKey();
const Ogre::ConfigFile::SettingsMultiMap& settings = *iSection.getNext();
if (!rs)
{
// Unrecognised render system
continue;
}
Ogre::ConfigFile::SettingsMultiMap::const_iterator i;
for (i = settings.begin(); i != settings.end(); ++i)
{
mRoot->setRenderSystem(rs);
}
}
if (!rs)
{
// Unrecognised render system
return false;
}
Ogre::String err = rs->validateConfigOptions();
if (err.length() > 0)
return false;
mRoot->setRenderSystem(rs);
mRoot->initialise(false);
mWindow = mRoot->createRenderWindow("Main Wnd", 1024, 768, false);
}
Ogre::String rs = mRoot->getRenderSystem()->getName();
if (rs == "OpenGL Rendering Subsystem")
mChosenRender = RSC_GL;
else
mChosenRender = RSC_DX;
Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("Current Render System: " + mRoot->getRenderSystem()->getName());
return true;
}
void ProperOgreApp::initInput()
{
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
mWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
mInputMgr = OIS::InputManager::createInputSystem(pl);
mKeyboard = static_cast<OIS::Keyboard*>(mInputMgr->createInputObject(OIS::OISKeyboard, false));
mMouse = static_cast<OIS::Mouse*>(mInputMgr->createInputObject( OIS::OISMouse, true ));
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);
}
void ProperOgreApp::createScene()
{
sceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Mgr");
cam = sceneMgr->createCamera("main Cam");
vp = mWindow->addViewport(cam);
cam->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
cam->setPosition(0, 0, 300);
cam->lookAt(0, 0, -300);
// Load resources
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load("resources_d.cfg");
// Go through all sections & settings in the file
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
Ogre::String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
mPlatform = new MyGUI::OgrePlatform();
mPlatform->initialise(mWindow,sceneMgr);
mGUI = new MyGUI::Gui();
mGUI->initialise("MyGUI_Core.xml");
windowResized(mWindow);
MyGUI::ImageBox* Winmain = mGUI->createWidget<MyGUI::ImageBox>("",0, 0, 1024, 768, MyGUI::Align::Default, "Overlapped","GraphWindow");
MyGUI::ButtonPtr button = Winmain->createWidget<MyGUI::Button>("Button", 10, 10, 120, 26, MyGUI::Align::Stretch, "Main");
button->setCaption("Exit Game");
button->eventMouseButtonClick += MyGUI::newDelegate(this,&ProperOgreApp::quit);
MyGUI::WindowPtr window = Winmain->createWidget<MyGUI::Window>("WindowCSX", 300, 0, 390, 300, MyGUI::Align::Stretch, "Overlapped");
window->setCaption("3D Graphics Settings");
window->setMovable(false);
/*window->setSize(390,400);*/
window->setMaxSize(390,400);
window->setMinSize(390,400);
MyGUI::ComboBoxPtr combo = window->createWidget<MyGUI::ComboBox>("ComboBox",135,80,100,25, MyGUI::Align::Bottom, "Overlapped");
combo->setCaption("Resolution");
combo->addItem("640x480");
combo->addItem("800x600");
combo->addItem("1024x768");
combo->addItem("1280x600");
combo->addItem("1280x720");
combo->addItem("1280x760");
combo->addItem("1360x768");
combo->addItem("1366x768");
combo->setIndexSelected(2);
combo->setComboModeDrop(true);
combo->eventComboAccept += MyGUI::newDelegate(this, &ProperOgreApp::Resolution);
window->eventWindowButtonPressed += MyGUI::newDelegate(this, &ProperOgreApp::notifyWindowPressedMyGUI);
MyGUI::ButtonPtr Radio = window->createWidget<MyGUI::Button>("RadioButton" , 45, 25, 20, 20, MyGUI::Align::Stretch, "SharedLayer");
Radio->eventMouseButtonClick += MyGUI::newDelegate(this, &ProperOgreApp::DirectX);
MyGUI::TextBox* text = window->createWidget<MyGUI::TextBox>("TextBox", 30, 05, 70, 15, MyGUI::Align::Default, "Main");
text->setCaption("#ffffffDirectX");
text->setTextShadow(true);
MyGUI::ButtonPtr Radio2 = window->createWidget<MyGUI::Button>("RadioButton" , 310, 25, 20, 20, MyGUI::Align::Default, "SharedLayer");
Radio2->eventMouseButtonClick += MyGUI::newDelegate(this, &ProperOgreApp::OpenGL);
if (mChosenRender == RSC_DX)
Radio->setStateSelected(true);
else
Radio2->setStateSelected(true);
MyGUI::TextBox* text2 = window->createWidget<MyGUI::TextBox>("TextBox", 295, 05, 70, 15, MyGUI::Align::Default, "Main");
text2->setCaption("#ffffffOpenGL");
text2->setTextShadow(true);
MyGUI::ButtonPtr Radio3 = window->createWidget<MyGUI::Button>("RadioButton" , 310, 135, 20, 20, MyGUI::Align::Default, "SharedLayer");
Radio3->eventMouseButtonClick += MyGUI::newDelegate(this, &ProperOgreApp::FullScreen);
MyGUI::TextBox* text3 = window->createWidget<MyGUI::TextBox>("TextBox", 285, 115, 200, 15, MyGUI::Align::Default, "Main");
text3->setCaption("#ffffffFull Screen");
text3->setTextShadow(true);
MyGUI::ButtonPtr Radio4 = window->createWidget<MyGUI::Button>("RadioButton" , 45, 135, 20, 20, MyGUI::Align::Default, "SharedLayer");
Radio4->eventMouseButtonClick += MyGUI::newDelegate(this, &ProperOgreApp::WindowedMode);
MyGUI::TextBox* text4 = window->createWidget<MyGUI::TextBox>("TextBox", 05, 115, 200, 15, MyGUI::Align::Default, "Main");
text4->setCaption("#ffffffWindowed Mode");
text4->setTextShadow(true);
if (Radio4 || !Radio3)
{
Radio4->setStateSelected(true);
/*MyGUI::ResizingPolicy::Fill;*/
}else if (Radio3 || !Radio4)
{
Radio3->setStateSelected(true);
}
/*else
{
Radio4->setStateSelected(false);
Radio3->setStateSelected(true);
}*/
MyGUI::PopupMenu* w = Winmain->createWidget<MyGUI::PopupMenu>("PopupMenu", 800, 0, 300, 143, MyGUI::Align::Stretch, "Main");
w->addItem("#ffffffExpandable Item >", MyGUI::MenuItemType::Popup);
MyGUI::MenuCtrl* child = w->createItemChildAt(0);
child->addItem("Common Item");
child->addItem("Expandable Item", MyGUI::MenuItemType::Popup);
MyGUI::MenuCtrl* child2 = child->createItemChildAt(1);
child2->addItem("Common Item");
// Create scene
Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("headNode");
Ogre::Entity* ent = sceneMgr->createEntity("headEntity", "ogrehead.mesh");
node->attachObject(ent);
sceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
sceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
}
void ProperOgreApp::onUpdate()
{
mMouse->capture();
mKeyboard->capture();
if (mKeyboard->isKeyDown(OIS::KC_F1))
{
destroy();
initOgre(true, "OpenGL Rendering Subsystem");
initInput();
createScene();
}
else if (mKeyboard->isKeyDown(OIS::KC_F2))
{
destroy();
initOgre(true, "Direct3D9 Rendering Subsystem");
initInput();
createScene();
}
if (mShouldChangeRS && mNextRS != RSC_NONE)
{
destroy();
if (mNextRS == RSC_GL)
initOgre(true, "OpenGL Rendering Subsystem");
else
initOgre(true, "Direct3D9 Rendering Subsystem");
initInput();
createScene();
mShouldChangeRS = false;
mNextRS = RSC_NONE;
}
}
void ProperOgreApp::windowResized(Ogre::RenderWindow* rw)
{
unsigned int width, height, depth;
int left, top;
rw->getMetrics(width, height, depth, left, top);
const OIS::MouseState &ms = mMouse->getMouseState();
ms.width = width;
ms.height = height;
}
bool ProperOgreApp::keyPressed(const OIS::KeyEvent& arg)
{
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.key), arg.text);
return true;
}
bool ProperOgreApp::keyReleased(const OIS::KeyEvent& arg)
{
MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(arg.key));
return true;
}
bool ProperOgreApp::mouseMoved(const OIS::MouseEvent& arg)
{
MyGUI::InputManager::getInstance().injectMouseMove(arg.state.X.abs, arg.state.Y.abs, arg.state.Z.abs);
return true;
}
bool ProperOgreApp::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
MyGUI::InputManager::getInstance().injectMousePress(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id));
return true;
}
bool ProperOgreApp::mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
{
MyGUI::InputManager::getInstance().injectMouseRelease(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id));
return true;
}
void ProperOgreApp::quit(MyGUI::WidgetPtr button)
{
if(button)
exit(0);
}
void ProperOgreApp::OpenGL(MyGUI::WidgetPtr buttonGL)
{
mShouldChangeRS = true;
mNextRS = RSC_GL;
}
void ProperOgreApp::DirectX(MyGUI::WidgetPtr buttonDX)
{
mShouldChangeRS = true;
mNextRS = RSC_DX;
}
void ProperOgreApp::WindowedMode(MyGUI::WidgetPtr window)
{
/*int width, height;
width = vp->getActualWidth();
height= vp->getActualHeight();
mWindow->setFullscreen(true, width, height);*/
if(mWindow->getWidth() == 640 && mWindow->getHeight() == 480)
{
mWindow->setFullscreen(false,640,480);
}
else if(mWindow->getWidth() == 800 && mWindow->getHeight() == 600)
{
mWindow->setFullscreen(false,800,600);
}
else if(mWindow->getWidth() == 1024 && mWindow->getHeight() == 768)
{
mWindow->setFullscreen(false,1024,768);
}
else if(mWindow->getWidth() == 1280 && mWindow->getHeight() == 600)
{
mWindow->setFullscreen(false,1280,600);
}
else if(mWindow->getWidth() == 1280 && mWindow->getHeight() == 720)
{
mWindow->setFullscreen(false,1280,720);
}
else if(mWindow->getWidth() == 1280 && mWindow->getHeight() == 760)
{
mWindow->setFullscreen(false,1280,760);
}
else if(mWindow->getWidth() == 1360 && mWindow->getHeight() == 768)
{
mWindow->setFullscreen(false,1360,768);
}
else if(mWindow->getWidth() == 1366 && mWindow->getHeight() == 768)
{
mWindow->setFullscreen(false,1366,768);
}
}
void ProperOgreApp::FullScreen(MyGUI::WidgetPtr fullscreen)
{
//int width, height;
//width = vp->getActualWidth();
//height= vp->getActualHeight();
//
//mWindow->setFullscreen(true, width, height);
if(mWindow->getWidth() == 640 && mWindow->getHeight() == 480)
{
mWindow->setFullscreen(true,640,480);
}
else if(mWindow->getWidth() == 800 && mWindow->getHeight() == 600)
{
mWindow->setFullscreen(true,800,600);
}
else if(mWindow->getWidth() == 1024 && mWindow->getHeight() == 768)
{
mWindow->setFullscreen(true,1024,768);
}
else if(mWindow->getWidth() == 1280 && mWindow->getHeight() == 600)
{
mWindow->setFullscreen(true,1280,600);
}
else if(mWindow->getWidth() == 1280 && mWindow->getHeight() == 720)
{
mWindow->setFullscreen(true,1280,720);
}
else if(mWindow->getWidth() == 1280 && mWindow->getHeight() == 760)
{
mWindow->setFullscreen(true,1280,760);
}
else if(mWindow->getWidth() == 1360 && mWindow->getHeight() == 768)
{
mWindow->setFullscreen(true,1360,768);
}
else if(mWindow->getWidth() == 1366 && mWindow->getHeight() == 768)
{
mWindow->setFullscreen(true,1366,768);
}
}
void ProperOgreApp::Resolution(MyGUI::ComboBox* buttonRes, size_t index)
{
if (index == 0 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false, 640, 480);
window = mGUI->findWidget<MyGUI::ImageBox>("GraphWindow");
window->setSize(vp->getActualWidth(),vp->getActualHeight());
/* MyGUI::WindowPtr window = mGUI->findWidget<MyGUI::Window>("GraphWindow");
window->getActionScale();*/
/*mGUI->_resizeWindow();*/
/*mWindow->setFullscreen(false,640,480);
mWindow->update();
buttonRes->setAlign(MyGUI::Align::Center);*/
}
else if (index == 1 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,800,600);
}
else if (index == 2 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,1024,768);
}
else if (index == 3 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,1280,600);
}
else if (index == 4 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,1280,720);
}
else if (index == 5 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,1280,760);
}
else if (index == 6 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,1360,768);
}
else if (index == 7 && !mWindow->isFullScreen())
{
mWindow->setFullscreen(false,1366,768);
}
else if (index == 0 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true, 640, 480);
/*mWindow->setFullscreen(false,640,480);
mWindow->update();
buttonRes->setAlign(MyGUI::Align::Center);*/
}
else if (index == 1 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,800,600);
}
else if (index == 2 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,1024,768);
}
else if (index == 3 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,1280,600);
}
else if (index == 4 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,1280,720);
}
else if (index == 5 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,1280,760);
}
else if (index == 6 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,1360,768);
}
else if (index == 7 && mWindow->isFullScreen())
{
mWindow->setFullscreen(true,1366,768);
}
}
void ProperOgreApp::notifyWindowPressedMyGUI(MyGUI::WindowPtr _widget, const std::string& _name)
{
MyGUI::WindowPtr window = _widget->castType<MyGUI::Window>();
if (_name == "close") window->destroySmooth();
else if (_name == "minimized") {
// hide window and show button in your taskbar
}
else if (_name == "maximized") {
// maximized window
}
}
bool ProperOgreApp::render()
{
while(true)
{
// Pump window messages for nice behaviour
Ogre::WindowEventUtilities::messagePump();
onUpdate();
if(mWindow->isClosed())
{
return false;
}
// Render a frame
if(!mRoot->renderOneFrame()) return false;
}
}
void ProperOgreApp::destroy()
{
mInputMgr->destroyInputObject( mMouse );
mInputMgr->destroyInputObject( mKeyboard );
OIS::InputManager::destroyInputSystem(mInputMgr);
mInputMgr = 0;
mGUI->shutdown();
delete mGUI;
mGUI = 0;
mPlatform->shutdown();
delete mPlatform;
mPlatform = 0;
mWindow->destroy();
mWindow = 0;
delete mRoot;
}
int main()
{
ProperOgreApp* app = new ProperOgreApp;
app->initOgre();
app->initInput();
app->createScene();
while(app->render());
app->destroy();
delete app;
return 0;
}
main.h ->
#ifndef MAIN_H
#define MAIN_H
#include <Ogre.h>
#include <OIS.h>
#include "MyGUI.h"
#include "MyGUI_OgrePlatform.h"
enum RenderSystemChoice
{
RSC_GL,
RSC_DX,
RSC_NONE
};
class ProperOgreApp : public OIS::KeyListener, public OIS::MouseListener
{
public:
ProperOgreApp();
~ProperOgreApp();
bool initOgre(bool shouldChangeRS, Ogre::String rsName);
void initInput();
void createScene();
void onUpdate();
void windowResized(Ogre::RenderWindow* rw);
bool keyPressed(const OIS::KeyEvent& arg);
bool keyReleased(const OIS::KeyEvent& arg);
bool mouseMoved(const OIS::MouseEvent& arg);
bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
void quit(MyGUI::WidgetPtr button);
void OpenGL(MyGUI::WidgetPtr buttonGL);
void DirectX(MyGUI::WidgetPtr buttonDX);
void WindowedMode(MyGUI::WidgetPtr Windowed);
void FullScreen(MyGUI::WidgetPtr Fullscreen);
void Resolution(MyGUI::ComboBox* buttonRes, size_t index);
void notifyWindowPressedMyGUI(MyGUI::WindowPtr _widget, const std::string& _name);
bool render();
void destroy();
private:
Ogre::Root* mRoot;
Ogre::RenderWindow* mWindow;
Ogre::SceneManager* sceneMgr;
Ogre::Camera* cam;
Ogre::String mResourcesCfg;
Ogre::String mPluginsCfg;
OIS::Keyboard* mKeyboard;
OIS::Mouse* mMouse;
OIS::InputManager* mInputMgr;
MyGUI::Gui* mGUI;
MyGUI::OgrePlatform* mPlatform;
bool mShouldChangeRS;
RenderSystemChoice mNextRS;
RenderSystemChoice mChosenRender;
/*int mFrameCount;*/
MyGUI::RenderManager* mrm;
Ogre::SceneNode* node;
Ogre::Viewport* vp;
MyGUI::ImageBox* window;
/*char name[16];
Ogre::Entity* ent;*/
};
#endif
thx in advance,
Romulo Romero