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

Author Topic: SFML Text is incomplete when shown on window  (Read 5931 times)

0 Members and 1 Guest are viewing this topic.

yingche

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
SFML Text is incomplete when shown on window
« 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.

yingche

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: SFML Text is incomplete when shown on window
« Reply #1 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.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: SFML Text is incomplete when shown on window
« Reply #2 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. ;)
« Last Edit: February 12, 2016, 11:56:25 am by Mr_Blame »

ramaskrik

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: SFML Text is incomplete when shown on window
« Reply #3 on: February 12, 2016, 01:28:25 pm »
  • You must draw stuff to the window every frame, which means these must be in the loop:
   window.clear(Color::White);
   window.draw(text);
   window.display();
  • waitEvent() is blocking. It is intended to be used in multithreaded programs, where you have a separate thread dedicated to handling events. For single-threaded programs use pollEvent() instead.

Please, read this before moving on.

yingche

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: SFML Text is incomplete when shown on window
« Reply #4 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.

ramaskrik

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: SFML Text is incomplete when shown on window
« Reply #5 on: February 12, 2016, 02:13:28 pm »
Show us the screenshot then.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: SFML Text is incomplete when shown on window
« Reply #6 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. :)

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML Text is incomplete when shown on window
« Reply #7 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. 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).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ramaskrik

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: SFML Text is incomplete when shown on window
« Reply #8 on: February 13, 2016, 01:11:56 pm »
waitEvent() is blocking. 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML Text is incomplete when shown on window
« Reply #9 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  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ramaskrik

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: SFML Text is incomplete when shown on window
« Reply #10 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

yingche

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: SFML Text is incomplete when shown on window
« Reply #11 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!

ramaskrik

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: SFML Text is incomplete when shown on window
« Reply #12 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.

yingche

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • Email
Re: SFML Text is incomplete when shown on window
« Reply #13 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.
« Last Edit: February 15, 2016, 10:34:32 am by yingche »

ramaskrik

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: SFML Text is incomplete when shown on window
« Reply #14 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.

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

Anyway, this doesn't look like an SFML problem.
« Last Edit: February 15, 2016, 10:48:13 am by ramaskrik »