SFML community forums

Help => Graphics => Topic started by: yingche on February 12, 2016, 11:31:58 am

Title: SFML Text is incomplete when shown on window
Post by: yingche on February 12, 2016, 11:31:58 am
I drew some text on window using Text class. The text color was black, and the background color of window was white. Then something strange occured: the text shown on window was incomplete! But if the text color is white, and the background color of window is black, evething is OK. I don't konw whether I have found a bug.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 12, 2016, 11:47:12 am
int main()
{
   RenderWindow window(VideoMode(640, 480), "1");
   Font font;
   font.loadFromFile(String("system.ttf"));
   Text text("aaabbbcccdddeeefffgggHHH", font, 22);
   text.setColor(Color::Black);
   text.setPosition(10.4, 20.3);
   window.clear(Color::White);
   window.draw(text);
   window.display();
   while (1){
      Event event;
      window.waitEvent(event);
      if (event.type == Event::Closed)break;
   }
   return 0;
}

This is the source code. I don't konw why I cannot add image here, maybe the browser doesn't support it.
Title: Re: SFML Text is incomplete when shown on window
Post by: Mr_Blame on February 12, 2016, 11:51:09 am
you do not updae your window graphicly at all -> this is bad. Why you have this bug - this is probably some drivers work. ;)
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 12, 2016, 01:28:25 pm
   window.clear(Color::White);
   window.draw(text);
   window.display();

Please, read this (http://www.sfml-dev.org/tutorials/2.3/) before moving on.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 12, 2016, 02:09:11 pm
I just write a simple program to show the problem. I know I should clear,draw and display every frame. I just want to know:
When I use black text and white background, the edge of every letter is strange. I can describe the phenomenon in this way. A letter is printed on a paper,and you cut the paper in order to remove the margin,but you cut a little bit more. As a result, the letter is incomplete. The text on the screen is like this. My English is not good,but I hope I have described the problem clearly.
I really think it is a bug. I think it may due to the transformation between float type and int type,but I'm not sure.
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 12, 2016, 02:13:28 pm
Show us the screenshot then.
Title: Re: SFML Text is incomplete when shown on window
Post by: Mr_Blame on February 12, 2016, 03:42:15 pm
I want to add more: first you do not call window.close() in an example code and also... Try another font - system.ttf is a bit glitchy i think... At least try to test your code with another for e.g. Arial. :)
Title: Re: SFML Text is incomplete when shown on window
Post by: Hapax on February 12, 2016, 08:28:44 pm
This thread should be in the Help section as this is not a general discussion about SFML.

Please post code inside [code=cpp] [/code] tags.
font.loadFromFile() can implicitly take a string literal as a parameter so there's no need to first convert to a string. i.e. font.loadFromFile("system.ttf");
You should be closing the window.
Try a different font and try other text positions.
Please post screenshots of both colours (one working and one not working) so people can know the result of your problem.

waitEvent() is blocking (http://www.sfml-dev.org/documentation/2.3/classsf_1_1Window.php#aaf02ab64fbc1d374eef3696df54137bc). It is intended to be used in multithreaded programs, where you have a separate thread dedicated to handling events.
This is not true. Waiting for events is for times when nothing has to happen unless an event has occurred (a lot of applications but probably not games). Polling events is for real-time updates regardless of if the user or OS is interacting with the program (such as games).
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 13, 2016, 01:11:56 pm
waitEvent() is blocking (http://www.sfml-dev.org/documentation/2.3/classsf_1_1Window.php#aaf02ab64fbc1d374eef3696df54137bc). It is intended to be used in multithreaded programs, where you have a separate thread dedicated to handling events.
This is not true. Waiting for events is for times when nothing has to happen unless an event has occurred (a lot of applications but probably not games). Polling events is for real-time updates regardless of if the user or OS is interacting with the program (such as games).
I stand corrected. I was using the (apparently simplified) description from the docs.
Title: Re: SFML Text is incomplete when shown on window
Post by: Hapax on February 13, 2016, 04:59:54 pm
I stand corrected. I was using the (apparently simplified) description from the docs.
I apologise as it may have sounded like I was saying that what you said was wrong and what I said is how it is.
I actually meant that it isn't only for what you suggested (multi-threading); it's also useful in a single-threaded application in the way I described  :)
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 13, 2016, 08:37:34 pm
Don't worry. I didn't take it personally. In fact, I was glad I learnt something new. Keep up the good work, bro :D
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 15, 2016, 09:57:29 am
I have tried a lot of times,but I still cannot add a screenshot here. The button "insert image" doesn't work! Help me!
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 15, 2016, 10:18:14 am
It does. It starts to upload it only after you send your post however. In case that still doesn't work, just upload it somewhere else and paste the link here.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 15, 2016, 10:27:02 am
http://pan.baidu.com/s/1qXb6jlq
I upload the screenshot to netdisk.
In the image,the right and bottom of every letter is strange. Have a look at the right of letter 'g','H','p', and the bottom of 'g','e'. The picture has been stretched. The fontsize is 20.
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 15, 2016, 10:41:40 am
The problem with national web services usually is, that the others don't understand a word. This is what I get
Quote
啊哦,你所访问的页面不存在了。
可能的原因:
1.在地址栏中输入了错误的地址。
2.你点击的某个链接已过期。
返回上一级页面>
回到网站首页>
Looks like a broken link. Please, upload it once again here for instance (http://prnt.sc/).

Edit
OK, looks like it just wasn't uploaded then. Now I see it.

Anyway, this doesn't look like an SFML problem.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 15, 2016, 11:27:17 am
In my opinion, the reason may due to a conversion between float type and int type. The fractional part lost, so the letters display incompletely. I think the error is not due to freetype library, but SFML itself.
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 15, 2016, 01:17:02 pm
You could upload the font you're using, so I can test it on my computer.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 15, 2016, 03:22:13 pm
http://pan.baidu.com/s/1nurR3pZ
I just casually select a font file from the folder "c:\windows\fonts". You can try other files, and most of them have this problem.
Thank you so much for helping me :D
Title: Re: SFML Text is incomplete when shown on window
Post by: ramaskrik on February 15, 2016, 06:55:44 pm
Seems just fine here.
Title: Re: SFML Text is incomplete when shown on window
Post by: Hapax on February 16, 2016, 01:33:21 am
What exactly was the error you were having with the text? You said the text was "incomplete". Your screenshot shows all of the text in both cases.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 16, 2016, 01:57:27 am
After all,the fractional part is less than one pixel. So if the font size is large, it looks nice. You can try smaller font size.
Title: Re: SFML Text is incomplete when shown on window
Post by: Hapax on February 16, 2016, 02:57:06 am
Are you referring to the fact that some of the text looks slightly "straight" on edges on one version and not on the other?

This is a perception thing.

Pixel-wise, it's exactly perfect.
I've inverted the image you gave us so that the black on white text is now white on black and vice versa, and the same effect appears on the one on white (the one that looked fine before).
I'll upload the image. It has your screenshot at the top, and the inverted version at the bottom.
Title: Re: SFML Text is incomplete when shown on window
Post by: yingche on February 16, 2016, 06:14:09 am
I'm sorry that what I said before was wrong. Both white backgroung and black background have this problem. And if the font size is set to 16,18,ect, the phenomenon is very clear.