batch draw points and color

This commit is contained in:
Jakob Hördt 2024-08-04 19:40:28 +02:00
parent cc58fa1f50
commit 767607ede1

View file

@ -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<SDL_Point, batchsize> 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));