rendering_system.cpp 1.1 KB

12345678910111213141516171819202122232425262728
  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. constexpr int logical_width = 1920;
  11. constexpr int logical_height = 1080;
  12. SDL_SetRenderLogicalPresentation(ctx, logical_width, logical_height, SDL_LOGICAL_PRESENTATION_LETTERBOX);
  13. SDL_SetRenderDrawColor(ctx, 0u, 0u, 0u, SDL_ALPHA_OPAQUE);
  14. SDL_RenderClear(ctx);
  15. for(auto [entt, pos, rect]: registry.view<renderable_component, position_component, rect_component>().each()) {
  16. SDL_FRect elem{rect.area.x + pos.point.x, rect.area.y + pos.point.y, rect.area.w, rect.area.h};
  17. SDL_SetRenderDrawColor(ctx, 255u, 255u, 255u, SDL_ALPHA_OPAQUE);
  18. SDL_RenderRect(ctx, &elem);
  19. }
  20. SDL_SetRenderLogicalPresentation(ctx, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED);
  21. }
  22. } // namespace testbed