rendering_system.cpp 981 B

12345678910111213141516171819202122232425
  1. #include <SDL3/SDL_render.h>
  2. #include <application/context.h>
  3. #include <component/position_component.h>
  4. #include <component/rect_component.h>
  5. #include <component/renderable_component.h>
  6. #include <entt/entity/registry.hpp>
  7. #include <system/rendering_system.h>
  8. namespace testbed {
  9. void rendering_system(entt::registry &registry, const context &ctx) {
  10. SDL_SetRenderLogicalPresentation(ctx, ctx.logical_width(), ctx.logical_height(), SDL_LOGICAL_PRESENTATION_LETTERBOX);
  11. SDL_SetRenderDrawColor(ctx, 0u, 0u, 0u, SDL_ALPHA_OPAQUE);
  12. SDL_RenderClear(ctx);
  13. for(auto [entt, pos, rect]: registry.view<renderable_component, position_component, rect_component>().each()) {
  14. SDL_FRect elem{rect.x + pos.x, rect.y + pos.y, rect.w, rect.h};
  15. SDL_SetRenderDrawColor(ctx, 255u, 255u, 255u, SDL_ALPHA_OPAQUE);
  16. SDL_RenderFillRect(ctx, &elem);
  17. }
  18. SDL_SetRenderLogicalPresentation(ctx, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED);
  19. }
  20. } // namespace testbed