Dragonfly Q&A

p_window->draw(text) in drawCh() not drawing to the window

0 like 0 dislike
As stated in the title I'm currently experiencing an issue where the text I'm specifying in drawCh() is not being drawn to the window.

This is troublesome as I follow the slides in the creation of the code and it matches up. Additionally, I've stepped through the code with the debugger and all values, such as ch, pixel_pos, and others, are correct. I've changed the color of the rectangle that's being drawn and that works perfectly fine, I simply can't get the character to draw. Any suggestions on where to look to solve this issue?
Dragonfly version 4.2
asked Sep 18, 2016 in Engine Development by Thomas-Lourenco
Hey, we had talked during office hours and it seemed as though we had the same problem. Did you ever end up getting this figured out?
I had redeclared my font when I was loading it in. Therefore, when I used the font variable from the class later it was undefined. I fixed it by removing sf::Font from the font variable in my constructor.

Hope this helps you as it did me!
Wow, okay. Thanks a lot. Can't believe I didn't notice that. Appreciate it a lot.

1 Answer

0 like 0 dislike
<p>Are the fonts being loaded properly (check the error code returned when loading the font in SFML)?

<p>Try running listing 4.68. That's a basic DF "hello, world" without any engine code.

<p>Assuming that works, make a simpler case like listing 4.83 that just draws a character on the screen.  Hopefully, by that point, you'll have some ideas on what is wrong.
answered Sep 18, 2016 by claypool
I've run listing 4.68 and it functions properly.

I'm using listing 4.83 to try and test my code currently. Since I changed to color of the rectangle I was able to verify that it is working correctly, but text still isn't being drawn on top of it.
So, it sounds like you can draw text - good.

Can you draw text without the rectangle (e.g., see if commenting out the rectangle in the Graphics Manager allows you to display text)?

Hopefully, this will help you narrow down the problem.
I've tried that as well, and unfortunately it does not change the situation. The character still is not drawn. I'll try some other methods to fix the problem though.
I had the same issue - try altering the setPosition method from pixel_pos.getX to some actual number. Turns out it was drawing my text off the screen!

EDIT: The example vector in the listing was too high. Keep pixel_pos the same and change the vector to something like (2,4).
What listing are you talking about?
Listing 4.83 suggests using a vector(10,5), which didn't appear on my screen. When I ran the same code with a vector (2,4), it worked fine.
Thank you for the suggestion, unfortunately that didn't work for me. The rectangle is drawn in both cases so the character is the only issue I have currently. I've also tried changing the code in drawCh() to ensure the character was drawn somewhere on screen.
That's odd since both (10,5) and (2,4) are on the screen in all normal cases. Remember that Dragonfly expects all (x,y) units to be spaces.  So, depending upon the conversion to pixels (i.e., if the charWidth() computation is suspect), this could take the pixel position off the visible window.
More information about Dragonfly can be found on the Dragonfly Home Page.