Simple Fast Media LibraryIf you program in C++, Ruby, Python or whatever you need a library and many people as of late at Gamedev.net have been referring people to SFML. So what is SFML? It's exactly what the name suggest, simple-fast-media-library(SFML).
What I like from the start is that the main team only focuses on C/C++ that's great, there's also other bindings by users for .net, ruby, python, and even D(It's getting there but I prefer F for now). Personally don't use ruby or pythons bindings mainly due to the fact is that they don't work as "well" as they should, there's also ATI graphics card issues that are NOT a problem with the C/C++ versions. It's better if you just bind the language you want as a scripting language and leave the rest to C++ or C depending on which one you chose (C is great if your creating old school games and want to use what the original nes-snes did)
Now presumably I hope you know how to download a source and compile it to whatever you want to use for an IDE, I use Visual C++ 2010 Express as I'm not a fan of Code::Blocks. If not I'll have a blank version of SFML 1.6 pre-built for visual studio 2010 for you to use with a basic Main.cpp displaying "Hello World" on the screen.
Now a basic project for SFML is going to look something like this.
CODE
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
// Application Entry Point
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// Create the main rendering window
sf::RenderWindow app(sf::VideoMode(640, 480, 32), "SFML Window Caption Test");
// Application Loop
while(app.IsOpened())
{
// Event Processing
sf::Event event;
while(app.GetEvent(event))
{
// Window is closed
if(event.Type == sf::Event::Closed)
app.Close();
// Escape key pressed
if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
app.Close();
// Exeample of a Key Event
if (event.Key.Code == sf::Key::F1)
{
sf::Image Screen = app.Capture();
Screen.SaveToFile("screenshot.jpg");
}
}
// Clear the display
app.Clear();
// Update the display
app.Display();
}
return 0;
}
Now let's talk about "events" for a moment, events are used in every language library I've used, they're in C++, they're in Ruby, and they're most certainly in Python. So what are they? They're basically actions, now if you look at the Key event(action) example you see if you press "F1" you'll save a screenshot as "screenshot.jpg" but if you were saving multiple screenshots it'd be like "screenshot_"+NUM".jpg" or something like that. Just stick to snagit for screenshots but that's basically what event actions are for.
Now in my own project I'm binding Lua with C++ as it's super fast and was made to be embedded! so when I press "M" for example it's going to call my Menu.lua file and the script will run from there. Still messing and getting to know the binding a bit more before I get too technical.
There's a ton of things you can do out of the box with SFML, 2D, 2D-HD, even 3D with openGL! The only limit as for what I can tell is your programming ability and many believe this is what's going to take over the aging SDL(Standard development library), the sheer speed alone should make people switch over.
I haven't gone much into SFML only telling you what a few things are and where to even find SFML. In the next topic I'm going to teach you how to bind Lua with C++ and your assignment will be to get it working in a SFML project!
For those who want the SFML 1.6 build for C++ you can download it here.
Size: 30.1MB
Download:
Download SFMLJust to let you know there is a version 2.0 but I would hold off until it's officially released or a RC and with updated documentation and all of the current docs are for 1.6.