Release notes

DSFML is a binding of the C++ library SFML (Simple and Fast Multimedia Library). Binding has been done with the CSFML (SFML for C language).
From the SFML website :

SFML is a portable and easy to use multimedia API written in C++. You can see it as a modern, object-oriented alternative to SDL. SFML is composed of several packages to perfectly suit your needs. You can use SFML as a minimal windowing system to interface with OpenGL, or as a fully-featured multimedia library for building games or interactive programs.

DSFML : Tutorials

You can found tutorials for C++ version on the official SFML website. Except some changes (see notables differences), D api is almost the same of the C++ SFML. You can also see the samples included with this SDK.

Modules dependancies
audio : system
graphics : system, window
network : system
system : nothing
window : system

For every module, you use in your project, you need to provide the corresponding CSFML shared library

Externals dependancies
audio : libsndfile-1.dll, OpenAL
graphics : freetype (only under Linux OS)
network : nothing
system : nothing
window : nothing
Import package
audio : import sfml.audio.all;
graphics : import sfml.graphics.all;
network : import sfml.network.all;
system : import sfml.system.all;
window : import sfml.window.all;
Installation and building

Just extract the content of the zip file in a directory of your choice and run dsss build in the import path. If you want to create sample, run dsss build from the samples folder. If you use Linux, SFML C++ libraries must be already installed.

Default building links the import lib of CSFML dll so the symbol resolving is handled by the os, you don't need init function.

The other one consists of dynamic loading of dll symbol at runtime by an init call. DSFML contains a simple DLL loader which would be compatible with Tango and Phobos and with Windows and Linux. You need to initialize DSFML module before any call (which can be done by calling init() function of the used module in a static module constructor in the module containing the main function).
If you want to use the dynamic version, you need to add -version=Dynamic switch when building the library AND when you build your project.
module main;

import dsfml.system.all;
import dsfml.window.all;

static this()
{
    // Calling any DSFML functions prior to initialisation will result in a runtime error
    version (Dynamic)
    { 
        dsfml.system.loader.init(); // Init the system package
        dsfml.window.loader.init(); // Init the window package 
    }
}
void main()
{
    //..
}

OS related

On windows OS, CSFML consists of only one one DLL per module (csfml-[module_name].dll). On Linux, each module needs two shared libraries, one for the C++ version (libsfml-[module_name].so) and the other for C interface (libcsfml-[module_name].so)

On linux OS, if you use dynamic symbol loading, you need to link your project with libdl.so ( -L-ldl ). This is done automacally if you use rebuild and import the system package. You need to install C and C++ SFML.

Usage

By default, DSFML uses DSSS as building tool (you can find the dsss.conf in the import folder), but you can invoke directly dmd compiler. Command line example :

With DSSS and/or Rebuild, you don't need to pre-build DSFML, all is handled by rebuild.

Import library creation (Windows)

Optlink can only link files in OMF intel format and compiler on Windows OS produces files in COFF/PE format. DSFML provide OMF converted import library (in the extlibs/lib folder), but if you need to recreate these libraries, Digital Mars have a tool to convert COFF/PE import library to OMF format : coffimplib.
coffimplib inlib[.lib] [outfile[.def|.lib]] [-f] [-(i|e|l)] [-v]

OpenGL usage

DSFML comes with translated headers (cf. licence) and import libraries (in OMF format) for windows opengl32 and Glu shared library. If you want to use OpenGL in your application, just import module dsfml.GL.gl and dsfml.GL.glu and link with the import library. For Linux users, just link with GL or GLU shared library included in your system. If your use rebuild or DSSS, just import dsfml.GL headers, link will be done automatically. You can, of course, use other openGL headers, DSFML comes with GL headers to provide an all-inclusive library, and because openGL headers are not part of any D compiler package, but these headers are optionnal (DSFML doesn't use it).

Package Description Notables differences between orignal SFML and the D binding Licence

DSFML source code is released under the term of zlib/png licence.

Quick start
import dsfml.system.all;     // System package is always needed by other packages
import dsfml.window.all;     // Window package contains some basics display classes
import dsfml.graphics.all;   // Graphics contains classes for Image, Sprite and Render Window

static this()
{
    version (Dynamic) // load dll symbols if necessary
    {
        dsfml.system.loader.init();
        dsfml.window.loader.init();
        dsfml.graphics.loader.init();
    }
}

void main()
{
    // We create a window for displaying our text
    RenderWindow app = new RenderWindow(VideoMode(800, 600, 32), "My first window");
    // We set a limit for the framerate to avoid CPU saturation.
    app.setFramerateLimit(100);
    
    // Let's create a shape to display
    Shape shape = Shape.circle(300, 300, 100, Color.WHITE);
    
    //Some instructions
    String str = new String("Use arrow keys to move the shape."w);
    str.setPosition(Vector2f(50, 50));
    
    Event evt; // The event structure
    while (app.isOpened())
    {
        
        // The event loop
        while (app.getEvent(evt))
        {
            // if the form has been closed ...
            if (evt.Type == Event.EventType.CLOSED)
                app.close();
            // or if a keyboard key has been pressed ...
            else if (evt.Type == Event.EventType.KEYPRESSED)
            {
                // ... we move our shape according to the key
                switch (evt.Key.Code)
                {
                    case KeyCode.UP :
                        shape.move(0, -5.f);
                    break;
                    case KeyCode.DOWN :
                        shape.move(0, 5f);
                    break;
                    case KeyCode.LEFT :
                        shape.move(-5f, 0);
                    break;
                    case KeyCode.RIGHT :
                        shape.move(5f, 0);
                    break;
                    default :
                    break;
                }
            }
        }
        
        // We draw our string on the render window
        app.draw(shape);
        // and our string
        app.draw(str);
        
        // And we display the window
        app.display();
    }
} 


Page generated by Ddoc.