⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_hello.c

📁 Linux嵌入式设计配套光盘,学习嵌入式设计可参考
💻 C
字号:
/**************************************************************************** * sdl_hello.c * * Demonstrate a minimal SDL program to display "Hello, world!". ****************************************************************************/#include "SDL.h"                /* All SDL App's need this */#include "SDL_ttf.h"            /* Truetype fonts */int main(int argc, char *argv[]) {  SDL_Surface *Screen;  SDL_Surface *helloSurface;  TTF_Font *helloFont;  SDL_Color helloColor = {128,128,255,0}; /* light blue */  SDL_Rect  helloRect  = {150,100,0,0};   /* set x,y; w,h filled in later */  SDL_Event event;  int       enableQuit;  if((SDL_Init(SDL_INIT_VIDEO)==-1)) {     fprintf(stderr, "Could not initialize SDL: %s.\n", SDL_GetError());    exit(1);  }  atexit(SDL_Quit);             /* Schedule clean up on exit. */      /* Initialize the display in a 640x480 8-bit palettized mode. */  Screen = SDL_SetVideoMode(640, 480, 8, 0);  if ( Screen == NULL ) {    fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",            SDL_GetError());    exit(1);  }  SDL_ShowCursor(SDL_DISABLE);  /* Hide the mouse cursor. */  if(TTF_Init() == -1) {    fprintf(stderr, "TTF_Init: %s\n", TTF_GetError());    exit(-1);  }  atexit(TTF_Quit);             /* Schedule clean up on exit. */  /* Open a font and create a text surface for "Hello, world!" */  helloFont = TTF_OpenFont("/usr/local/share/fonts/bitstream/VeraBI.ttf", 42);  helloSurface = TTF_RenderText_Solid(helloFont, "Hello, world!", helloColor);  /* Blit the text surface to the screen surface. This will update helloRect     with the actual blitting rectangle, thus recording helloSurface's width     and height. */  SDL_BlitSurface(helloSurface, NULL, Screen, &helloRect);  /* Update the portion of the screen containing the new text. */  SDL_UpdateRects(Screen, 1, &helloRect);  enableQuit = 0;  while(!enableQuit){    SDL_WaitEvent(&event);    switch(event.type){  /* Process the appropiate event type */      case SDL_KEYDOWN:        /* Respond to keys that are significant for the application. */        switch(event.key.keysym.sym){          case SDLK_SPACE:          case SDLK_ESCAPE:	/* make it easy to exit */          case SDLK_RETURN:            enableQuit = 1;            break;          case SDLK_s:            SDL_SaveBMP(Screen, "/tmp/Screen.bmp");            break;        }        break;    }  }  SDL_ShowCursor(SDL_ENABLE);  /* Hide the mouse cursor. */  exit(0);                      /* SDL_Quit and TTF_Quit called on exit. */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -