下載地址:http://libsdl.org/download-2.0.phpphp
windows上下載:html
把下載的include 和lib文件夾複製到本身工程下:windows
配置本身的工程:ui
這個SDL2.dll放到生成的exe相同目錄中去,就能夠。能夠是.c或者.cpp文件均可以,代碼以下spa
#include <SDL.h> #include <stdio.h> //屏幕的寬高常量 const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; int main(int argc, char *args[]) { //咱們要渲染的窗口 SDL_Window *window = NULL; //窗口的表面 SDL_Surface *screenSurface = NULL; //初始化SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { exit(-1); } //建立窗口 window = SDL_CreateWindow("MY FIRST SDL WINDOW", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (NULL == window) { SDL_Quit(); return -1; } //獲取窗口表面 screenSurface = SDL_GetWindowSurface(window); //表面塗上白色 SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF)); //更新表面 SDL_UpdateWindowSurface(window); //等待兩秒 SDL_Delay(2000); //銷燬窗口 SDL_DestroyWindow(window); //退出SDL子系統 SDL_Quit(); return 0; }
運行結果以下:code