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 :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 dependanciesFor every module, you use in your project, you need to provide the corresponding CSFML shared library
Externals dependanciesJust 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.
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.
UsageBy 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 :
[project.d]
buildflags += -I [path of DSFML source]
buildflags += -S [path of DSFML extlibs/lib, if you use non-dynamic version]
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]
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 DescriptionDSFML source code is released under the term of zlib/png licence.
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(); } }