Foreword: the vast majority of these informations and pieces of advice comes from the various members of the SDL mailing list. I hope that this thematical gathering will help the SDL users. Many thanks to the several SDL contributors! |
This section focuses on the listing of:
Due to the amount of relevant informations, this is still a document in progress and any help would be appreciated.
Around the SDL core library, there are some other libraries that provide complementary services. Each of these so-called standard libraries, whose name begins with "SDL_
", focuses on a particular theme:
Some less known SDL-related libraries exist, such as SDL_rtf, which allows to display Rich Text Format (RTF) documents in a SDL application.
Once written and tested, an application has to be officially released and distributed. As SDL-based applications are often cross-platform, the distribution and packaging concerns are particularly strong.
The most known library to display TrueType fonts in the SDL world is SDL_ttf.
Alternatives to SDL_ttf, other popular add-on libraries for rendering bitmap text, are SFont, Krnfont, and Kyra. They use a single bitmap image with spacing information in the top pixel row to define a font.
For simple text display, one can use the dedicated primitives provided by SDL_gfx (see stringColor
and stringRGBA
).
To get more control over one's text and less overhead, one might use FreeType directly, instead of going through SDL_TTF, although FreeType is deemed difficult to use that way.
One can use as well Glyph Keeper.
Bitmap Font Builder makes it easy to create bitmaps for use in OpenGL (and DirectX) applications.
The Polyfonts library draws text into all types of SDL surfaces. It works the same on software and hardware surfaces as it does on OpenGL surfaces, where the fonts are stored as geometry in the form of OpenGL rendering commands and vertex data. That means that all the fonts can be drawn in any size and any orientation.
Polyfonts has a large number of fonts converted to geometry, so they can be rendered without ever creating a texture. It includes a number of stroke fonts that can be drawn very quickly with OpenGL, but because of the large number of triangles needed to represent most outline fonts it can be a bit slow for rendering antialiased outline fonts. Use pre-rendering in that case.
Other OpenGL-related tools for fonts are OpenGL-FreeType Library (OGLFT) and, if you are working in C++, FTGL [homepage]. They both require FreeType and convert TTF fonts to geometry, and then render then from that.
More infos about OpenGL textures related to fonts.
To display static or even TTF text, pre-rendering is the safe and efficient way. For text that changes, render all glyphs to surfaces or, with OpenGL, to textures. Paste them together to form text.
More precisely, for outline fonts one may render each glyph/size/color once when it is first used by the program, and convert it to a surface or texture at that point. Then the text is either drawn by surface blitting or texture mapping on quads, for each individual glyph in a string.
It also means one have a texture for each glyph that has been used; it is surprising how few glyphs are ever used. This method seems to be a good way to render antialiased text.
Since, with SDL_ttf for example, displaying Truetype fonts is made easy, one just has to find freely-distributable fonts for his application. This can be a tricky task, since many "free fonts" found in the Internet infringe licensing schemas. Here are some pointers to the most known fonts which are freely distributable, roughly sorted by decreasing confidence in their legality. Some of these fonts are released under the GPL license.
Please ensure that you have been granted permission or you obtained a license of use for the fonts you use, if they are not truly free for your needs.
The most beautiful fonts that are free for use often do not include enough characters for internationalization.
The SDL_ttf library is one of the standard SDL libraries. [Wiki]
SDL_ttf 2.x uses FreeType 2 (not 1.2, as stated in the docs).
text = TTF_RenderText_Solid( myFont, message, color )
, there must be a call to SDL_FreeSurface( text )
TTF_Closefont( myFont )
TTF_Quit()
TTF_OpenFont
does not seem to check it!)TTF_RenderText_Solid,
, that does not work on this platform. One may use, as a work-around, SDL_RenderText_Shaded
and set the colorkey of the surface.TTF_RenderText_Solid
and encountering problemsTTF_RenderText_Blended
One may see only empty squares instead of the expected characters. This little box is the default glyph that you get when you ask for nonexistent glyphs. Here are the most common reasons and solutions for that issue:
showfont
demo. The difference is that PaintShop is rendering the TTF font at 72 dpi, whereas SDL is rendering it at the dpi of your monitor, where is probably 96 dpi (hence
appearring smaller).
In SDL_ttf.c
, add the following:
|
|
Or see our LOANI automatic installer: generateSDL_ttf
in loani-requiredTools.sh
auto-corrects SDL_ttf.c
.
PhysicsFS is a file-system library. This efficient library is convenient, however it does not come packaged with most Linux distributions that allow you to install via CD. This is not a problem though in windows where you can just drop in the DLL.
With MinGW, to avoid main.c: undefined reference to `WinMain@16'
, use:
make LDFLAGS=-lmingw32
.
To be found here, its drawback is that Boost implies numerous dependencies.
One can use zziplib to read ZIP archives.
fnkdat provides a platform independant interface for determining common directory names [homepage].
http://www.etek.chalmers.se/~e8cal1/sge/
To compile SDL_gfx for Dev-Cpp or for Mingw32, basically you need to add a couple of defines that are not set by default:
|
One needs to simply compile the library sources (.c/.h) with the defines -DWIN32
and -DBUILD_DLL
when creating the DLL. Use the define -DWIN32
when using the DLL.
There are VC6 and VC7 project files included in the SDL_gfx distribution, but some users reported that there were not working properly.
The rotozoom routine creates a new surface. You usually use it like this (pseudocode):
|
This pre-rotates your images and caches them for later use. It works well for smaller images since caching uses memory. To get good quality, your input should be 32bit (i.e. PNG with transparency) and interpolation should be enabled in the rotozoom routine.
A smarter approach would be to cache only a few images relevant to the current game state (i.e. angle-20, angle-10, angle, angle+10, angle+20) and re-render to update the cache as needed when the game state is changed. That way, you can optimize to save a rotozoom for every single state change.
Once you have the new surface, you can determine its center from its dimensions and blit as usual using clipping to limit its visibility to a rectangular area.
Here are some hardware accelerated vector graphics libraries:
Using dedicated vector graphics libraries can help a lot, since OpenGL and DirectX are much more low level. Consider the OpenGL calls which would be required to render this vector-graphic image.
Both Smoke and SVGL aim to render such vector graphics by converting the conventional vector-graphics primitives (gradient and radial fills; areas enclosed by implicit lines and curves; stroked contours etc.) into OpenGL primitives (filling commands and triangle meshes). The hardest part of this is the efficient tesselation of vector "areas" into triangle meshes
It can be performed thanks to SDL_gfx, it is bilinear but SDL_gfx is not as portable as SDL. Zooming is only supported for 8-bpp and 32-bpp surfaces.
A sdl-stretch library is available too.
Hardware acceleration does not occur in windowed mode. Stephane Marchesin made a new SDL video backend that uses OpenGL to scale the display.
This backend uses another backend to get the window creation and keyboard handling stuff, so it is "portable". For now, it is only tested under linux/X11/i386 but it should work for other platforms with OpenGL support. It's by no means fast, but it can be useful.
Get the patch here. To choose the new screen size, do the following:
|
By default, a 2x window scaling is used.
plaympeg.c
example to learn how to use it. Blitting to an off-screen surface is recommended, since blitting directly to the screen might create timing problems, with SMPEG blitting over the other screen renderings without control. You really need to use threaded audio or SMPEG does not work very well. Not that it works particularly well anyway... If you are using Linux you are probably best off using ffmpeg, which is more work but is far better at the job. To overcome some SMPEG build issues, add -lstdc++
into the file smpeg-config
[more infos]. Note also that audio must have been initialized before playing videos with smpeg, even if the video does not have any sound. It looks like SMPEG only supports mpeg-1. The way to get SMPEG compiled with shared and static is to use ltconfig and ltmain.sh from the FINK project [see]. The project team gave up on 2001.
wxWindows
)You may also wish to look at the SDL library listing, which has, among other things, several GUI libraries listed.
Mix_LoadWAV
and Mix_PlayChannel
from the main threadSee also: our sound with SDL section.
Fast events is basically a replacement for the event handling functions in SDL. It gets rid of the 10 ms delay (Linux 2.4 time-slice) in the WaitEvent function, and uses threads to update/change the event queue. This makes the event handling go faster.
OGLCONSOLE is a GPL powerful "never-fail" quake-style drop-down interactive command console for all OpenGL applications.
Thanks to David Wührer for having checked the links.
If you have information more detailed or more recent than those presented in this document, if you noticed errors, neglects or points insufficiently discussed, drop us a line!