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/api/Text.h | 6 ------ src/crepe/facade/SDLContext.cpp | 16 +++++++++++----- src/example/rendering_particle.cpp | 24 +++++++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index da40141..fb5c7e5 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -28,12 +28,6 @@ public: */ unsigned int font_size = 16; - //! Layer sorting level of the text - const int sorting_in_layer = 0; - - //! Order within the sorting text - const int order_in_layer = 0; - //! Label text color. Color text_color = Color::BLACK; }; 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, diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 5440fdd..0a2f946 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -7,8 +7,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -27,6 +27,7 @@ public: Color color(255, 255, 255, 255); + /* Asset img{"asset/texture/square.png"}; Sprite & test_sprite = game_object.add_component( @@ -49,6 +50,7 @@ public: .position_offset = {0, -1}, .world_space = false, }); + */ auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{5, 5}, Camera::Data{ @@ -56,21 +58,25 @@ public: .postion_offset = {1000, 1000}, }); - /* - game_object.add_component(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS", - Text::Data{.text_color = Color::RED}, "test TEST"); + game_object.add_component(vec2{1, 1}, vec2{0, -1}, "ComicSansMS", + Text::Data{ + .text_color = Color::RED, + }, + "test TEST"); - game_object.add_component(vec2{1, 1}, vec2{0, 0.5}, "ComicSansMS", - Text::Data{.text_color = Color::BLACK}, "TEST test"); - */ + game_object.add_component(vec2{1, 1}, vec2{0, 1}, "Ariel", + Text::Data{ + .text_color = Color::BLACK, + }, + "TEST test").world_space = true; } string get_name() const { return "TestScene"; }; }; int main(int argc, char * argv[]) { - LoopManager engine; + Engine engine; engine.add_scene(); - engine.start(); + engine.main(); return 0; } -- cgit v1.2.3