From 8abc6008880dd9ed0c16a68a126b49f0eb03caa2 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 16 Dec 2024 20:52:43 +0100 Subject: fonting --- src/crepe/api/Config.h | 2 +- src/crepe/api/Text.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 47a81b7..c20287d 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -26,7 +26,7 @@ struct Config final { * * Only messages with equal or higher priority than this value will be logged. */ - Log::Level level = Log::Level::INFO; + Log::Level level = Log::Level::DEBUG; /** * \brief Colored log output * diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp index 5b2befe..07d1705 100644 --- a/src/crepe/api/Text.cpp +++ b/src/crepe/api/Text.cpp @@ -1,4 +1,5 @@ #include "../facade/FontFacade.h" +#include "util/Log.h" #include "Text.h" @@ -9,4 +10,6 @@ Text::Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, : UIObject(id, dimensions, offset), text(text), data(data), - font(FontFacade::get_font_asset(font_family)) {} + font(FontFacade::get_font_asset(font_family)) { + dbg_trace(); +} -- 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/api') 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 7039acfa49e64b6865c7897de29a1b812b8df7d0 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 14:22:04 +0100 Subject: revered to master --- src/crepe/api/Config.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index b86faff..ca2d3f1 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -26,7 +26,7 @@ struct Config final { * * Only messages with equal or higher priority than this value will be logged. */ - Log::Level level = Log::Level::DEBUG; + Log::Level level = Log::Level::INFO; /** * \brief Colored log output * @@ -76,17 +76,6 @@ struct Config final { */ std::string root_pattern = ".crepe-root"; } asset; - //! Default font options - struct { - /** - * \brief Default font size - * - * Using the SDL_ttf library the font size needs to be set when loading the font. - * This config option is the font size at which all fonts will be loaded initially. - * - */ - unsigned int size = 32; - } font; //! Audio system settings struct { -- cgit v1.2.3 From 6ba8f83d482b5b7ade4cf63293cb9625a7e91f55 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 17 Dec 2024 14:44:40 +0100 Subject: config will be checout with master once PR#77 is merged, and sdlcontext adjustemetns for merging --- src/crepe/api/Config.h | 4 ++++ src/crepe/facade/SDLContext.h | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index ed1cf38..e91ecd1 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -46,6 +46,10 @@ 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/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 7c791f2..e9c334e 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -78,13 +78,6 @@ public: const Transform & transform; }; -public: - /** - * \brief Gets the singleton instance of SDLContext. - * \return Reference to the SDLContext instance. - */ - static SDLContext & get_instance(); - public: SDLContext(const SDLContext &) = delete; SDLContext(SDLContext &&) = delete; -- 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/api') 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/api') 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 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/api') 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