High cpu usage while rendering?

Hi, I’m trying to make my own bmp image rendering function myself without using SDL_image for pratice.

However, cpu usage was too high compare to SDL_image.

I used SDL_RenderDrawPoint() and multi-for statement for drawing an image.
When I put my own function to while loop (main sdl loop), the cpu usage went crazy.

I think it’s because I didn’t use GPU for rendering, so can someone give me some advises or solutions for this?

This also happens when I rendering a lot of images. How can I make my SDL faster and less cpu using compare to other programs?

Please help me.
Thank you.

You don’t need SDL_image for BMPs. Core SDL2 has the necessary functionality to render them: SDL_LoadBMP(), SDL_CreateTextureFromSurface(), and SDL_RenderCopy().

Yeah… I know that… but as I wrote, I want to pratice and try to make my own one. I want to know how it works and why it’s that slow when I remake BMP loading myself.

Using SDL_RenderDrawPoint to draw an image one pixel at a time is always going to be incredibly slow!

Maybe SDL_RenderDrawPoints is quicker (unless it just calls SDL_RenderDrawPoint for each point) but it’s a terribly slow way to draw an image either way.

Then, what should I do? Should I create an empty texture or surface and write rgb points on it? I think that’s slow too.

Decoding pixel data to a surface in RAM is the fastest way of doing it, which is how it’s already done with SDL_LoadBMP.

Is there a reason why you’re trying to reinvent the stone wheel one grain of sand at a time? If you’re just wanting to kill time out of interest, take a look at LodePNG. You can look at how the source code builds up the pixel data in memory.