Wondering if my implementation is a good way to go about this pixel simulation

Hello! I am new to coding with graphics. I’ve made a sand simulation in PyGame and I decided to rewrite it in SDL.

Before I code any further… I had a couple of concerns with my implementation.

I am directly working with the pixels by updating their colors using SDL_SetRenderDrawColor() and SDL_RenderDrawPoint(). No textures.

However, I am looping through the screen multiple times. Once to move elements that can be moved, and again to draw them.

I suspect I am thinking about this implementation inefficiently. I have no frame cap right now, but currently the screen width and height are set to 250, but when I move it up to something like 500, the simulation is very slow and I suspect it is due to the implementation I currently have for drawing the pixels.

I was wondering if anyone could provide me with some insight on creating a pixel-based game such as this? I’d appreciate some higher level abstraction, I just want to get better at coding in general.

Here is my Github repo with my full source code if anyone wants to take a look! Thank you very much.

I think drawing lots of pixels with SDL_RenderDrawPoint would be very slow and you’d be better off with SDL_RenderDrawPoints. See:


Thanks for your reply!

How would I go about setting the color of each pixel if I’m drawing them all at once?

I was previously setting the draw color then rendering the pixel. If I’m rendering them in a batch, I’m not sure how to go about setting individual colors.

I’d draw all the pixels that are gonna be the same colour in batches.