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.

Messages - Celtic Minstrel

Pages: 1 ... 4 5 [6]
Graphics / Re: Odd text artifacts
« on: June 21, 2012, 09:19:49 am »
Well, that's good to hear, in a way; at least I know it's not me. :P I didn't find it on the issue tracker when searching for "text" though.

Is there any workaround?

Graphics / Odd text artifacts
« on: June 21, 2012, 05:32:47 am »
I'm not sure whether this is something I'm doing wrong or a bug in the library, but I'm getting boxes around some of the letters when I render text. Example:

I'm not entirely sure what code to post, since I have no idea why this is happening. I created a small program that just draws text to the screen and then waits to be closed, but wasn't able to reproduce this.

If it's relevant, I'm on a Mac using clang and libc++, for which I had to compile SFML myself. I haven't checked yet whether this occurs on Windows as well (that would require a reboot and rewriting a few functions, so it's unlikely I'll check soon).

Here's the function I'm using to draw text (the "Left" in the name refers to alignment), and its subroutines:
Code: [Select]
FloatRect drawTextLeft(short left, short top, string str, int size, Color clr, int style) {
Text text = makeText(str, size, clr, style);
FloatRect bounds = text.getLocalBounds();
drawText(left, top, text);
adjustForWhitespace(str, &bounds.left, &bounds.width, text.getFont(), size, style);
return bounds;

void adjustForWhitespace(string str, float* left, float* width, const Font& font, int size, int style) {
// Hack to force the text drawing functions to account for whitespace
// Only accounts for actual space, unfortunately; tabs not handled
int space = ({
Text withSpace("| |", font, size);
Text withoutSpace("||", font, size);
withSpace.getLocalBounds().width - withoutSpace.getLocalBounds().width;
size_t pre = str.find_first_not_of(' ');
if(pre == string::npos) pre = 0;
size_t post = str.size() - str.find_last_not_of(' ') - 1;
if(left) *left -= pre * space;
if(width) *width += (pre + post) * space;

Text makeText(string str, int size, Color clr, int style) {
Text text(str);
return text;

void drawText(int left, int top, Text& text) {
text.setPosition(left, top);

When I commented out the call to adjustForWhitespace, there were less artifacts, but there were still some — less boxes, and sometimes just fragments of boxes. Also, I notice that it tends to happen to certain letters. Maybe that's a hint towards the cause of this?

When clang & libc++ are set as default compiler & standard lib by Apple I'll see what should be done.

Unless you have good arguments against my decision, of course.  ;)
Nah, I more or less expected an answer like this. Would it be worth mentioning somewhere in the Xcode and compiling tutorials, though?

Your questions are already answered, either on this forum or in the task tracker.
Even the C++ library one? I was searching for quite awhile for clues towards that issue and didn't find anything mentioning anything to point me towards the actual solution.

One other thing... a lot of the classes have many attributes, but only one or two of them can be specified in the constructor, so it would be nice to make the setXYZ functions return (*this) so that you can chain calls.
What's the problem with
Text text("my string"); text.setSize(16); text.setColor(blue); text.setStyle(Text::Bold);

Allowing chained calls is a very specific feature, and to me "many attributes" is not a valid arguments for adding it to a class.

I suppose it's mostly just personal preference really. I generally prefer to initialize my objects all at once. But of course the existing method works fine, and is what I'm doing anyway.

Not entirely sure if this is the right area of the forum to post this in...

So, I discovered the existence of this a day or two ago as a substitute for SDL, when I was looking into ways of improving rendering speed (I was rendering a lot of tiles per frame and the time for rendering was quite a bit longer than the time I had allotted for a frame; I did try optimizing my rendering within SDL first, and then tried OpenGL with SDL, but the first didn't help much and I had strange problems with OpenGL). Converting the project from SDL to SFML was quite an undertaking, and was not entirely straightforward, but it did at least improve the rendering speed even though my drawing is still pretty inefficient (I'm currently creating and immediately discarding around 500 or so Sprites per frame in the "blit" function I used to make the transition easier; I might look into using a VertexArray later for the tiles that don't change often).

However, I noticed a couple of missing features in the library (none of which are absolutely essential for me, fortunately), and I also had some problems linking with it. (I'm using the SFML 2.0 latest development snapshot from the downloads page.)

A new project with the Xcode templates worked fine, but my existing project could not locate a number of SFML symbols. I compared my project settings with the template settings, and eventually figured out that the key was in the standard C++ library; the templates linked against GCC's C++ library, whereas I was linking against LLVM's C++ library for the C++11 support. Once I had figured this out it wasn't too hard to rebuild SFML with the other library (by setting the CMAKE_CXX_FLAGS variable to -stdlib=libc++ when building), but I was wondering if this might become an option in the prebuilt libraries anytime soon?

Some of the keys I was handling with SDL are not supported in SFML. These are the enter key on the numeric keypad, and the clear key in the same area (which would be num lock on a Windows keyboard). I noticed the numpad equals and period keys are also missing, as well as caps lock and one or two others (older Apple keyboards have a Help key, for example). Also, while I don't really need this, you only support function keys up to 15; I have 19 function keys (I use an Apple flat extended keyboard, with an Fn key in place of Help/Insert). I only really care about Enter and Clear/NumLock, though. And, uh, this is just an aesthetic thing, but calling Backspace "Back" threw me off for a few moments.

While I don't especially need it at this point, it would be nice to add a Strikethrough style to the Text class. There's already an Underline, and strikethrough is almost the same as underline for rendering (just a line in a different place). And speaking of the Text class, it seems to strip leading and trailing whitespace from the input string, which led to a whole lot of issues with my formatted text rendering (with embedded images, even) until I wrote a workaround to account for it. I don't think it should strip whitespace like this.

One other thing... a lot of the classes have many attributes, but only one or two of them can be specified in the constructor, so it would be nice to make the setXYZ functions return (*this) so that you can chain calls. For example:
Code: [Select]
Text text = Text("my string").setSize(16).setColor(blue).setStyle(Text::Bold);

Pages: 1 ... 4 5 [6]