while(event.type != SDL_QUIT)
{
SDL_RenderClear(sdlRenderer);
SDL_SetRenderDrawColor(sdlRenderer, 150, 0, 0, 255);
SDL_RenderPresent(sdlRenderer);
}
You are comparing a variable that doesn't change in your while
loop. You need to update it in every iteration of loop using SDL_PollEvent(&event)
Something like this:
bool quit = false;
SDL_Event event;
// Loop while user hasn't quit
while ( !quit )
{
// Check all new event to see if a SDL_QUIT event has come in...
while (SDL_PollEvent(&event) )
{
// SDL_QUIT event has come in, quit.
if ( event.type == SDL_QUIT )
{
quit = true;
}
}
SDL_RenderClear(sdlRenderer);
SDL_SetRenderDrawColor(sdlRenderer, 150, 0, 0, 255);
SDL_RenderPresent(sdlRenderer);
}
Also I don't think you need SDL2_main anymore. At least I don't use it in my code.
Nor do you need #include <stdio.h>
and #include <stdlib.h>
in your specific example.
Tutorials
SDL2 is fairly new, so there aren't that much tutorials around. The only ones I know is TwinklebearDev.But in most cases SDL1.3 and SDL2 are quite similar. So in most cases you can use SDL1.3 code with SDL_Texture
, SDL_Renderer
and SDL_Window.
You can have a look here for more information on porting from 1.3 to 2.0. For SDL1.3 I have used LazyFoo's tutorials.