Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Nexus

Pages: 1 ... 3 4 [5] 6 7
SFML wiki / Source quality
« on: April 25, 2011, 12:45:37 pm »

I am currently porting articles from the old to the new wiki. And especially at source codes, I see a problem: Some codes are badly documented, contain severe mistakes or suffer from being unmaintained.

Of course, the idea behind the wiki is that everyone can improve it, but applied to C++ code, this can be complicated. You never know whether the author likes it if his code is changed because the original intention may be distorted, the licenses are not always clear, and different users have different views concerning good code.

Since we have currently the opportunity to form the new wiki, I suggest to wait with porting articles of this kind, and inform the authors to allow them improving their articles. The navigation for wiki users (especially beginners) becomes easier if they don't have to face a huge mess of codes that are once written and never looked at again. Besides, the really good articles don't get lost like this.

What do you think? And how should this be handled in the future?

SFML projects / Thor C++ Library – An SFML extension
« on: April 18, 2011, 11:34:24 pm »

[Edit] This post is outdated. Please use now this thread to discuss about the next version of Thor.

Good evening,

I would like to present a project I have been working on the last time. Thor is an open-source C++ library which provides extensions of SFML. There have been a lot of feature requests in the forum that were either too high level or out of scope for integration into SFML. Nevertheless, some of them are very useful in game and multimedia programming. That is why I have implemented some of them, hoping that SFML users can benefit from the functionality.

Thor is completely free to use, like SFML it is licensed under zlib/libpng.


The Thor C++ library comes with the following small modules:

- 2D Vector algebra functions: Dot product, compute length and angles, ...
- 3D Vector algebra functions: Dot and cross product, compute length and angles, ...
- PolarVector: 2D vector class that stores polar coordinates

- Zone class hierarchy for geometric figures
- Base classes for positionable, rotatable and scalable objects

- ParticleSystem class based on sf::Image, stores and manages particles (lifetime, transformations, color, ...)
- Customizable Emitter and Affector classes

- SfmlEventSystem class to handle SFML events via callbacks
- EventSystem template for user-defined events

- ResourceManager class template that allows safe and easy loading, storage and access to resources
- ResourcePtr provides shared access to resources
- Predefined helper classes for SFML resources like sf::Image

- ConcaveShape class: As an extension to sf::Shape, it works with concave shapes
- Arrow class to visualize vectors
- Color blending and simple construction of color gradients
- String conversion functions for a few SFML classes like sf::Vector

- StopWatch class: Wrapper around sf::Clock for pausable clocks
- Timer class: Countdown mechanism
- TriggeringTimer class: Countdown invoking callbacks at expiration

- SingleDispatcher: Dynamic dispatch to unary functions
- DoubleDispatcher: Dynamic dispatch to binary functions (multimethods)
- Other utility like foreach macros

- ScopedPtr: Local RAII smart pointer
- MovedPtr: Movable smart pointer implementation
- CopiedPtr: Smart pointer with deep copy semantics

- Generalization of trigonometry functions
- Random number generator based on TR1
- Delaunay triangulation


You can download version 1.0 directly on my homepage. You will also find tutorials and the API documentation there. I use CMake to build the source code, but I also supply precompiled binaries for some configurations. Note that the library bases on the newest Git revisions of SFML 2.

In the next days, I am going to setup an SVN repository so that you are able to follow the development of the Thor C++ library.


I try to improve the library continuously, so I appreciate feedback, be it bug reports, feature requests or general discussions. Let me know what you like to be part of Thor, and I can think about it. One of the tasks I am planning to implement in near future is a design that allows easy animations with sf::Sprite, another example is a Z buffer.

General / CMake: Link to debug/release libraries in VS 2010
« on: April 11, 2011, 03:30:14 pm »
Hello, I try to link the SFML libraries in an executable I build with CMake. My problem is to choose the right configuration (debug/release) of the libraries. Normally, I could check CMAKE_BUILD_TYPE for this purpose.

However, Visual Studio (and maybe other IDEs) internally use both Release/Debug configurations independently of CMAKE_BUILD_TYPE. How is it possible to link "sfml-xy.lib" in Release and "sfml-xy-d.lib" in Debug mode? What do I have to pass to target_link_libraries()?

I have already looked at the SFML examples, but I haven't found out a lot. I am not used to macros, besides I don't know if the libraries are handled differently because they are built in the same CMake project as SFML itself. And is it correct that the FindSFML variable SFML_LIBRARIES always lists the Release libraries?

Graphics / sf::Sprite::SetImage - distorted rendering
« on: March 29, 2011, 08:15:10 pm »
Hello, the following code
Code: [Select]
int main()
    sf::RenderWindow window(sf::VideoMode(1000, 800), "SFML test");

    sf::Image image1;

    sf::Image image2; // smaller than image1

    sf::Sprite sprite(image1);

    while (window.IsOpened())
        sf::Event event;
        while (window.GetEvent(event))
            if (event.Type == sf::Event::Closed || event.Type == sf::Event::KeyPressed)
                return 0;

leads to a distorted rendering of image2. The sprite itself is drawn correctly, but besides it, the space of image1 is filled with artifacts. When I create the sprite directly with
Code: [Select]
sf::Sprite sprite(image2);everything is okay. Tell me if you need a screenshot or if I should add the issue to the task tracker.

By the way, the code uses the images of the OpenGL example.

General discussions / Angle signs in SFML
« on: March 26, 2011, 09:15:53 pm »

I have written some functionality in combination with vectors and angles. The more I use them, the more I think the way how SFML handles angles is not consistent. Relative to the screen, sf::Drawable::Rotate() rotates in counter-clockwise direction. But since the Y axis points downwards, the mathematical correct rotation would be clockwise.

This is not only a matter of taste. The status quo complicates the correct computation of angles. In screen coordinates, a vector with polar angle 90° points downwards, but rotating a drawable by 90° makes it "point" upwards (given angle 0° corresponds right). This is a problem when interacting with other objects on the screen. For example, a particle emitter that has the direction of the mentioned vector, emits the particles in a "wrong" direction (compared to sf::Drawable). The angle of sf::Drawable is also inconsistent with sf::View. Rotating both the view and the drawable by 1° should have no effects, however the drawable appears rotated by 2°.

Generally, the user has to flip the sign of the rotation before drawing, as soon as he computes screen objects like projectiles which require more complex vector algebra. While this is certainly possible, it is counter-intuitive and probably confusing for beginners, once they delve into trigonometry.

Therefore, my proposal is to change the angle sign in the sf::Drawable methods. I know it's not an easy decision to modify such a thing, but you should take the opportunity of SFML 2 before it is released :)

General / Finding SFML with CMake
« on: March 09, 2011, 07:58:14 pm »
Hello, I am using Windows 7. My SFML installation directory has this structure:
Code: [Select]
# C:/Program Files/C++ Libraries/SFML
  # include
    # SFML
  # lib
    # sfml-window.lib
    # sfml-window-d.lib
  # bin
    # sfml-window-2.dll
    # sfml-window-d-2.dll

I have looked at the FindSFML module and written the following small script (CMakeFiles.txt) in order to find out the SFML paths:
Code: [Select]
cmake_minimum_required (VERSION 2.8)
project (Experiment)

set(SFMLDIR "C:/Program Files/C++ Libraries/SFML")

find_package(SFML REQUIRED)
message("Directory = ${SFMLDIR}")
message("Include = ${SFML_INCLUDE_DIR}")
message("Release = ${SFML_WINDOW_LIBRARY}")
message("Debug = ${SFML_WINDOW_LIBRARY_DEBUG}")
message("Libraries = ${SFML_LIBRARIES}")

When I run CMake in the directory of this file, I get the following output:
Code: [Select]
Found SFML: C:/Program Files/C++ Libraries/SFML/include
Directory = C:/Program Files/C++ Libraries/SFML
Include = C:/Program Files/C++ Libraries/SFML/include
Release =
Debug =
Libraries =
Configuring done

Why are the libraries not found? Do I have to initialize variables apart from SFMLDIR?

Feature requests / Proposal to change identifiers
« on: January 02, 2011, 05:52:23 pm »

I think SFML 2 is a good opportunity to fix a few inconsistences regarding identifier names. I have some suggestions, even if they're not extremely crucial. Said enough, I'll just post how I personally see it ;)

  • sf::Shape's methods SetOutlineWidth and GetOutlineWidth should become SetOutlineThickness and GetOutlineThickness. This is consistent with the parameter names of the static factory methods, besides the notion of thickness is clearer (since width is often used together with height).
  • Now that sf::Window has a WaitEvent function, it is probably of advantage to call the counterpart PollEvent instead of GetEvent. First, it's not a classical getter method; second, "poll" expresses the operating principle in a better way and explicitly shows the difference to "wait".
  • Maybe rename sf::RenderWindow::UseVerticalSync to EnableVerticalSync. The documentation talks about "enabling", the parameter name is "enabled", and in this way you don't have three different prefixes for setter methods in sf::RenderWindow (SetPosition, EnableKeyRepeat, UseVerticalSync).
  • sf::Music contains the member functions OpenFromFile and OpenFromMemory. The other resource classes sf::Font, sf::Image and sf::SoundBuffer call the same methods LoadFromFile and LoadFromMemory. In principle, both names are possible, but I wouldn't mix them.
  • A parameter name concern: sf::Drawable has various overloads of SetScale and Scale. Most of the parameters are "factors", but SetScale(const sf::Vector2&) takes a "scale". I suggest to distinguish better between absolute and relative scale setters, or at least to use uniform names.

Graphics / Empty image semantics
« on: December 26, 2010, 03:04:33 pm »
Although this is rather a theoretical problem, I want to inform you about some observations I've made. The following code fails with a STL debug assertion (VS 2010):
Code: [Select]
#include <SFML/Graphics/Image.hpp>
int main()
sf::Image image;

The problem is the statement &pixels[0] in ImageLoader.cpp. As far as I know, if you access the 0th element of an empty std::vector, you evoke undefined behaviour.

There are a few other places (also in Image.cpp) where the access is unchecked. In some of them, you could handle it like in Image::CreateMaskFromColor():
Code: [Select]
if (myPixels.empty())

But I don't know if there is a convention how to represent empty image files. Anyway, you should probably make the semantics clearer or explicitly forbid some operations on singular sf::Image instances.

General / SFML and CMake with Ubuntu
« on: December 24, 2010, 12:36:20 am »
Hi, I've just set up Ubuntu 10.04 and I'm now trying to install SFML. I downloaded it via subversion, I also installed CMake (and its GUI version).

When I try to configure SFML, I get the following errors:
Code: [Select]
CMake Error at /usr/share/cmake-2.8/Modules/FindX11.cmake:372 (MESSAGE):
  Could not find X11
Call Stack (most recent call first):
  src/SFML/Window/CMakeLists.txt:77 (find_package)

A lot of entries contain a "NOTFOUND". How can I find out the correct paths to X11? Shouldn't they be recognized automatically?

When I try to install the X11 package ("sudo apt-get install x11-common"), I'm told my version is up-to-date. Sorry for this beginner question, but I'm not too familiar with Ubuntu.

Graphics / Bug with local sf::Image declarations?
« on: December 18, 2010, 02:39:27 am »
Hello, I use the SVN revision 1691 of SFML 2 and I compile with Visual Studio 2010. I just encountered a very strange behaviour. Given the following code, a blue sprite is drawn as expected:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
sf::RenderWindow app(sf::VideoMode(200, 200), "Title");

sf::Image image;
image.Create(30, 30, sf::Color::Blue);

for (;;)
sf::Event event;
while (app.GetEvent(event))
if (event.Type == sf::Event::KeyPressed)
return 0;


sf::Sprite sprite(image);


Now let's declare the sf::Image locally inside the loop (which may be inefficient, but not fundamentally wrong), like this:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
sf::RenderWindow app(sf::VideoMode(200, 200), "Title");

for (;;)
sf::Event event;
while (app.GetEvent(event))
if (event.Type == sf::Event::KeyPressed)
return 0;


sf::Image image;
image.Create(30, 30, sf::Color::Blue);
sf::Sprite sprite(image);


And what I get is a white sprite. :shock:

Actually, by observing it more precisely, I see it blue for a single frame (the first one), then it becomes white for the rest of the time.

I'm confused because the image is still in scope when the sprite is drawn. Must it exist any longer?

General discussions / Developing with CMake
« on: December 01, 2010, 08:43:46 pm »
Hello, I have a rather general question concerning CMake. I often hear it simplifies things, for developers as well as for users. I understand, that when CMake is correctly configured, it can be used for a large amount of compilers and IDEs.

But until one can configure it correctly to support a wide range of compilers, it seems to be a real pain, especially in the beginning. I've been surprised a little bit by the big amount of script and config files required for CMake just to generate SFML. Besides, a lot of cases (e.g. VS or g++) are still differentiated manually, while CMake promises to relieve developers of exactly this process. The recent quotation mark issue shows me that there are still several things that don't work as expected (maybe I should inform the CMake team about that).

I have considered using CMake to build own libraries in the future, but at the moment I'm rather sceptical. Also I would have to learn the CMake script language...

What is your experience (Laurent and other people using CMake to build own projects)?

General / CMake and Visual Studio 2010
« on: November 16, 2010, 09:31:28 pm »
Hello, I'm using Visual Studio 2010 and I've got problems to setup SFML with CMake. I followed the tutorial, performed the configure and generate steps and tried to compile the SFML libraries inside a MSVC++ solution. However, errors of the form
LINK : fatal error LNK1181: Input file "C:/Program" cannot be opened.
(translated) appeared. The reason is, the full paths specified in Project Properties -> Librarian -> Command Line -> Additional Options are subdirectories of C:/Program files/, and the space inside the string "Program files" is interpreted as argument-separator. A solution would be to write the whole argument inside "" quotation marks. Is there a possibility to adapt the CMake configuration correspondingly? I have already changed the variable GLEW_LIBRARY in CMake, but how about the other libraries?

And another question: Can I specify in CMake the directory where the libraries (.lib or .dll files) should be generated? It would be nice if I didn't have to change the paths inside the generated MSVC++ solution every time.

Thanks in advance!

Graphics / Blurred text at non-integral coordinates
« on: September 16, 2010, 05:02:40 pm »
Hi, the sf::Text class is not rendering properly when not aligned to integer coordinates. Example:

Complete and minimal code:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
sf::RenderWindow app(sf::VideoMode(640, 480), "Blurred text", sf::Style::Default);

sf::Text normal("This is how it should look");

sf::Text blurred("And this is the blurred version");
blurred.Move(0.5f, 20.5f);

for (;;)
sf::Event event;
while (app.GetEvent(event))
if (event.Type == sf::Event::Closed
|| event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::Escape)
return 0;


I remember there has been (or still is) a similar issue with sf::Sprite. There may be use cases at sprites (although I don't see many of them), but hardly at text.

If this behaviour is intended, why? And can't there be a simpler solution than to round all the time? I mean, a big advantage of the drawables working with floats results of the possibility, that one can move a drawable continuously, for example. By rounding all the time, integers could as well be used.

Sorry if this topic has already come up quite often, I've so far only found this thread.

SFML website / Minor documentation and tutorial remarks
« on: September 14, 2010, 11:28:07 pm »
Just a few things I've stumbled upon:

Quote from: "SFML 2 Documentation - [url=http://www.sfml-dev.org/documentation/2.0/classsf_1_1Mutex.htm
sf::Mutex[/url]"]When a thread is locked by a thread, any other thread trying to lock it will be blocked until the mutex is released by the thread that locked it.
I think it should be "mutex" instead of "thread".

Quote from: "SFML 2 Documentation - [url=http://www.sfml-dev.org/documentation/2.0/classsf_1_1Vector2.htm#58c32383b5291380db4b43a289f75988
sf::Vector2[/url] and sf::Vector3"]Default constructor.
It might be useful to specify that the default constructor creates a zero vector. Although this is assumable, it may be not obvious to SFML beginners.

Quote from: "SFML 2 Documentation - [url=http://www.sfml-dev.org/documentation/2.0/classsf_1_1Shape.htm
sf::Shape[/url]"]It is important to keep in mind that shapes must always be convex
As you, Laurent, pointed out some time ago, it needn't necessarily be convex. It's okay if every polygon point is directly connected to the center (the connecting line is completely inside the polygon). For example, regular stars can be represented using sf::Shape, although they are concave.

Quote from: "SFML 2 Documentation - [url=http://www.sfml-dev.org/documentation/2.0/classsf_1_1Font.htm#0fc12ebb5aa620ac9673f3739358e93f
sf::Font[/url]"]bool sf::Font::LoadFromMemory (const void *  data,  std::size_t  sizeInBytes)

Load the font from a file.
It should be rather "memory".

Quote from: "SFML 1.6 Tutorial - [url=http://www.sfml-dev.org/tutorials/1.6/network-packets.php
Network - Using and extending packets[/url]"]Like I just said earlier, primitive C++ types such as unsigned int, char, etc. have a size which is not fixed and may vary depending on the platform.
char is probably not the best example, since it is guaranteed that sizeof(char) == sizeof(unsigned char) == sizeof(signed char) == 1 for all platforms.

Quote from: "SFML 1.6 Tutorial - [url=http://www.sfml-dev.org/tutorials/1.6/network-selector.php
Network - Using a selector[/url]"]bool ReceiveWithTimeout(sf::SocketTCP Socket, sf::Packet& Packet, float Timeout = 0)
Is the copy by value intended?

Graphics / Meaningless code in Font.cpp
« on: July 18, 2010, 10:33:07 pm »
This concerns a recent SVN modification (in this thread). I stumpled upon
Code: [Select]
   if (codePoint == 100)
        codePoint = codePoint;
in line 156-157 of Font.cpp. I don't think this is intended, so I'm telling you. Just in case you wanted to achieve something different, but were overtired at the moment you wrote that. :D

Or did you just experiment and haven't removed it yet? ;)

Pages: 1 ... 3 4 [5] 6 7