round final text render coordinates to int.
This didn't fix the main bug I'm struggling with, but someone in SFML forums reported that float coordinates could cause graphical bugs in text rendering.
This commit is contained in:
@@ -152,7 +152,10 @@ static void draw_stored_scale_aware_text(sf::RenderTexture& texture, sf::RenderT
|
||||
sf::Vector2f position = str_to_draw.getPosition();
|
||||
position = position + sf::Vector2f {0.0f+targ_rect.left, 0.0f+targ_rect.top};
|
||||
position *= (float)get_ui_scale();
|
||||
str_to_draw.setPosition(position + scaled_top_left);
|
||||
position += scaled_top_left;
|
||||
// Rounding to whole-number positions *might* avoid unpredictable graphics bugs:
|
||||
round_vec(position);
|
||||
str_to_draw.setPosition(position);
|
||||
dest_window.draw(str_to_draw);
|
||||
if(!text.clip_rect.empty())
|
||||
undo_clip(dest_window);
|
||||
|
@@ -182,7 +182,10 @@ void draw_scale_aware_text(sf::RenderTarget& dest_window, sf::Text str_to_draw)
|
||||
dest_window.setView(dest_window.getDefaultView());
|
||||
|
||||
sf::Vector2f text_position = str_to_draw.getPosition() * (float)get_ui_scale();
|
||||
str_to_draw.setPosition(text_position + scaled_view_top_left(dest_window, scaled_view));
|
||||
text_position += scaled_view_top_left(dest_window, scaled_view);
|
||||
// Rounding to whole-number positions *might* avoid unpredictable graphics bugs:
|
||||
round_vec(text_position);
|
||||
str_to_draw.setPosition(text_position);
|
||||
|
||||
// Draw the text immediately
|
||||
dest_window.draw(str_to_draw);
|
||||
|
@@ -65,5 +65,9 @@ void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,std::stri
|
||||
void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,std::string str,eTextMode mode,TextStyle style, break_info_t break_info,bool right_align = false);
|
||||
break_info_t calculate_line_wrapping(rectangle dest_rect, std::string str, TextStyle style);
|
||||
size_t string_length(std::string str, const TextStyle& style, short* height = nullptr);
|
||||
inline void round_vec(sf::Vector2f& vec) {
|
||||
vec.x = round(vec.x);
|
||||
vec.y = round(vec.y);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user