#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <glm/common.hpp>
#include <stdexcept>
#include <vector>
const static int width = 1280;
const static int height = 800;
struct STATE {
SDL_Window *w;
SDL_Renderer *rdr;
};
auto SDL_AppInit(void **appstate, int argc, char **argv) -> SDL_AppResult {
SDL_Init(SDL_INIT_VIDEO);
auto state = new STATE;
if (!SDL_CreateWindowAndRenderer(
"", width, height, SDL_WINDOW_UTILITY, &state->w, &state->rdr
)) {
throw std::runtime_error(SDL_GetError());
};
*appstate = state;
return SDL_APP_CONTINUE;
}
constexpr float tau = std::numbers::pi_v<float> * 2.f;
auto SDL_AppIterate(void *appstate) -> SDL_AppResult {
auto state = reinterpret_cast<STATE *>(appstate);
SDL_SetRenderDrawColor(state->rdr, 0, 0, 0, 255);
SDL_RenderClear(state->rdr);
auto arc = sKit::geom::vertex::arc<SDL_FPoint>(
width / 3.f,
height / 3.f,
100,
glm::fract(SDL_GetTicks() * 0.0003) * tau,
);
SDL_RenderGeometry(
state->rdr,
nullptr,
c.vertices.data(),
c.vertices.size(),
c.indices.data(),
c.indices.size()
);
SDL_SetRenderDrawColor(state->rdr, 255, 255, 255, 255);
SDL_RenderLines(state->rdr,
arc.data(),
arc.size());
SDL_RenderPresent(state->rdr);
return SDL_APP_CONTINUE;
}
auto SDL_AppEvent(void *appstate, SDL_Event *event) -> SDL_AppResult {
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
} else if (event->key.key == SDLK_ESCAPE) {
return SDL_APP_SUCCESS;
} else
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
delete reinterpret_cast<STATE *>(appstate);
}