Original Post
Hello, I have been following the Beginner's Tutorial 2 of the OGRE wiki. I wanted to customize the code by trying to make the "ninja" in the scene move when I press the U button
The user-input is supposedly being handled by SFML.
As far as I know, the Project is able to Build without linker errors, however, the application crashes the moment It tries to load the 3d scene after the dialogue for setting the graphics.
It gets the Buffer Overrun error dialogue
I was able to deduce that the problem occurs when I try to create the window for SFML. With the sf::Window line of code gone, It is able to work properly, as shown in my code
(note: I placed the event-handling code within comments to prove that the application crashes on the line that is supposed to create the sfml window for user input)
What is disabling my application from handling user input properly? Can it be solved? Do i even need to create an SFML window in the first place for user-input? How do I solve this problem?
I'm stumped, SFML has been a roadblock in my quest of handling user input. The OGRE tutorials are much more bearable since they teach me how to setup the project and insert the code, in my opinion. I wonder if i should still use SFML after this experiment of mine....
Cheers.
The user-input is supposedly being handled by SFML.
As far as I know, the Project is able to Build without linker errors, however, the application crashes the moment It tries to load the 3d scene after the dialogue for setting the graphics.
It gets the Buffer Overrun error dialogue
I was able to deduce that the problem occurs when I try to create the window for SFML. With the sf::Window line of code gone, It is able to work properly, as shown in my code
(note: I placed the event-handling code within comments to prove that the application crashes on the line that is supposed to create the sfml window for user input)
/*
-----------------------------------------------------------------------------
Filename: TutorialApplication.cpp
-----------------------------------------------------------------------------
This source file is part of the
___ __ __ _ _ _
/___\__ _ _ __ ___ / / /\ \ (_) | _(_)
// // _` | '__/ _ \ \ \/ \/ / | |/ / |
/ \_// (_| | | | __/ \ /\ /| | <| |
\___/ \__, |_| \___| \/ \/ |_|_|\_\_|
|___/
Tutorial Framework
http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#include "TutorialApplication.h"
//add SFML
#include<SFML\System.hpp>
#include<SFML\Window.hpp>
//#include<SFML\Graphics.hpp>
TutorialApplication::TutorialApplication(void)
{
}
TutorialApplication::~TutorialApplication(void)
{
}
//-------------------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
mSceneMgr->setAmbientLight(Ogre::ColourValue(0,0,0));
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja","ninja.mesh");
entNinja->setCastShadows(true);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);
//the plane
Ogre::Plane plane(Ogre::Vector3::UNIT_Y,0);
Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity","ground");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);
//materials for the floor
entGround->setMaterialName("Examples/Rockwall");
entGround->setCastShadows(false);
//lights
Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
pointLight->setType(Ogre::Light::LT_POINT);
pointLight->setPosition(Ogre::Vector3(0,150,250));
pointLight->setDiffuseColour(1.0,0.0,0.0);
pointLight->setSpecularColour(1.0,0.0,0.0);
//directional light
Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
directionalLight->setDiffuseColour(.25,0.25,0.0);
directionalLight->setSpecularColour(.25,0.25,0.0);
directionalLight->setDirection(Ogre::Vector3(0,-1,1));
//spotlight
Ogre::Light* spotLight = mSceneMgr->createLight("spotLight");
spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
spotLight->setDiffuseColour(0, 0, 1.0);
spotLight->setSpecularColour(0, 0, 1.0);
spotLight->setDirection(-1, -1, 0);
spotLight->setPosition(Ogre::Vector3(300, 300, 0));
spotLight->setSpotlightRange(Ogre::Degree(35),Ogre::Degree(50));
//SFML STUFF (The bug occurs when I try to create the next line
sf::Window App(sf::VideoMode(20, 20, 32), "SFML Window"); //Error occurs @ this line based on my deductions
/*
while(App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::U))
mSceneMgr->getRootSceneNode()->translate(Ogre::Vector3(10,0,0));
}
}
*/ //cout << system("cd");
}
void TutorialApplication::createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setPosition(Ogre::Vector3(0,10,500));
mCamera->lookAt(Ogre::Vector3(0,0,0));
mCamera->setNearClipDistance(5);
mCameraMan = new OgreBites::SdkCameraMan(mCamera);
}
void TutorialApplication::createViewports(void)
{
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth())/Ogre::Real(vp->getActualHeight()));
}
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create application object
TutorialApplication app;
try
{
app.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR| MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
What is disabling my application from handling user input properly? Can it be solved? Do i even need to create an SFML window in the first place for user-input? How do I solve this problem?
I'm stumped, SFML has been a roadblock in my quest of handling user input. The OGRE tutorials are much more bearable since they teach me how to setup the project and insert the code, in my opinion. I wonder if i should still use SFML after this experiment of mine....
Cheers.