I my trying to learn SDL in C++ . I have simple program which will display a image . but When I try to close window by clicking close button on the window nothing happens.
here is my code:-
#include <SDL2/SDL.h> int main(int argc,char **argv) { static int k =0; SDL_Init(SDL_INIT_VIDEO); SDL_Window *w; w = SDL_CreateWindow("SDL VS Works",300,300,400,500,SDL_WINDOW_OPENGL); SDL_Renderer *render = SDL_CreateRenderer(w,-1,SDL_RENDERER_ACCELERATED); SDL_Surface *tux = SDL_LoadBMP("res/tux.bmp"); SDL_Texture *texture = SDL_CreateTextureFromSurface(render,tux); SDL_FreeSurface(tux); SDL_ShowWindow(w); SDL_Event event; while(1) { k++; printf("Running and loop %d\'th\n",k); SDL_PollEvent(&event); if(event.type == SDL_QUIT) { printf("closing \n"); goto sos; } SDL_RenderCopy(render,texture,0,0); SDL_RenderPresent(render); SDL_Delay(1000); } sos: SDL_DestroyWindow(w); SDL_DestroyRenderer(render); SDL_DestroyTexture(texture); SDL_Quit(); } I am using g++ 7.3 on Arch Linux.
gototobreakout of a loop.SDL_PollEventreturns. Usually by having it as a condition in a loop.