程式語言 - Simple DirectMedia Layer (SDL) - v1.2 - C/C++ - Hello, world!



參考資訊:
https://www.libsdl.org/release/SDL-1.2.15/docs/html/index.html

main.c

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_gfxPrimitives.h>

int main(int argc, char **argv)
{
    SDL_Surface *screen = NULL;

    SDL_Init(SDL_INIT_VIDEO);
    screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE);

    stringRGBA(screen, 100, 100, "hello, world!", 0xff, 0xff, 0xff, 0xff);
    SDL_Flip(screen);
    SDL_Delay(3000);

    SDL_Quit();
    return 0;
}

Line 10 初始化需要的元件,如:顯示、聲音等
Line 11 設定螢幕解析度為320x240且顏色為16Bit,使用的Buffer優先從Video硬體配置
Line 13 顯示訊息,位置在x:100, y:100
Line 14 更新Video Buffer(傳遞給底層顯示驅動程式)
Line 15 延遲3秒
Line 17 釋放資源,假如沒有設定SDL_INIT_NOPARACHUTE,則SDL會自動做資源回收動作

編譯、執行

$ gcc main.c -o main -lSDL -lSDL_gfx -I/usr/include/SDL
$ ./main