SDL
SDLのバイナリパッケージをcygwinにインストールする
cygwinのsetup.exeを実行後、ダウンロード元のサイトに
http://cefiro.homelinux.org/resources/files/
を指定して、SDLのパッケージを追加する
makefileの書き方
all: gcc -I/usr/local/mingw32/include/SDL -L/usr/local/mingw32/include/SDL \ -o base base.c \ -lmingw32 -lSDLmain -lSDL -mwindows -mno-cygwin # objdump -p base.exe | grep dll
何もしないウインドウの表示
#include "SDL.h" int main(int argc,char *argv[]) { SDL_Surface *screen; SDL_Event e; int done = 0; if (SDL_Init(SDL_INIT_VIDEO) < 0) exit(1); screen = SDL_SetVideoMode(200, 200, 8, SDL_HWSURFACE); if(screen == NULL){ SDL_Quit(); exit(2); } do{ if (SDL_PollEvent(&e) != 0){ switch(e.type){ case SDL_QUIT: done = 1; break; } } }while(!done); SDL_Quit(); return 0; }
箱を描く
SDL_Rect dest={0,0,100,100}; Uint32 color; color = SDL_MapRGB(screen->format, 0, 0, 255); SDL_FillRect(screen, &dest, color); SDL_UpdateRect(screen, 0, 0, 0, 0);
キー入力取得
while(SDL_PollEvent(&event)) { switch(event.type){ case SDL_KEYDOWN: printf( "%s\n", SDL_GetKeyName(event.key.keysym.sym)); break; } }
bitmap読み込み・表示
// 読み込み SDL_Surface *image; image = SDL_LoadBMP(file_name); if (image == NULL) { // エラー return; } // 表示 SDL_BlitSurface(image, NULL, screen, NULL); // 画面更新 SDL_UpdateRect(screen, 0, 0, image->w, image->h); // ビットマップ開放 SDL_FreeSurface(image);