Being a classical musician, jazz musician and programmer I often write music programs: MIDI editors, converters and music notation editors. I always use C++ and wxWidgets as I want my programs to be portable between the Windows and the Linux/Unix world.
I encountered some problems with the graphics routines in wxWidgets. When looking for alternatives I found SFML ("Simple and Fast Multimedia Library") - one of the successors of opengl. SFML is basically a set of libraries with bindings in many languages. Among them C++ and D ("DSFML"). SFML is however not a complete replacement for UI APIs like wxWidgets: it concentrates on direct output to the screen and has no components for Windows widgets like entry fields, combo boxes or list boxes.I am rather satisfied with the execution speed, the clarity of the API and the portability of SFML. I was however very astonished to see (in the SFML support forums) people urged to use cmake instead of conventional make as build system. I wrote therefor two conventional make files for Windos with Mingw g++ and for Linux with GNU g++ (btw both from GNU) to show that SFML programs can easily be built with conventional make files. Some pathes must however be adapted.
I Include here a ZIP file that contains:
I normally use the make program from
Digital Mars (part of the C++ compiler) even with Mingw g++.
But the Mingw
make program works as well: it is named mingw32-make.exe.
Call the buil process as follows under Windows:
mingw32-make -f sfml2.mak
or under Linux:
make -f sfml2u.mak
I have appended an 'u' to the names of the make files under Linux.
Here is a sample make file for Windows:
OBJS=sfml2.o
CFLAGS=-static -DWIN32 -Ic:\Huckert\src\SFML\SFML-2.4.2\include
LFLAGS=-Lc:\huckert\src\SFML\SFML-2.4.2\lib -lsfml-main -lsfml-window -lsfml-graphics -lsfml-system -lsfml-audio
sfml2.exe: $(OBJS)
g++ -o sfml2.exe $(CFLAGS) $(OBJS) $(LFLAGS)
sfml2.o: sfml2.cpp
g++ -c $(CFLAGS) -o sfml2.o sfml2.cpp
clean:
del $(OBJS) sfml2.exe
This is really not complicated!
The following two screen shots show the results of my SFML
programs. The first image is from sample program sfml2.cpp
(see the ZIP file)
and demonstrates basic calls like drawing rectangles, drawing lines,
loading a font, drawing (rotated) texts
and loading a background image:
The second image shows the results of my experiences
when writing an output driver for a music notation editor.
The program noten.cpp (see the ZIP file) is
slightly more complex but also
better structured. The musical objects are painted via bitmaps
(images). It is important to set the transparency masks
for the images correctly. Another experience: if you use
subprograms (functions, routines, methods) as in the second sample
program then it is very important
that the SFML instances like sf:Texture, sf:Image
etc are allocated on the heap (via new or
malloc etc.) -
not on the stack as local storage! static memory
is also OK:
Copyright for all images, texts and software on this page: Dr. E. Huckert
If you want to contact me: this is my mail address