From 767607ede15a87cfbbc5ccf3f332adb76c733b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20H=C3=B6rdt?= <6329417-neop_@users.noreply.gitlab.com> Date: Sun, 4 Aug 2024 19:40:28 +0200 Subject: [PATCH] batch draw points and color --- main.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 2a37db2..f22a551 100644 --- a/main.cpp +++ b/main.cpp @@ -95,14 +95,11 @@ int main() try { window_t window{SDL_CreateWindow( "random walk", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, - height, 0 // SDL_WINDOW_FULLSCREEN + height, SDL_WINDOW_FULLSCREEN )}; renderer_t renderer{SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED) }; SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); - sdl_check(SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE)); - sdl_check(SDL_RenderClear(renderer)); - sdl_check(SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE)); { // dump renderer info SDL_RendererInfo renderer_info; @@ -119,6 +116,10 @@ int main() try { renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height ); + sdl_check(SDL_SetRenderTarget(renderer, texture)); + sdl_check(SDL_SetRenderDrawColor(renderer, 0xdb, 0xd7, 0xc0, SDL_ALPHA_OPAQUE)); + sdl_check(SDL_RenderClear(renderer)); + sdl_check(SDL_SetRenderDrawColor(renderer, 0x0d, 0x0f, 0x14, SDL_ALPHA_OPAQUE)); SDL_Point pos{.x = width / 2, .y = height / 2}; constexpr SDL_Point directions[] = { @@ -130,7 +131,7 @@ int main() try { // aarrggbb?? constexpr Uint32 bg_color = 0xffdbd7c0; constexpr Uint32 walk_color = 0xff0d0f14; - constexpr auto batchsize = 1; + constexpr auto batchsize = 100; const auto start_time = clock::now(); auto next_poll_events_time = start_time; @@ -151,6 +152,7 @@ int main() try { } sdl_check(SDL_SetRenderTarget(renderer, texture)); + std::array point_batch; for (auto step = 0z; step < batchsize; ++step) { SDL_Point newpoint; do { @@ -158,8 +160,9 @@ int main() try { } while (newpoint.x < 0 or newpoint.x >= width or newpoint.y < 0 or newpoint.y >= height); pos = newpoint; - sdl_check(SDL_RenderDrawPoint(renderer, pos.x, pos.y)); + point_batch[step] = newpoint; } + sdl_check(SDL_RenderDrawPoints(renderer, point_batch.data(), point_batch.size())); sdl_check(SDL_SetRenderTarget(renderer, nullptr)); sdl_check(SDL_RenderCopy(renderer, texture, nullptr, nullptr));