From d521c06c34a7b73a6a45de8bebac83cac843581c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20H=C3=B6rdt?= <6329417-neop_@users.noreply.gitlab.com> Date: Sat, 3 Aug 2024 23:38:19 +0200 Subject: [PATCH] simple surface drawing --- main.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index 6804914..b6285a1 100644 --- a/main.cpp +++ b/main.cpp @@ -2,13 +2,9 @@ #include -#include -#include -#include #include #include #include -#include template struct sdl_wrapper_t : std::unique_ptr { @@ -73,6 +69,13 @@ int main() { auto* window_surface = SDL_GetWindowSurface(window); if (!window_surface) { return EXIT_FAILURE; } if (window_surface->format->palette) { return EXIT_FAILURE; } + std::println( + "got surface with {} bits per pixel", + window_surface->format->BitsPerPixel + ); + if (!(window_surface->format->format & SDL_PIXELFORMAT_RGBA32)) { + return EXIT_FAILURE; + } SDL_Point pos{.x = width / 2, .y = height / 2}; const SDL_Point directions[] = { @@ -81,17 +84,20 @@ int main() { std::mt19937_64 rne(std::random_device{}()); std::uniform_int_distribution dist(0, 3); + // aarrggbb?? + constexpr Uint32 walk_color = 0xff00ff00; for (bool continu = true; continu;) { - - { - SDL_Point newpoint; - do { - newpoint = pos + directions[dist(rne)]; - } while (newpoint.x < 0 or newpoint.x >= width or newpoint.y < 0 or - newpoint.y >= height); - pos = newpoint; - } + SDL_Point newpoint; + do { + newpoint = pos + directions[dist(rne)]; + } while (newpoint.x < 0 or newpoint.x >= width or newpoint.y < 0 or + newpoint.y >= height); + pos = newpoint; + SDL_LockSurface(window_surface); + static_cast(window_surface->pixels + )[pos.x + pos.y * window_surface->h] = walk_color; + SDL_UnlockSurface(window_surface); for (SDL_Event e; SDL_PollEvent(&e);) { if (e.type == SDL_QUIT) { continu = false; }