2 /* Simple program: Create a blank window, wait for keypress, quit.
4 Please see the SDL documentation for details on using the SDL API:
5 /Developer/Documentation/SDL/docs.html
16 int main(int argc, char *argv[])
18 Uint32 initflags = SDL_INIT_VIDEO; /* See documentation for details */
21 Uint32 videoflags = SDL_SWSURFACE;
25 /* Initialize the SDL library */
26 if ( SDL_Init(initflags) < 0 ) {
27 fprintf(stderr, "Couldn't initialize SDL: %s\n",
32 /* Set 640x480 video mode */
33 screen=SDL_SetVideoMode(640,480, video_bpp, videoflags);
35 fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
36 video_bpp, SDL_GetError());
42 SDL_Rect box = {sizeof(SDL_Rect)};
48 if (TTF_Init() == -1) {
53 TTF_Font* font = TTF_OpenFont("font.ttf", 12);
60 SDL_Color color = {sizeof(SDL_Color)};
62 SDL_Surface* ttf = TTF_RenderUTF8_Blended(font, "@", color);
63 SDL_Rect dist = {sizeof(SDL_Rect)};
70 SDL_FillRect(screen, NULL, 0xffffffff);
71 SDL_BlitSurface(ttf, NULL, screen, &dist);
72 SDL_UpdateRect(screen, 0, 0, 0, 0);
74 /* キーによって文字列の位置を移動させる。*/
75 Uint8* keys = SDL_GetKeyState(NULL);
76 if (keys[SDLK_h] == SDL_PRESSED)
80 if (keys[SDLK_j] == SDL_PRESSED)
84 if (keys[SDLK_k] == SDL_PRESSED)
88 if (keys[SDLK_l] == SDL_PRESSED)
92 if (keys[SDLK_q] == SDL_PRESSED)
97 /* Check for events */
98 if ( SDL_PollEvent(&event) ) {
100 case SDL_MOUSEMOTION:
102 case SDL_MOUSEBUTTONDOWN:
113 /* Clean up the SDL library */
114 SDL_FreeSurface(ttf);