Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - caracal

Pages: [1]
1
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;
}
 

2
General discussions / SFML2 & OpenSceneGraph (Here is a Code Example)
« on: January 01, 2012, 11:57:58 am »
I see the same question asked over and over again how do you
get 3d graphics in sfml? Well here is a simple example.

All you need is SFML2 and OpenSceneGraph v3

Code: [Select]


// g++ main.cpp -o main -lsfml-window -lsfml-graphics -lsfml-system -losg -losgDB -losgGA -losgUtil

#include <SFML/Graphics.hpp>

#include <osgUtil/SceneView>
#include <osg/Node>
#include <osg/CameraNode>
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osg/PositionAttitudeTransform>


int  main()
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "SFML2 OpenSceneGraph Example1");


    // Load a sprite to display
    sf::Texture texture;
    if (!texture.LoadFromFile("../data/background.jpg"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);
     
     

        // OSG Code Start
       
         // View
osgUtil::SceneView* viewer = new osgUtil::SceneView();
viewer->setDefaults();
 
        // Camera
        osg::Camera* camera;
camera = viewer->getCamera();
camera->setViewport(20, 20, 640, 480);
camera->setClearColor(osg::Vec4(0, 0, 0, 0));

        // Root Scene Node
osg::Group* root = new osg::Group();
 
        // Transformation Object for our 3D Model
osg::PositionAttitudeTransform* meshTrans = new          
        osg::PositionAttitudeTransform();
meshTrans->setPosition(osg::Vec3d( 3,  0, -6));

        // 3D Model
osg::Node* mesh = osgDB::readNodeFile("../data/ship.3ds");
root->addChild(meshTrans);
meshTrans->addChild(mesh);

        // Set Root Scene Node to View and Init Vew
viewer->setSceneData(root);
viewer->init();

       // OSG Code End


// Start the game loop
        while (window.IsOpened())
        {
        // Process events
          sf::Event event;
          while (window.PollEvent(event))
          {
              // Close window : exit
              if (event.Type == sf::Event::Closed)
                  window.Close();
          }
         
        window.Clear();
       
        window.Draw(sprite);
       

                // OSG Code Start

        window.SaveGLStates();
viewer->update();
viewer->cull();
viewer->draw();
window.RestoreGLStates();

                // OSG Code End


window.Display();
}
}


Screenshot



Hope that helps

3
SFML projects / Zester Project (Software Development Toolkit)
« on: May 26, 2010, 08:32:26 pm »

Larger screenshot

Zester is a application development framework used for the development of GUI programs (in which case it is known as a widget toolkit), and also used for developing non-GUI programs such as console tools and servers.

Please keep in mind I code in C first then C++ because its easier to write language bindings for C verses C++.

Window Management
Xlib is an X Window System protocol client library in the C programming language. It
contains functions for interacting with an X server. These functions allow programmers to
write programs without knowing the details of the protocol. Few applications use Xlib
directly; rather, they employ other libraries that use Xlib functions to provide widget toolkits
http://www.x.org/wiki/

When integrating SFML with X11 as seen in http://www.sfml-dev.org/tutorials/1.6/graphics-x11.php there are a few things to keep in mind.

1. X11 is a 26 year old code base.
2. Setting a windows attributes before its show is done differently then after it is shown.
3. Setting attributes of a window and performing windowing functions is done differently when there is already a NETWM compliant window manager in place then when there is not.

Once I finish the Basic Window Management Functions I will continue on with Advance Window Management Functions, Input & Event Functions.
 
Basic Window Management Functions
zst_window_create
zst_window_destroy
zst_window_resize
zst_window_move
zst_window_resize_move
zst_window_show
zst_window_hide
zst_window_raise
zst_window_lower
zst_window_restack
zst_window_minimize
zst_window_unminimize
zst_window_maximize
zst_window_unmaximize
zst_window_fullscreen
zst_window_unfullscreen
zst_window_clear
zst_window_iconify
zst_window_deiconify
zst_window_stick
zst_window_unstick
zst_window_set_keep_above
zst_window_set_keep_below
zst_window_set_opacity
zst_window_flush
zst_window_set_min_size
zst_window_set_max_size
zst_window_set_base_size
zst_window_set_title
zst_window_set_skip_pager
zst_window_set_skip_taskbar
zst_window_set_override_redirect

Window Types
Desktop
Dock
Toolbar
Menu
Utility
Splash
Dialog
Normal


Multimedia
Simple and Fast Multimedia Library (SFML) is an object-oriented, cross-platform,
free and open source software multimedia API written in C++ by Laurent Gomila. It is
intended as a more modern alternative to SDL with a greater emphasis on OOP.
http://www.sfml-dev.org/

2D Vector Graphic Library:
Cairo is a 2D graphics library with support for multiple output devices. Currently
supported output targets include the X Window System, Quartz, Win32, image buffers,
PostScript, PDF, and SVG file output. Experimental backends include OpenGL (through
glitz), XCB, BeOS, OS/2, and DirectFB.
http://cairographics.org/

Image Processing Library:
Magick++ is a software suite to create, edit, and compose bitmap images.
It can read, convert and write images in a variety of formats (over 100) including
DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and
TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform
images, adjust image colors, apply various special effects, or draw text, lines, polygons,
ellipses and Bézier curves.
http://www.imagemagick.org/Magick++/

3D Graphics Engine:
Horde3D is a small open source 3D rendering engine. It is written in an effort to
create a graphics engine that offers the stunning visual effects expected in next-generation
games while at the same time being as lightweight and conceptually clean as possible.
http://www.horde3d.org/

Web Browser Engine:
Berkelium is a library that provides off-screen browser rendering via Google’s open
source Chromium and takes advantage of Chromium’s multi-process rendering engine,
allowing us to safely isolate browser instances.
http://github.com/sirikata/berkelium

Audio Synthesis:
Nsound is a C++ framework for audio synthesis. It aims to be as powerful as Csound
 but with the programming features of C++. Nsound tries to make the process of
generating complex and interesting sound as easy for the programmer as possible.
http://nsound.sourceforge.net/

2D Physics Library:
Box2D is a 2D rigid body simulation library for games.
http://www.box2d.org/index.html

3D Physics Library:
Bullet is an open source software multi-threaded 3D collision detection, soft body
and rigid body dynamics library (physics engine) for games and visual effects in film.
http://bulletphysics.org

Audio & Video:
OpenCV is a computer vision library originally developed by Intel. It is free for use
under the open source BSD license. The library is cross-platform. It focuses mainly on
real-time image processing. If the library finds Intel's Integrated Performance Primitives
on the system, it will use these commercial optimized routines to accelerate itself.
http://opencv.willowgarage.com/wiki/

Scripting
Lua combines simple procedural syntax with powerful data description constructs based on
associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting
bytecode for a register-based virtual machine, and has automatic memory management
with incremental garbage collection, making it ideal for configuration, scripting, and rapid
prototyping.
http://www.lua.org/

Pages: [1]
anything