SDL
Simple DirectMedia Layer - Homepage
GitHub - rubygame/ruby-sdl-ffi: Ruby-FFI binding to SDL multimedia libraries. (Still in alpha)
GitHub - jacius/nice-ffi: Nice-FFI: Convenience layer atop Ruby-FFI
これちゃんと動く。
しろま日記 : Linux - Ubuntu で初めてのSDLプログラミング
sdl_sample1.c
#include <stdlib.h> #include <SDL/SDL.h> int main(int argc, char *argv[]){ SDL_Surface *gScreenSurface; SDL_Event ev; // 初期化 if(SDL_Init(SDL_INIT_VIDEO)){ printf("初期化に失敗したっぽい\n"); return 1; } // ウィンドウのタイトルとアイコン(→キャプション)を設定 SDL_WM_SetCaption("HELLO SDL!", NULL); // ウィンドウの初期化 gScreenSurface = SDL_SetVideoMode(300,200,24,SDL_SWSURFACE); // 終了イベント待ち while(1){ SDL_PollEvent(&ev); if(ev.type == SDL_QUIT) break; } SDL_Quit(); return 0; }
コンパイルと実行。
$ gcc sdl_sample1.c -lSDL $ ./a.out
コンパイルの仕方とか。
How to compile an example SDL program written in C? - Stack Overflow
SDL2
ははあ、わかったぞ。サンプルコード。
sdl2_sample1.c
#include <stdlib.h> #include <SDL2/SDL.h> int main(int argc, char* argv[]) { SDL_Window *window; // Declare a pointer SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 // Create an application window with the following settings: window = SDL_CreateWindow( "An SDL2 window", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position 640, // width, in pixels 480, // height, in pixels SDL_WINDOW_OPENGL // flags - see below ); // Check that the window was successfully created if (window == NULL) { // In the case that the window could not be made... printf("Could not create window: %s\n", SDL_GetError()); return 1; } // The window is open: could enter program loop here (see SDL_PollEvent()) SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example // Close and destroy the window SDL_DestroyWindow(window); // Clean up SDL_Quit(); return 0; }
コンパイルと実行。
$ gcc sdl2_sample1.c -lSDL2 $ ./a.out
ちなみに SDL2 は /usr/include にあった。
sdl2_sample2.c
#include <SDL2/SDL.h> int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_VIDEO) == 0) { SDL_Window* window = NULL; SDL_Renderer* renderer = NULL; if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) == 0) { SDL_bool done = SDL_FALSE; while (!done) { SDL_Event event; SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_RenderClear(renderer); SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); SDL_RenderDrawLine(renderer, 320, 200, 300, 240); SDL_RenderDrawLine(renderer, 300, 240, 340, 240); SDL_RenderDrawLine(renderer, 340, 240, 320, 200); SDL_RenderPresent(renderer); while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { done = SDL_TRUE; } } } } if (renderer) { SDL_DestroyRenderer(renderer); } if (window) { SDL_DestroyWindow(window); } } SDL_Quit(); return 0; }
sdl2_gfx で円を描く方法。
Draw a filled circle with SDL2_gfx in C/C++ - Stack Overflow
はてなブックマーク - SDL2に関するmieki256のブックマーク
SDL2_gfx: SDL2_gfx - Graphics primitives and surface functions for SDL2