// g++ main.cpp `pkg-config --cflags --libs sdl2`
#include <SDL.h>
#include <iostream>
int main( int argc, char** argv )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* win = SDL_CreateWindow("my window", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if (!win)
{
std :: cout << "Failed to create a window! Error: " << SDL_GetError() << "
";
}
SDL_Surface* winSurface = SDL_GetWindowSurface(win);
bool running = true;
while( running )
{
SDL_Event ev;
while( SDL_PollEvent( &ev ) )
{
if( ( SDL_QUIT == ev.type ) ||
( SDL_KEYDOWN == ev.type && SDL_SCANCODE_ESCAPE == ev.key.keysym.scancode ) )
{
running = false;
break;
}
}
SDL_FillRect(winSurface, NULL, SDL_MapRGB(winSurface->format, 255, 90, 120));
SDL_UpdateWindowSurface(win);
}
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}