💾 Archived View for kvothe.one › dev › scraps › hello_sdl.c captured on 2020-11-07 at 00:58:27.

View Raw

More Information

⬅️ Previous capture (2020-09-24)

-=-=-=-=-=-=-

#define SDL_DISABLE_IMMINTRIN_H 1
#include <SDL2/SDL.h>
#include <stdio.h>

// compile as follows:
// gcc -lSDL2 -L/usr/local/lib -I/usr/local/include hello_sdl.c -o hello_sdl

int main() {
    SDL_Window*  window         = NULL;
    SDL_Surface* screen_surface = NULL;
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        printf( "SDL couldn't initialize! SDL Error: %s\n", SDL_GetError() );
        return -1;
    }
    window = SDL_CreateWindow( "hello sdl",
                               SDL_WINDOWPOS_UNDEFINED,
                               SDL_WINDOWPOS_UNDEFINED,
                               640, // width
                               480, // height
                               SDL_WINDOW_SHOWN );
    if ( window == NULL ) {
        printf( "Couldn't create a window! SDL Error: %s\n", SDL_GetError() );
        return -1;
    }
    screen_surface = SDL_GetWindowSurface( window );
    SDL_FillRect( screen_surface,
                  NULL,                            // R,    G,    B
                  SDL_MapRGB( screen_surface->format, 0x22, 0x11, 0x33 ) );
    SDL_UpdateWindowSurface( window );
    SDL_Delay( 2000 );
    SDL_DestroyWindow ( window );
    SDL_Quit();
    return 0;
}