Here is an example on how to use SFML v2.1 for Window, Input, ... for Ogre v1.9
Note: Currently this only works on linux, changes to this line of code maybe required for other platforms. "misc["currentGLContext"] = Ogre::String("true");"
Performance appears to be very good.
I tried briefly to draw 2D Graphics via SFML but I wasn't able to get anything to show-up, I will have to look further into it.
The SFML related code is actually very short and simple, I did however provide a full Ogre example with a frame-listener, etc. But 99% of the provided code in the example isn't needed.
Thanks to this Ogre/GLFW Example
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=69853 I was able to get this working.
I hope you find this useful.
// g++ main.cpp -o main `pkg-config --libs --cflags OGRE` -lsfml-window -lsfml-graphics -lsfml-system -lGL
// SFML v2.1 Includes
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>
// Ogre v1.9 Includes
#include <Ogre.h>
#include <OgreFrameListener.h>
using namespace Ogre;
//
class MyFrameListener : public Ogre::FrameListener {
public:
bool frameStarted (const FrameEvent &evt);
bool frameEnded (const FrameEvent &evt);
bool frameRenderingQueued (const FrameEvent &evt);
};
//
bool MyFrameListener::frameStarted(const FrameEvent &evt) {
//std::cout << "Frame Started" << std::endl;
return true;
}
//
bool MyFrameListener::frameEnded(const FrameEvent &evt) {
//std::cout << "Frame Ended" << std::endl;
return true;
}
//
bool MyFrameListener::frameRenderingQueued(const FrameEvent &evt) {
//std::cout << "Frame Queued" << std::endl;
return true;
}
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "Ogre3D v1.9 and SFML v2.1", sf::Style::Default, sf::ContextSettings(32));
// Create an instance of the OGRE Root Class
Ogre::Root* ogreRoot = new Ogre::Root;
// Configures the application
if (!ogreRoot->restoreConfig())
ogreRoot->showConfigDialog();
ogreRoot->saveConfig();
// Create Rendering System, but don't initialise it.
ogreRoot->setRenderSystem(ogreRoot->getAvailableRenderers()[0]);
ogreRoot->initialise(false);
//
Ogre::NameValuePairList misc;
misc["currentGLContext"] = Ogre::String("true");
// Create a render window | Note: Window Title and Size are not important here.
Ogre::RenderWindow* ogreWindow = ogreRoot->createRenderWindow("Ogre Window", 800, 600, false, &misc);
ogreWindow->setVisible(true);
// Create Render Target
Ogre::RenderTarget *ogreRenderTarget = ogreWindow;
// Create Scene Manager
Ogre::SceneManager* ogreSceneMgr = ogreRoot->createSceneManager(Ogre::ST_GENERIC);
// Create a new camera
Ogre::Camera* ogreCamera = ogreSceneMgr->createCamera("Camer0");
ogreCamera->setPosition(Ogre::Vector3(0,0,10));
ogreCamera->lookAt(Ogre::Vector3(0,0,-300));
ogreCamera->setNearClipDistance(5);
// Create OGRE Viewport and Set Background Colour
Ogre::Viewport* vp = ogreWindow->addViewport(ogreCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
// Use the viewport to set the aspect ratio of the camera
ogreCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
// Add our model to our resources and index it
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("media/packs/Sinbad.zip", "Zip");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("media/models/", "FileSystem");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Set Scene Ambient Light.
ogreSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
// Create a new light.
Ogre::Light* light = ogreSceneMgr->createLight("Light0");
light->setPosition(20.0f, 80.0f, 50.0f);
// Create an instance of our model and add it to the scene
Ogre::Entity* ent = ogreSceneMgr->createEntity("Sinbad.mesh");
Ogre::SceneNode* entNode = ogreSceneMgr->createSceneNode("Character0");
entNode->attachObject(ent);
ogreSceneMgr->getRootSceneNode()->addChild(entNode);
entNode->setPosition(0,0,0);
// Create an instance of the MyFrameListener Class and add it to the root object
MyFrameListener* myListener = new MyFrameListener();
ogreRoot->addFrameListener(myListener);
// run the main loop
bool running = true;
while (running)
{
//Ogre::WindowEventUtilities::messagePump();
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
//glViewport(0, 0, event.size.width, event.size.height);
}
}
// clear the buffers
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.clear();
// draw...
ogreRoot->renderOneFrame();
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
delete myListener;
delete ogreRoot;
return 0;
}