From 8abc6008880dd9ed0c16a68a126b49f0eb03caa2 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 16 Dec 2024 20:52:43 +0100 Subject: fonting --- src/crepe/system/RenderSystem.cpp | 19 +++++++++++++++++++ src/crepe/system/RenderSystem.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'src/crepe/system') diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index afd9548..7f00891 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -15,6 +15,8 @@ #include "../manager/ResourceManager.h" #include "RenderSystem.h" +#include "api/Text.h" +#include "facade/Font.h" #include "types.h" using namespace crepe; @@ -67,9 +69,26 @@ RefVector RenderSystem::sort(RefVector & objs) const { void RenderSystem::update() { this->clear_screen(); this->render(); + this->render_text(); this->present_screen(); } + +void RenderSystem::render_text(){ + SDLContext & ctx = this->mediator.sdl_context; + ComponentManager & mgr = this->mediator.component_manager; + ResourceManager & resource_manager = this->mediator.resource_manager; + + RefVector texts = mgr.get_components_by_type(); + + for (Text & text : texts) { + if (!text.active) continue; + resource_manager.get(text.font); + //ctx.draw_text(text, font); + } + +} + bool RenderSystem::render_particle(const Sprite & sprite, const double & scale) { ComponentManager & mgr = this->mediator.component_manager; diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index fc7b46e..ae55404 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -27,6 +27,8 @@ public: void update() override; private: + + void render_text(); //! Clears the screen in preparation for rendering. void clear_screen(); -- cgit v1.2.3 From c0dc5f5d785cb4d0b0f5c05174c36fab9eef9cfb Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 16 Dec 2024 20:58:02 +0100 Subject: rendersys --- src/crepe/system/RenderSystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 7f00891..f2ed97d 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -81,9 +81,9 @@ void RenderSystem::render_text(){ RefVector texts = mgr.get_components_by_type(); - for (Text & text : texts) { + for (const Text & text : texts) { if (!text.active) continue; - resource_manager.get(text.font); + const Font & res = resource_manager.get(text.font); //ctx.draw_text(text, font); } -- cgit v1.2.3 From 2f8d36a33854715828d412792663f355b9e393ae Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 09:08:06 +0100 Subject: idk --- src/crepe/api/Config.h | 2 +- src/crepe/facade/Font.cpp | 4 +++- src/crepe/facade/SDLContext.cpp | 23 +++++++++++++---------- src/crepe/system/RenderSystem.cpp | 2 +- src/example/rendering_particle.cpp | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index c20287d..b86faff 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -85,7 +85,7 @@ struct Config final { * This config option is the font size at which all fonts will be loaded initially. * */ - unsigned int size = 16; + unsigned int size = 32; } font; //! Audio system settings diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 83e8519..a9f1633 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -1,5 +1,6 @@ #include "../api/Config.h" #include "util/Log.h" +#include #include "Font.h" @@ -10,7 +11,8 @@ Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator) { dbg_trace(); Config & config = Config::get_instance(); - const std::string FONT_PATH = src.get_path(); + const std::string & FONT_PATH = src.get_path(); + cout << FONT_PATH.c_str() << endl; TTF_Font * font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); if (font == NULL) throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH)); diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 4e969b9..a06940d 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -34,9 +34,6 @@ using namespace std; SDLContext::SDLContext(Mediator & mediator) { dbg_trace(); - if (TTF_Init() == -1) { - throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError())); - } if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw runtime_error(format("SDLContext: SDL_Init error: {}", SDL_GetError())); } @@ -65,6 +62,10 @@ SDLContext::SDLContext(Mediator & mediator) { throw runtime_error("SDLContext: SDL_image could not initialize!"); } + if (TTF_Init() == -1) { + throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError())); + } + mediator.sdl_context = *this; } @@ -77,8 +78,8 @@ SDLContext::~SDLContext() { // TODO: how are we going to ensure that these are called from the same // thread that SDL_Init() was called on? This has caused problems for me // before. - IMG_Quit(); TTF_Quit(); + IMG_Quit(); SDL_Quit(); } @@ -297,13 +298,15 @@ void SDLContext::draw_text(const Text & text, const Font & font){ SDL_Texture * font_texture = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface); SDL_FreeSurface(font_surface); - SDL_FRect dstrect { - .x = text.offset.x, - .y = text.offset.y, - .w = text.dimensions.x, - .h = text.dimensions.y, + SDL_Rect dstrect { + .x = (int)text.offset.x, + .y = (int)text.offset.y, + .w = (int)text.dimensions.x, + .h = (int)text.dimensions.y, }; - SDL_RenderCopyExF(this->game_renderer.get(), font_texture, NULL, &dstrect , 0 , NULL, SDL_FLIP_NONE); + + SDL_RenderCopy(this->game_renderer.get(), font_texture, NULL, NULL); + SDL_RenderCopyExF(this->game_renderer.get(), font_texture, NULL, NULL, 0 , NULL, SDL_FLIP_NONE); SDL_DestroyTexture(font_texture); } diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index f2ed97d..9611a9e 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -84,7 +84,7 @@ void RenderSystem::render_text(){ for (const Text & text : texts) { if (!text.active) continue; const Font & res = resource_manager.get(text.font); - //ctx.draw_text(text, font); + ctx.draw_text(text, res); } } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 3857acc..21ed7fc 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -66,7 +66,7 @@ public: .bg_color = Color::WHITE, }); - game_object.add_component(vec2{200,200}, vec2{0,0}, "test test", "OpenSymbol", Text::Data{}); + game_object.add_component(vec2{200,200}, vec2{0,0}, "test test", "", Text::Data{}); } string get_name() const { return "TestScene"; }; -- cgit v1.2.3 From bcaee968761c1d2e85c20925b237480c87da9747 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 13:29:58 +0100 Subject: tmp fix --- src/crepe/facade/Font.cpp | 11 +++++++++++ src/crepe/facade/Font.h | 8 ++++++-- src/crepe/facade/FontFacade.cpp | 12 ++++++------ src/crepe/facade/SDLContext.cpp | 2 ++ src/crepe/system/RenderSystem.cpp | 5 +++-- src/example/rendering_particle.cpp | 7 ++++--- 6 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 8c16563..47d0e39 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -2,6 +2,7 @@ #include "../api/Config.h" #include "util/Log.h" #include +#include #include "Font.h" @@ -13,11 +14,21 @@ Font::Font(const Asset & src, Mediator & mediator) dbg_trace(); Config & config = Config::get_instance(); const std::string FONT_PATH = src.get_path(); + + this->path = FONT_PATH; + + cout << this->path << endl; + /* TTF_Font * loaded_font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); if (loaded_font == NULL) { throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH)); } this->font = {loaded_font, [](TTF_Font * font) { TTF_CloseFont(font); }}; + */ } TTF_Font * Font::get_font() const { return this->font.get(); } + +const string & Font::get_path() const noexcept{ + return this->path; +} diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h index 91c59c0..0b1768b 100644 --- a/src/crepe/facade/Font.h +++ b/src/crepe/facade/Font.h @@ -1,10 +1,11 @@ #pragma once #include +#include #include +#include #include "../Resource.h" -#include "../api/Config.h" namespace crepe { @@ -24,7 +25,6 @@ public: * \param mediator The Mediator object used for managing the SDL context or related systems. */ Font(const Asset & src, Mediator & mediator); - ~Font(); /** * \brief Gets the underlying TTF_Font resource. @@ -36,9 +36,13 @@ public: */ TTF_Font * get_font() const; + const std::string & get_path() const noexcept; + private: //! The SDL_ttf font object with custom deleter. std::unique_ptr> font; + + std::string path; }; } // namespace crepe diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp index aa9d00c..a0464e0 100644 --- a/src/crepe/facade/FontFacade.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "FontFacade.h" @@ -12,13 +13,13 @@ Asset FontFacade::get_font_asset(const string font_family) { } // Create a pattern to search for the font family FcPattern * pattern = FcNameParse(reinterpret_cast(font_family.c_str())); - if (pattern == NULL) { + if (!pattern) { throw runtime_error("Failed to create font pattern."); } // Default configuration FcConfig * config = FcConfigGetCurrent(); - if (config == NULL) { + if (!config) { FcPatternDestroy(pattern); throw runtime_error("Failed to get current Fontconfig configuration."); } @@ -28,15 +29,14 @@ Asset FontFacade::get_font_asset(const string font_family) { FcPattern * matched_pattern = FcFontMatch(config, pattern, &result); FcPatternDestroy(pattern); - if (matched_pattern == NULL) { - FcPatternDestroy(matched_pattern); + if (!matched_pattern) { throw runtime_error("No matching font found."); } // Extract the file path FcChar8 * file_path = nullptr; if (FcPatternGetString(matched_pattern, FC_FILE, 0, &file_path) != FcResultMatch - || file_path == NULL) { + || !file_path) { FcPatternDestroy(matched_pattern); throw runtime_error("Failed to get font file path."); } @@ -44,6 +44,6 @@ Asset FontFacade::get_font_asset(const string font_family) { // Convert the file path to a string string font_file_path = reinterpret_cast(file_path); FcPatternDestroy(matched_pattern); - FcFini(); + cout << font_file_path << endl; return Asset(font_file_path); } diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index a06940d..1befbe5 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -294,7 +294,9 @@ void SDLContext::draw_text(const Text & text, const Font & font){ .b = text.data.text_color.b, .a = text.data.text_color.a, }; + TTF_Font * ttf_font = TTF_OpenFont(font.get_path().c_str(), Config::get_instance().font.size); SDL_Surface * font_surface = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color); + TTF_CloseFont(ttf_font); SDL_Texture * font_texture = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface); SDL_FreeSurface(font_surface); diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 9611a9e..4a70843 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -13,15 +13,16 @@ #include "../facade/Texture.h" #include "../manager/ComponentManager.h" #include "../manager/ResourceManager.h" - -#include "RenderSystem.h" #include "api/Text.h" #include "facade/Font.h" + +#include "RenderSystem.h" #include "types.h" using namespace crepe; using namespace std; + void RenderSystem::clear_screen() { SDLContext & ctx = this->mediator.sdl_context; ctx.clear_screen(); diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 21ed7fc..b261f52 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -1,3 +1,5 @@ + + #include "api/Asset.h" #include "api/Text.h" #include @@ -14,7 +16,6 @@ #include #include #include -#include using namespace crepe; using namespace std; @@ -65,8 +66,8 @@ public: Camera::Data{ .bg_color = Color::WHITE, }); - - game_object.add_component(vec2{200,200}, vec2{0,0}, "test test", "", Text::Data{}); + game_object.add_component(vec2{200, 200}, vec2{0, 0}, "test test", "Ariel.ttf", + Text::Data{}); } string get_name() const { return "TestScene"; }; -- cgit v1.2.3 From 0c02511f6a64766174cb0db3beb4cc159d3efdf7 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 13:36:17 +0100 Subject: merging wouter --- src/crepe/facade/Font.cpp | 9 --------- src/crepe/facade/Font.h | 3 --- src/crepe/facade/SDLContext.cpp | 2 -- src/crepe/system/RenderSystem.cpp | 2 +- 4 files changed, 1 insertion(+), 15 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 51e9690..9c1a800 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -2,8 +2,6 @@ #include "../api/Asset.h" #include "../api/Config.h" -#include "util/Log.h" -#include #include #include "Font.h" @@ -16,10 +14,6 @@ Font::Font(const Asset & src, Mediator & mediator) Config & config = Config::get_instance(); const std::string FONT_PATH = src.get_path(); - this->path = FONT_PATH; - - cout << this->path << endl; - /* TTF_Font * loaded_font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); if (loaded_font == NULL) { throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH)); @@ -29,6 +23,3 @@ Font::Font(const Asset & src, Mediator & mediator) TTF_Font * Font::get_font() const { return this->font.get(); } -const string & Font::get_path() const noexcept{ - return this->path; -} diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h index 3eff3c6..b08366d 100644 --- a/src/crepe/facade/Font.h +++ b/src/crepe/facade/Font.h @@ -3,7 +3,6 @@ #include #include #include -#include #include "../Resource.h" @@ -35,8 +34,6 @@ public: */ TTF_Font * get_font() const; - const std::string & get_path() const noexcept; - private: //! The SDL_ttf font object with custom deleter. std::unique_ptr> font = nullptr; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 7bd9dbc..c19f0aa 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -294,9 +294,7 @@ void SDLContext::draw_text(const Text & text, const Font & font){ .b = text.data.text_color.b, .a = text.data.text_color.a, }; - TTF_Font * ttf_font = TTF_OpenFont(font.get_path().c_str(), Config::get_instance().font.size); SDL_Surface * font_surface = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color); - TTF_CloseFont(ttf_font); SDL_Texture * font_texture = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface); SDL_FreeSurface(font_surface); diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 7d6a31b..578a4c0 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -87,7 +87,7 @@ void RenderSystem::render_text(){ for (const Text & text : texts) { if (!text.active) continue; - const Font & res = resource_manager.get(text.font); + const Font & res = resource_manager.get(text.font.value()); ctx.draw_text(text, res); } -- cgit v1.2.3 From 8d3fd95ad8564740bb169f4e08bc085a232a4d83 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 13:58:52 +0100 Subject: workig rending text --- src/crepe/facade/SDLContext.cpp | 36 +++++++++++++++++++++++++----------- src/crepe/facade/SDLContext.h | 8 +++++++- src/crepe/system/RenderSystem.cpp | 16 ++++++++++------ src/example/rendering_particle.cpp | 6 +++--- 4 files changed, 45 insertions(+), 21 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index a5ccdae..27f2cb3 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -22,6 +22,7 @@ #include "../api/Sprite.h" #include "../util/Log.h" #include "api/Text.h" +#include "api/Transform.h" #include "facade/Font.h" #include "manager/Mediator.h" @@ -286,27 +287,40 @@ void SDLContext::draw(const RenderContext & ctx) { angle, NULL, render_flip); } +void SDLContext::draw_text(const RenderText & data) { -void SDLContext::draw_text(const Text & text, const Font & font){ - SDL_Color color { + const Text & text = data.text; + const Font & font = data.font; + const Transform & transform = data.transform; + + SDL_Color color{ .r = text.data.text_color.r, .g = text.data.text_color.g, .b = text.data.text_color.b, .a = text.data.text_color.a, }; - SDL_Surface * font_surface = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color); - SDL_Texture * font_texture = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface); + SDL_Surface * font_surface + = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color); + SDL_Texture * font_texture + = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface); SDL_FreeSurface(font_surface); - SDL_Rect dstrect { - .x = (int)text.offset.x, - .y = (int)text.offset.y, - .w = (int)text.dimensions.x, - .h = (int)text.dimensions.y, + vec2 size = text.dimensions * cam_aux_data.render_scale; + vec2 screen_pos = (transform.position + text.offset - cam_aux_data.cam_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, + .y = screen_pos.y, + .w = size.x, + .h = size.y, }; - SDL_RenderCopy(this->game_renderer.get(), font_texture, NULL, NULL); - SDL_RenderCopyExF(this->game_renderer.get(), font_texture, NULL, NULL, 0 , NULL, SDL_FLIP_NONE); + SDL_RenderCopyExF(this->game_renderer.get(), font_texture, NULL, &dstrect, 0, NULL, + SDL_FLIP_NONE); SDL_DestroyTexture(font_texture); } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 33a4ff9..066a881 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -71,6 +71,12 @@ public: const double & scale; }; + struct RenderText { + const Text & text; + const Font & font; + const Transform & transform; + }; + public: //! EventType enum for passing eventType enum EventType { @@ -187,7 +193,7 @@ public: */ void draw(const RenderContext & ctx); - void draw_text(const Text & text, const Font & font); + void draw_text(const RenderText & data); //! Clears the screen, preparing for a new frame. void clear_screen(); diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 872ba29..2641435 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -76,20 +76,24 @@ void RenderSystem::update() { this->present_screen(); } - -void RenderSystem::render_text(){ +void RenderSystem::render_text() { SDLContext & ctx = this->mediator.sdl_context; ComponentManager & mgr = this->mediator.component_manager; ResourceManager & resource_manager = this->mediator.resource_manager; RefVector texts = mgr.get_components_by_type(); - for (const Text & text : texts) { + for (const Text & text : texts) { if (!text.active) continue; - const Font & res = resource_manager.get(text.font.value()); - ctx.draw_text(text, res); + const Font & font = resource_manager.get(text.font.value()); + const auto & transform + = mgr.get_components_by_id(text.game_object_id).front().get(); + ctx.draw_text(SDLContext::RenderText{ + .text = text, + .font = font, + .transform = transform, + }); } - } bool RenderSystem::render_particle(const Sprite & sprite, const double & scale) { diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index b261f52..aa71dd0 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -62,12 +62,12 @@ public: .position_offset = {0, 0}, }); - auto & cam = game_object.add_component(ivec2{400, 400}, vec2{400, 400}, + auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{400, 400}, Camera::Data{ .bg_color = Color::WHITE, }); - game_object.add_component(vec2{200, 200}, vec2{0, 0}, "test test", "Ariel.ttf", - Text::Data{}); + game_object.add_component(vec2{400, 400}, vec2{0, 0}, "ComicSansMS", + Text::Data{.text_color = Color::RED}, "TEST test"); } string get_name() const { return "TestScene"; }; -- cgit v1.2.3 From dff8c63a5af46fd3b0115e10efe9f0b67e9111b8 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 13:59:19 +0100 Subject: make format --- src/crepe/facade/Font.cpp | 1 - src/crepe/facade/SDLContext.cpp | 1 - src/crepe/system/RenderSystem.h | 1 - 3 files changed, 3 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 81a9e7a..4694f7c 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -21,4 +21,3 @@ Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator) { } TTF_Font * Font::get_font() const { return this->font.get(); } - diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 27f2cb3..41c6d21 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -311,7 +311,6 @@ void SDLContext::draw_text(const RenderText & data) { * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; - SDL_FRect dstrect{ .x = screen_pos.x, .y = screen_pos.y, diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 3476765..3aa846e 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -27,7 +27,6 @@ public: void update() override; private: - void render_text(); //! Clears the screen in preparation for rendering. void clear_screen(); -- cgit v1.2.3 From 68be6b67f79413cb4af0ca15262ca1547a7d0d41 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 14:16:47 +0100 Subject: finalized text rendering --- src/crepe/facade/SDLContext.cpp | 22 ++++++++++++++++------ src/crepe/facade/SDLContext.h | 5 +++++ src/crepe/system/RenderSystem.cpp | 26 +++++--------------------- src/crepe/system/RenderSystem.h | 8 ++------ 4 files changed, 28 insertions(+), 33 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 41c6d21..c3c1b59 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -292,6 +292,8 @@ void SDLContext::draw_text(const RenderText & data) { const Text & text = data.text; const Font & font = data.font; const Transform & transform = data.transform; + std::unique_ptr> font_surface; + std::unique_ptr> font_texture; SDL_Color color{ .r = text.data.text_color.r, @@ -299,11 +301,20 @@ void SDLContext::draw_text(const RenderText & data) { .b = text.data.text_color.b, .a = text.data.text_color.a, }; - SDL_Surface * font_surface + SDL_Surface * tmp_font_surface = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color); - SDL_Texture * font_texture - = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface); - SDL_FreeSurface(font_surface); + if (!tmp_font_surface) { + throw runtime_error(format("draw_text: font surface error: {}", SDL_GetError())); + } + font_surface = {tmp_font_surface, [](SDL_Surface * surface) { SDL_FreeSurface(surface); }}; + + SDL_Texture * tmp_font_texture + = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface.get()); + if (!tmp_font_texture) { + throw runtime_error(format("draw_text: font texture error: {}", SDL_GetError())); + } + font_texture + = {tmp_font_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; vec2 size = text.dimensions * cam_aux_data.render_scale; vec2 screen_pos = (transform.position + text.offset - cam_aux_data.cam_pos @@ -318,9 +329,8 @@ void SDLContext::draw_text(const RenderText & data) { .h = size.y, }; - SDL_RenderCopyExF(this->game_renderer.get(), font_texture, NULL, &dstrect, 0, NULL, + SDL_RenderCopyExF(this->game_renderer.get(), font_texture.get(), NULL, &dstrect, 0, NULL, SDL_FLIP_NONE); - SDL_DestroyTexture(font_texture); } void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) { diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 066a881..aeace07 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -193,6 +193,11 @@ public: */ void draw(const RenderContext & ctx); + /** + * \brief draws a text to the screen + * + * \param data Reference to the rendering data needed to draw + */ void draw_text(const RenderText & data); //! Clears the screen, preparing for a new frame. diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 2641435..42e4236 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -83,8 +83,11 @@ void RenderSystem::render_text() { RefVector texts = mgr.get_components_by_type(); - for (const Text & text : texts) { + for (Text & text : texts) { if (!text.active) continue; + if (!text.font.has_value()) text.font = ctx.get_font_from_name(text.font_family); + if (!text.font.has_value()) continue; + const Font & font = resource_manager.get(text.font.value()); const auto & transform = mgr.get_components_by_id(text.game_object_id).front().get(); @@ -149,11 +152,7 @@ void RenderSystem::render() { ResourceManager & resource_manager = this->mediator.resource_manager; RefVector sorted_sprites = this->sort(sprites); RefVector text_components = mgr.get_components_by_type(); - for (Text & text : text_components) { - const Transform & transform - = mgr.get_components_by_id(text.game_object_id).front().get(); - this->render_text(text, transform); - } + for (const Sprite & sprite : sorted_sprites) { if (!sprite.active) continue; const Transform & transform @@ -166,18 +165,3 @@ void RenderSystem::render() { this->render_normal(sprite, transform); } } -void RenderSystem::render_text(Text & text, const Transform & tm) { - SDLContext & ctx = this->mediator.sdl_context; - - if (!text.font.has_value()) { - text.font = ctx.get_font_from_name(text.font_family); - } - - ResourceManager & resource_manager = this->mediator.resource_manager; - - if (!text.font.has_value()) { - return; - } - const Asset & font_asset = text.font.value(); - const Font & res = resource_manager.get(font_asset); -} diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 3aa846e..5fe24d7 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -27,7 +27,6 @@ public: void update() override; private: - void render_text(); //! Clears the screen in preparation for rendering. void clear_screen(); @@ -39,7 +38,7 @@ private: //! Renders the whole screen void render(); - + /** * \brief Renders all the particles on the screen from a given sprite. * @@ -53,11 +52,8 @@ private: bool render_particle(const Sprite & sprite, const double & scale); /** * \brief Renders all Text components - * - * \param text The text component to be rendered. - * \param tm the Transform component that holds the position,rotation and scale */ - void render_text(Text & text, const Transform & tm); + void render_text(); /** * \brief renders a sprite with a Transform component on the screen * -- cgit v1.2.3 From daff506e3b941a8bca8f6e785944fa5071a7130c Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 14:19:41 +0100 Subject: adjusted comments --- src/crepe/system/RenderSystem.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 5fe24d7..d5385eb 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -36,9 +36,13 @@ private: //! Updates the active camera used for rendering. void update_camera(); - //! Renders the whole screen + //! Renders all the sprites and particles void render(); - + + //! Renders all Text components + void render_text(); + +private: /** * \brief Renders all the particles on the screen from a given sprite. * @@ -50,10 +54,6 @@ private: * \return true if particles have been rendered */ bool render_particle(const Sprite & sprite, const double & scale); - /** - * \brief Renders all Text components - */ - void render_text(); /** * \brief renders a sprite with a Transform component on the screen * -- cgit v1.2.3 From 23eef97ed3fc57fdd619769a74d0abfa7f657714 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 15:58:03 +0100 Subject: merged master --- src/crepe/api/Config.h | 4 ---- src/crepe/system/RenderSystem.cpp | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 074c113..6b9e3ca 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -46,10 +46,6 @@ struct Config final { std::string location = "save.crepe.db"; } savemgr; - struct { - unsigned int size = 16; - } font; - //! physics-related settings struct { /** diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 684d798..4082591 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -85,7 +85,8 @@ void RenderSystem::render_text() { for (Text & text : texts) { if (!text.active) continue; - if (!text.font.has_value()) text.font = ctx.get_font_from_name(text.font_family); + if (!text.font.has_value()) + text.font.emplace(ctx.get_font_from_name(text.font_family)); if (!text.font.has_value()) continue; const Font & font = resource_manager.get(text.font.value()); -- cgit v1.2.3 From 36f941aa1cdea5faeec20a0dc793e0538ccd6d15 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 20:47:14 +0100 Subject: implemented feedback --- src/crepe/api/Text.cpp | 3 --- src/crepe/api/Text.h | 2 -- src/crepe/facade/Font.cpp | 2 -- src/crepe/facade/Font.h | 2 +- src/crepe/facade/SDLContext.cpp | 4 ++-- src/crepe/system/RenderSystem.cpp | 1 - 6 files changed, 3 insertions(+), 11 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp index 9d57abd..4a94180 100644 --- a/src/crepe/api/Text.cpp +++ b/src/crepe/api/Text.cpp @@ -1,6 +1,3 @@ -#include "../facade/FontFacade.h" -#include "util/Log.h" - #include "Text.h" using namespace crepe; diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index c30dc80..da40141 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -3,8 +3,6 @@ #include #include -#include "../Component.h" - #include "Asset.h" #include "Color.h" #include "UIObject.h" diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 0c670c1..771002f 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -2,7 +2,6 @@ #include "../api/Asset.h" #include "../api/Config.h" -#include #include "Font.h" @@ -12,7 +11,6 @@ using namespace crepe; Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator) { const Config & config = Config::get_instance(); const std::string FONT_PATH = src.get_path(); - TTF_Font * loaded_font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); if (loaded_font == NULL) { throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH)); diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h index b08366d..b208d96 100644 --- a/src/crepe/facade/Font.h +++ b/src/crepe/facade/Font.h @@ -1,10 +1,10 @@ #pragma once #include -#include #include #include "../Resource.h" +#include "../api/Config.h" namespace crepe { diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index ea3b71c..9a122f5 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -208,14 +208,14 @@ void SDLContext::draw_text(const RenderText & data) { }; SDL_Surface * tmp_font_surface = TTF_RenderText_Solid(font.get_font(), text.text.c_str(), color); - if (!tmp_font_surface) { + if (tmp_font_surface == NULL) { throw runtime_error(format("draw_text: font surface error: {}", SDL_GetError())); } font_surface = {tmp_font_surface, [](SDL_Surface * surface) { SDL_FreeSurface(surface); }}; SDL_Texture * tmp_font_texture = SDL_CreateTextureFromSurface(this->game_renderer.get(), font_surface.get()); - if (!tmp_font_texture) { + if (tmp_font_texture == NULL) { throw runtime_error(format("draw_text: font texture error: {}", SDL_GetError())); } font_texture diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 4082591..bf2bfd3 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -87,7 +87,6 @@ void RenderSystem::render_text() { if (!text.active) continue; if (!text.font.has_value()) text.font.emplace(ctx.get_font_from_name(text.font_family)); - if (!text.font.has_value()) continue; const Font & font = resource_manager.get(text.font.value()); const auto & transform -- cgit v1.2.3 From d0286486b5fddcfb32dcd1f3010aef5368ee678e Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 18 Dec 2024 19:17:38 +0100 Subject: rendering met absoluut position util functie, particle ben ik nog jaro aan het overleggen dus er die werkt niet goed --- src/crepe/facade/SDLContext.cpp | 14 +++++++------- src/crepe/system/RenderSystem.cpp | 12 ++++++------ src/crepe/system/RenderSystem.h | 2 +- src/crepe/util/AbsoluutPosition.cpp | 20 ++++++++++++++++++++ src/crepe/util/AbsoluutPosition.h | 14 ++++++++++++++ src/crepe/util/CMakeLists.txt | 2 ++ src/example/rendering_particle.cpp | 27 ++++++++++++++++++++------- 7 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 src/crepe/util/AbsoluutPosition.cpp create mode 100644 src/crepe/util/AbsoluutPosition.h (limited to 'src/crepe/system') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index f350250..d352adc 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -28,6 +28,7 @@ #include "SDLContext.h" #include "Texture.h" #include "types.h" +#include "util/AbsoluutPosition.h" using namespace crepe; using namespace std; @@ -148,8 +149,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { } size *= cam_aux_data.render_scale * ctx.img_scale * data.scale_offset; - vec2 screen_pos = (ctx.pos + data.position_offset - cam_aux_data.cam_pos - + (cam_aux_data.zoomed_viewport) / 2) + vec2 screen_pos = (ctx.pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; @@ -195,7 +195,7 @@ void SDLContext::draw_text(const RenderText & data) { const Text & text = data.text; const Font & font = data.font; - const Transform & transform = data.transform; + vec2 absoluut_pos = AbsoluutPosition::get_position(data.transform, data.text.offset); std::unique_ptr> font_surface; std::unique_ptr> font_texture; @@ -220,8 +220,8 @@ void SDLContext::draw_text(const RenderText & data) { font_texture = {tmp_font_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; - vec2 size = text.dimensions * cam_aux_data.render_scale * transform.scale; - vec2 screen_pos = (transform.position + text.offset - cam_aux_data.cam_pos + vec2 size = text.dimensions * cam_aux_data.render_scale * data.transform.scale; + vec2 screen_pos = (absoluut_pos + text.offset - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; @@ -233,8 +233,8 @@ void SDLContext::draw_text(const RenderText & data) { .h = size.y, }; - SDL_RenderCopyExF(this->game_renderer.get(), font_texture.get(), NULL, &dstrect, transform.rotation, NULL, - SDL_FLIP_NONE); + SDL_RenderCopyExF(this->game_renderer.get(), font_texture.get(), NULL, &dstrect, + data.transform.rotation, NULL, SDL_FLIP_NONE); } void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) { diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index bf2bfd3..ba09530 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -21,6 +21,7 @@ #include "RenderSystem.h" #include "types.h" +#include "util/AbsoluutPosition.h" using namespace crepe; using namespace std; @@ -99,8 +100,7 @@ void RenderSystem::render_text() { } } -bool RenderSystem::render_particle(const Sprite & sprite, const double & scale) { - +bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm){ ComponentManager & mgr = this->mediator.component_manager; SDLContext & ctx = this->mediator.sdl_context; ResourceManager & resource_manager = this->mediator.resource_manager; @@ -122,9 +122,9 @@ bool RenderSystem::render_particle(const Sprite & sprite, const double & scale) ctx.draw(SDLContext::RenderContext{ .sprite = sprite, .texture = res, - .pos = p.position, + .pos = AbsoluutPosition::get_position(tm, em.data.offset + sprite.data.position_offset), .angle = p.angle, - .scale = scale, + .scale = tm.scale, }); } } @@ -138,7 +138,7 @@ void RenderSystem::render_normal(const Sprite & sprite, const Transform & tm) { ctx.draw(SDLContext::RenderContext{ .sprite = sprite, .texture = res, - .pos = tm.position, + .pos = AbsoluutPosition::get_position(tm, sprite.data.position_offset), .angle = tm.rotation, .scale = tm.scale, }); @@ -158,7 +158,7 @@ void RenderSystem::render() { const Transform & transform = mgr.get_components_by_id(sprite.game_object_id).front().get(); - bool rendered_particles = this->render_particle(sprite, transform.scale); + bool rendered_particles = this->render_particle(sprite, transform); if (rendered_particles) continue; diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index d5385eb..762b11f 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -53,7 +53,7 @@ private: * constructor is now protected i cannot make tmp inside * \return true if particles have been rendered */ - bool render_particle(const Sprite & sprite, const double & scale); + bool render_particle(const Sprite & sprite, const Transform & tm); /** * \brief renders a sprite with a Transform component on the screen * diff --git a/src/crepe/util/AbsoluutPosition.cpp b/src/crepe/util/AbsoluutPosition.cpp new file mode 100644 index 0000000..296cc09 --- /dev/null +++ b/src/crepe/util/AbsoluutPosition.cpp @@ -0,0 +1,20 @@ +#include "AbsoluutPosition.h" + +using namespace crepe; + +vec2 AbsoluutPosition::get_position(const Transform & transform, const vec2 & offset) { + // Get the rotation in radians + float radians1 = transform.rotation * (M_PI / 180.0); + + // Calculate total offset with scale + vec2 total_offset = offset * transform.scale; + + // Rotate + float rotated_total_offset_x1 + = total_offset.x * cos(radians1) - total_offset.y * sin(radians1); + float rotated_total_offset_y1 + = total_offset.x * sin(radians1) + total_offset.y * cos(radians1); + + // Final positions considering scaling and rotation + return (transform.position + vec2(rotated_total_offset_x1, rotated_total_offset_y1)); +} diff --git a/src/crepe/util/AbsoluutPosition.h b/src/crepe/util/AbsoluutPosition.h new file mode 100644 index 0000000..30a7f93 --- /dev/null +++ b/src/crepe/util/AbsoluutPosition.h @@ -0,0 +1,14 @@ +#pragma once + +#include "api/Transform.h" + +#include "types.h" + +namespace crepe { + +class AbsoluutPosition { +public: + static vec2 get_position(const Transform & transform, const vec2 & offset); +}; + +} // namespace crepe diff --git a/src/crepe/util/CMakeLists.txt b/src/crepe/util/CMakeLists.txt index 94ed906..b4b9221 100644 --- a/src/crepe/util/CMakeLists.txt +++ b/src/crepe/util/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(crepe PUBLIC LogColor.cpp Log.cpp + AbsoluutPosition.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -11,5 +12,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Proxy.hpp OptionalRef.h OptionalRef.hpp + AbsoluutPosition.h ) diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 4430d75..9cf25d7 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -23,11 +23,11 @@ using namespace std; class TestScene : public Scene { public: void load_scene() { - GameObject game_object = new_object("", "", vec2{0, 0}, 0, 1); + GameObject game_object = new_object("", "", vec2{0, 0}, 45, 1); Color color(255, 255, 255, 255); - Asset img{"asset/spritesheet/spritesheet_test.png"}; + Asset img{"asset/texture/square.png"}; Sprite & test_sprite = game_object.add_component( img, Sprite::Data{ @@ -35,17 +35,30 @@ public: .flip = Sprite::FlipSettings{false, false}, .sorting_in_layer = 2, .order_in_layer = 2, - .size = {0, 0}, + .size = {1, 1}, .angle_offset = 0, - .position_offset = {0, 0}, + .position_offset = {0, 1}, }); - auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{4000, 4000}, + Sprite & test_sprite1 + = game_object.add_component(img, Sprite::Data{ + .color = color, + .size = {1, 1}, + .position_offset = {0, -1}, + }); + + auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{5, 5}, Camera::Data{ .bg_color = Color::WHITE, }); - game_object.add_component(vec2{4000, 400}, vec2{0, 0}, "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::RED}, "test TEST"); + + game_object.add_component(vec2{1, 1}, vec2{0, 0.5}, "ComicSansMS", + Text::Data{.text_color = Color::BLACK}, "TEST test"); + */ } string get_name() const { return "TestScene"; }; -- cgit v1.2.3 From ebe2fcfce52d9a303c5fa19d79554e20ac7f0bac Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Thu, 19 Dec 2024 09:07:34 +0100 Subject: removed absolute position because jaro is adjusting that --- src/crepe/system/RenderSystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index ba09530..b4b745f 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -122,7 +122,7 @@ bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm){ ctx.draw(SDLContext::RenderContext{ .sprite = sprite, .texture = res, - .pos = AbsoluutPosition::get_position(tm, em.data.offset + sprite.data.position_offset), + .pos = p.position, .angle = p.angle, .scale = tm.scale, }); @@ -138,7 +138,7 @@ void RenderSystem::render_normal(const Sprite & sprite, const Transform & tm) { ctx.draw(SDLContext::RenderContext{ .sprite = sprite, .texture = res, - .pos = AbsoluutPosition::get_position(tm, sprite.data.position_offset), + .pos = tm.position, .angle = tm.rotation, .scale = tm.scale, }); -- cgit v1.2.3 From b6d3bc08126652ed42a7c84f5e4a8283e5e74d22 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Thu, 19 Dec 2024 14:01:35 +0100 Subject: fix merge conflict --- src/crepe/system/RenderSystem.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 3ec1922..579c9f5 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -21,7 +21,6 @@ #include "RenderSystem.h" #include "types.h" -#include "util/AbsoluutPosition.h" using namespace crepe; using namespace std; @@ -124,7 +123,7 @@ bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm){ .sprite = sprite, .texture = res, .pos = p.position, - .angle = p.angle + transform_angle, + .angle = p.angle + tm.rotation, .scale = tm.scale, }); } -- cgit v1.2.3 From accec60f4e0150989a04afa14fca56fcca7658ac Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Thu, 19 Dec 2024 14:01:54 +0100 Subject: make format --- src/crepe/api/Script.cpp | 1 - src/crepe/system/RenderSystem.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 85016f5..7531388 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -40,4 +40,3 @@ bool Script::get_key_state(Keycode key) const noexcept { return false; } } - diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 579c9f5..e311604 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -99,7 +99,7 @@ void RenderSystem::render_text() { } } -bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm){ +bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm) { ComponentManager & mgr = this->mediator.component_manager; SDLContext & ctx = this->mediator.sdl_context; ResourceManager & resource_manager = this->mediator.resource_manager; -- cgit v1.2.3 From 26c6d4ade7e6748fe65d3ba8d9d267053d3cba2a Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Thu, 19 Dec 2024 14:07:52 +0100 Subject: adjusted tm naming --> transform and adjusted doxygen comments --- src/crepe/system/RenderSystem.cpp | 14 +++++++------- src/crepe/system/RenderSystem.h | 16 ++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index e311604..e8339c3 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -99,7 +99,7 @@ void RenderSystem::render_text() { } } -bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm) { +bool RenderSystem::render_particle(const Sprite & sprite, const Transform & transform) { ComponentManager & mgr = this->mediator.component_manager; SDLContext & ctx = this->mediator.sdl_context; ResourceManager & resource_manager = this->mediator.resource_manager; @@ -123,14 +123,14 @@ bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tm) .sprite = sprite, .texture = res, .pos = p.position, - .angle = p.angle + tm.rotation, - .scale = tm.scale, + .angle = p.angle + transform.rotation, + .scale = transform.scale, }); } } return rendering_particles; } -void RenderSystem::render_normal(const Sprite & sprite, const Transform & tm) { +void RenderSystem::render_normal(const Sprite & sprite, const Transform & transform) { SDLContext & ctx = this->mediator.sdl_context; ResourceManager & resource_manager = this->mediator.resource_manager; const Texture & res = resource_manager.get(sprite.source); @@ -138,9 +138,9 @@ void RenderSystem::render_normal(const Sprite & sprite, const Transform & tm) { ctx.draw(SDLContext::RenderContext{ .sprite = sprite, .texture = res, - .pos = tm.position, - .angle = tm.rotation, - .scale = tm.scale, + .pos = transform.position, + .angle = transform.rotation, + .scale = transform.scale, }); } diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 762b11f..ed55dd5 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -47,20 +47,17 @@ private: * \brief Renders all the particles on the screen from a given sprite. * * \param sprite renders the particles with given texture - * \param tm the Transform component for scale. This is not a const reference because each - * particle has a position and rotation that needs to overwrite the transform position and - * rotation without overwriting the current transform. and because the transform - * constructor is now protected i cannot make tmp inside + * \param transform the component that holds the position, rotation, and scale. * \return true if particles have been rendered */ - bool render_particle(const Sprite & sprite, const Transform & tm); + bool render_particle(const Sprite & sprite, const Transform & transform); /** * \brief renders a sprite with a Transform component on the screen * * \param sprite the sprite component that holds all the data - * \param tm the Transform component that holds the position,rotation and scale + * \param transform the Transform component that holds the position,rotation and scale */ - void render_normal(const Sprite & sprite, const Transform & tm); + void render_normal(const Sprite & sprite, const Transform & transform); /** * \brief sort a vector sprite objects with @@ -70,11 +67,6 @@ private: */ RefVector sort(RefVector & objs) const; - /** - * \todo Add text rendering using SDL_ttf for text components. - * \todo Implement a text component and a button component. - * \todo Consider adding text input functionality. - */ }; } // namespace crepe -- cgit v1.2.3 From 7c8c94663fdedb212e993eec232e6d40290cb67e Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Thu, 19 Dec 2024 15:51:59 +0100 Subject: make format --- src/crepe/facade/SDLContext.cpp | 8 ++++---- src/crepe/facade/SDLContext.h | 2 +- src/crepe/system/RenderSystem.h | 1 - src/example/rendering_particle.cpp | 7 +++---- 4 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index dc3f362..6fb312b 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -153,13 +153,13 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { size *= cam_aux_data.render_scale * ctx.img_scale * data.scale_offset; if (ctx.sprite.data.world_space) { - screen_pos = (screen_pos - cam_aux_data.cam_pos - + cam_aux_data.zoomed_viewport / 2) + 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; + screen_pos + = (screen_pos + cam_aux_data.zoomed_viewport / 2) * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; } cout << "HALLO" << endl; diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 7f07d34..e570073 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -19,9 +19,9 @@ #include "api/Sprite.h" #include "api/Transform.h" -#include "types.h" #include "EventData.h" #include "FontFacade.h" +#include "types.h" namespace crepe { class Texture; diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index ed55dd5..14e5c2d 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -66,7 +66,6 @@ private: * \return returns a sorted reference vector */ RefVector sort(RefVector & objs) const; - }; } // namespace crepe diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index b623596..5440fdd 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -38,7 +38,7 @@ public: .size = {1, 1}, .angle_offset = 0, .position_offset = {0, 1}, - .world_space = false, + .world_space = false, }); //auto & emitter = game_object.add_component(test_sprite, ParticleEmitter::Data{}); @@ -47,16 +47,15 @@ public: .color = color, .size = {1, 1}, .position_offset = {0, -1}, - .world_space = false, + .world_space = false, }); auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{5, 5}, Camera::Data{ .bg_color = Color::WHITE, - .postion_offset = {1000,1000}, + .postion_offset = {1000, 1000}, }); - /* game_object.add_component(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS", Text::Data{.text_color = Color::RED}, "test TEST"); -- cgit v1.2.3