I'm using SDL and need to plot pixels one by one on the screen. When I do this, it's extremely slow. I followed the tutorial here:
http://www.programmersranch.com/2014/02/sdl2-pixel-drawing.html
Which basically said to call:
SDL_RenderClear();
SDL_RenderCopy();
SDL_RenderPresent();
SDL_UpdateTexture();
Right after I update my pixel array.
I ran a loop (which calls the above functions) to demonstrate the issue:
for (unsigned int i = 0; i < 128; i++)
for (unsigned int j = 0; j < 128; j++)
plot_pixel(j, i, 0xff); // x, y, ARGB val
But it runs painfully slow. Is there a better way to plot pixels with extreme speed? The whole idea of my program is to plot pixels as fast as possible, and it takes several seconds to run through that loop and plot 128*128 pixels.
Here is the code for plot_pixel:
void plot_pixel(int x, int y, int argb)
{
pixels[y*width+x] = argb;
SDL_UpdateTexture(texture, NULL, pixels, width * 4);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
The code works exactly like I want it to (it plots a pixel) but its painfully slow.