aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.cpp
diff options
context:
space:
mode:
authorheavydemon21 <48092678+heavydemon21@users.noreply.github.com>2025-01-03 19:41:41 +0100
committerGitHub <noreply@github.com>2025-01-03 19:41:41 +0100
commitcf6ca6be5a9deac4de921f50d0aedf6a6156e0f4 (patch)
treee7b18df0361af1b081168569568d408cfd4b6538 /src/crepe/facade/SDLContext.cpp
parent61148c757a1f742ff09e40e5347e74e638c7371c (diff)
parent4526efe1b6dd63aaa177f8f35194989d3910d571 (diff)
Merge pull request #96 from lonkaars/niels/UI
rendering text world space fix
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r--src/crepe/facade/SDLContext.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 859f966..6c93fb2 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -69,8 +69,6 @@ SDLContext::SDLContext(Mediator & mediator) {
throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError()));
}
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
-
mediator.sdl_context = *this;
}
@@ -174,6 +172,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const {
}
void SDLContext::draw(const RenderContext & ctx) {
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
const Sprite::Data & data = ctx.sprite.data;
SDL_RendererFlip render_flip
= (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * data.flip.flip_x)
@@ -206,6 +205,7 @@ void SDLContext::draw(const RenderContext & ctx) {
}
void SDLContext::draw_text(const RenderText & data) {
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
const Text & text = data.text;
const Font & font = data.font;
@@ -235,9 +235,16 @@ void SDLContext::draw_text(const RenderText & data) {
= {tmp_font_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }};
vec2 size = text.dimensions * cam_aux_data.render_scale * data.transform.scale;
- vec2 screen_pos = (absoluut_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2
- ) * cam_aux_data.render_scale
- - size / 2 + cam_aux_data.bar_size;
+ vec2 screen_pos = absoluut_pos;
+ if (text.data.world_space) {
+ screen_pos = (screen_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2)
+ * cam_aux_data.render_scale
+ - size / 2 + cam_aux_data.bar_size;
+ } else {
+ screen_pos
+ = (screen_pos + (cam_aux_data.zoomed_viewport) / 2) * cam_aux_data.render_scale
+ - size / 2 + cam_aux_data.bar_size;
+ }
SDL_FRect dstrect {
.x = screen_pos.x,