From e5b57f6a0aadf4f5ca597e4ffa3e557eec87b54b Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 20 Dec 2024 15:26:51 +0100 Subject: add world space to text rendering and removedlayers on text --- src/crepe/facade/SDLContext.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 64c1fe2..9c45089 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -68,7 +68,7 @@ SDLContext::SDLContext(Mediator & mediator) { throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError())); } - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); mediator.sdl_context = *this; } @@ -232,10 +232,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.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, -- cgit v1.2.3 From 631975d4a03642271f80baeb4494dd01bda9c76e Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 20 Dec 2024 15:32:19 +0100 Subject: moved sdl hint to draw sprites and added another to text with 0 instead of 2 beacause otherwise its blurry --- src/crepe/facade/SDLContext.cpp | 3 ++- src/example/rendering_particle.cpp | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 9c45089..672d55a 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -68,7 +68,6 @@ SDLContext::SDLContext(Mediator & mediator) { throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError())); } - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); mediator.sdl_context = *this; } @@ -173,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) @@ -203,6 +203,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; diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index c8db499..5eae00d 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -27,7 +27,6 @@ public: Color color(255, 255, 255, 255); - /* Asset img{"asset/texture/square.png"}; Sprite & test_sprite = game_object.add_component( @@ -50,7 +49,6 @@ public: .position_offset = {0, -1}, .world_space = false, }); - */ auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{5, 5}, Camera::Data{ -- cgit v1.2.3 From 0ba3392d8d5ef1f69bda831c8e2be2efa505b632 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 20 Dec 2024 15:32:38 +0100 Subject: make format --- src/crepe/facade/SDLContext.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 672d55a..8e2e8a2 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -68,7 +68,6 @@ SDLContext::SDLContext(Mediator & mediator) { throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError())); } - mediator.sdl_context = *this; } -- cgit v1.2.3 From 296c80edd6727d6808ed0c98c001a8b456f1c037 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Sat, 21 Dec 2024 10:27:16 +0100 Subject: implemented feedback --- src/crepe/api/Button.h | 6 +++--- src/crepe/api/Text.h | 12 ++---------- src/crepe/api/UIObject.h | 2 -- src/crepe/facade/SDLContext.cpp | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src/crepe/facade/SDLContext.cpp') diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index d42527e..25709a4 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -1,8 +1,5 @@ #pragma once -#include - -#include "Event.h" #include "UIObject.h" namespace crepe { @@ -43,6 +40,9 @@ private: friend class InputSystem; //! Indicates whether the mouse is currently hovering over the button bool hover = false; + + //! variable indicating if transform is relative to camera(false) or world(true) + bool world_space = false; }; } // namespace crepe diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index fb5c7e5..9d8573f 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -17,16 +17,8 @@ class Text : public UIObject { public: //! Text data that does not have to be set in the constructor struct Data { - /** - * \brief fontsize for text rendering - * - * \note this is not the actual font size that is loaded in. - * - * Since SDL_TTF requires the font size when loading in the font it is not possible to switch the font size. - * The default font size that is loaded is set in the Config. - * Instead this value is used to upscale the font texture which can cause blurring or distorted text when upscaling or downscaling too much. - */ - unsigned int font_size = 16; + //! variable indicating if transform is relative to camera(false) or world(true) + bool world_space = false; //! Label text color. Color text_color = Color::BLACK; diff --git a/src/crepe/api/UIObject.h b/src/crepe/api/UIObject.h index f1318ab..f7f4fba 100644 --- a/src/crepe/api/UIObject.h +++ b/src/crepe/api/UIObject.h @@ -20,8 +20,6 @@ public: vec2 dimensions; //! Position offset relative to this GameObjects Transform vec2 offset; - //! variable indicating if transform is relative to camera(false) or world(true) - bool world_space = false; }; } // namespace crepe diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 8e2e8a2..17dcd04 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -233,7 +233,7 @@ void SDLContext::draw_text(const RenderText & data) { vec2 size = text.dimensions * cam_aux_data.render_scale * data.transform.scale; vec2 screen_pos = absoluut_pos; - if (text.world_space) { + 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; -- cgit v1.2.3