Try to port renderer

This commit is contained in:
2025-06-09 10:16:22 +02:00
parent fca47a059c
commit e1c6091450
3 changed files with 22 additions and 35 deletions

View File

@@ -14,7 +14,8 @@ struct TextureAtlasLayout
struct Texture struct Texture
{ {
// SDL_Texture* sdl_texture; uint8_t* data;
uint32_t data_length;
TextureAtlasLayout texture_atlas_layout; TextureAtlasLayout texture_atlas_layout;
}; };

View File

@@ -5,6 +5,7 @@
#include "physics.hpp" #include "physics.hpp"
#include "render.hpp" #include "render.hpp"
#include <Hall/Hall.h>
#include <entt/entt.hpp> #include <entt/entt.hpp>
void increment_ticks(entt::registry& registry) void increment_ticks(entt::registry& registry)
@@ -85,10 +86,11 @@ int main()
PhysicsModule::RemoveCollisionMarker(registry); PhysicsModule::RemoveCollisionMarker(registry);
PhysicsModule::CollisionCheck(registry); PhysicsModule::CollisionCheck(registry);
// SDL_RenderClear(sdl_handles.renderer); Hall::Clear(0);
RenderModule::RenderSprites(registry); RenderModule::RenderSprites(registry);
RenderModule::RenderScore(registry); RenderModule::RenderScore(registry);
// SDL_RenderPresent(sdl_handles.renderer); Hall::SetCommandSwapBuffers();
Hall::GetVSync();
} }
return 0; return 0;

View File

@@ -5,6 +5,8 @@
#include "physics.hpp" #include "physics.hpp"
#include "sprite.hpp" #include "sprite.hpp"
#include <Hall/Hall.h>
#include <format> #include <format>
RenderModule::RenderModule(entt::registry& registry) RenderModule::RenderModule(entt::registry& registry)
@@ -13,47 +15,29 @@ RenderModule::RenderModule(entt::registry& registry)
void RenderModule::RenderSprites(entt::registry& registry) void RenderModule::RenderSprites(entt::registry& registry)
{ {
// auto const& sdl_handles = registry.ctx().get<SdlHandles>();
auto const& game = registry.ctx().get<Game>(); auto const& game = registry.ctx().get<Game>();
auto sprites_view = auto sprites_view =
registry.view<Position const, Size const, Sprite const>(entt::exclude<Background>); registry.view<Position const, Size const, Sprite const>(entt::exclude<Background>);
auto background_view = registry.view<Position const, Size const, Sprite const, Background>(); auto background_view = registry.view<Position const, Size const, Sprite const, Background>();
for (auto [entity, pos, size, sprite] : background_view.each()) auto render_sprite = [](entt::entity entity, Position const& pos, Size const& size, Sprite const&sprite){
{
TextureAtlasLayout layout = sprite.texture->texture_atlas_layout; TextureAtlasLayout layout = sprite.texture->texture_atlas_layout;
uint8_t row = sprite.texture_atlas_index / layout.columns; uint8_t row = sprite.texture_atlas_index / layout.columns;
uint8_t column = sprite.texture_atlas_index % layout.columns; uint8_t column = sprite.texture_atlas_index % layout.columns;
// SDL_FRect srcrect{static_cast<float>(column * layout.width), // Problemchen: Wir können die Sprites nicht strecken... hat keiner Interpolation
// static_cast<float>(row * layout.height), // implementiert?
// static_cast<float>(layout.width), Hall::Draw(reinterpret_cast<unsigned short*>(sprite.texture->data), // Das ist 100% UB
// static_cast<float>(layout.height)}; column * layout.width,
row * layout.height,
pos.x,
pos.y,
layout.width,
layout.height,
sprite.texture->data_length);
};
// SDL_FRect dstrect{static_cast<float>(pos.x), background_view.each(render_sprite);
// static_cast<float>(pos.y), sprites_view.each(render_sprite);
// static_cast<float>(size.w),
// static_cast<float>(size.h)};
// SDL_RenderTexture(sdl_handles.renderer, sprite.texture->sdl_texture, &srcrect, &dstrect);
}
for (auto [entity, pos, size, sprite] : sprites_view.each())
{
TextureAtlasLayout layout = sprite.texture->texture_atlas_layout;
uint8_t row = sprite.texture_atlas_index / layout.columns;
uint8_t column = sprite.texture_atlas_index % layout.columns;
// SDL_FRect srcrect{static_cast<float>(column * layout.width),
// static_cast<float>(row * layout.height),
// static_cast<float>(layout.width),
// static_cast<float>(layout.height)};
// SDL_FRect dstrect{static_cast<float>(pos.x),
// static_cast<float>(pos.y),
// static_cast<float>(size.w),
// static_cast<float>(size.h)};
// SDL_RenderTexture(sdl_handles.renderer, sprite.texture->sdl_texture, &srcrect, &dstrect);
}
} }
void RenderModule::RenderScore(entt::registry& registry) void RenderModule::RenderScore(entt::registry& registry)