vector<int>xxi;
vector<int>yyi;
int main(int argc, char* argv[])
{
//Start up SDL and create window
if (!init())
{
printf("Failed to initialize!\n");
}
else
{
//Load media
if(0==1)
{
printf("Failed to load media!\n");
}
else
{
//Main loop flag
bool quit = false;
//Event handler
SDL_Event e;
//While application is running
while (!quit)
{
SDL_RenderDrawPoint(gRenderer, xxi[i], yyi[i]);
}
Here the figure keeps redrawing itself.
But I want the xxi[i], and yyi[i] points to get drawn once.
and stop refreshing.
and if I set quit to 1 or break the loop.
The window closes.
I am rendering the pixels.
But for example.
I am drawing a line.
But normal occurrence should draw the lines using pixel.
And the line should get fixated.
But the line keeps. refreshing.
line keeps redrawing itself.
You have to clear the screen and redraw everything every frame. That’s just how it works in hardware-accelerated land. If you want to plot pixels and not have to plot them again every frame, use SDL_Surfaces, but you won’t be able to use SDL_Renderer
You certainly can use SDL_Renderer in that case, it’s how my application works, but you must render to a target texture rather than to the default target. The code outline should be as follows:
SDL_Texture *target = SDL_CreateTexture(renderer, PIXELFORMAT, SDL_TEXTUREACCESS_TARGET, width, height);
SDL_SetRenderTarget(renderer, target);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
// Now draw whatever it is that you want to draw (just once!):
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDrawPoint(renderer, xxi[i], yyi[i]);
// Main loop:
bool quit = 0;
while (!quit)
{
// Handle events
// Copy texture to default target and present:
SDL_SetRenderTarget(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, target, NULL, NULL);
SDL_RenderPresent(renderer);
SDL_SetRenderTarget(renderer, target);
}
I can confirm that this works very well. You can update the texture whenever you want, but it is persistent so once updated you do not need to write to it again until something changes.