windows下第一个SDL2.0程序
下载地址:http://libsdl.org/download-2.0.php
windows上下载:
把下载的include 和lib文件夹复制到自己工程下:
配置自己的工程:
这个SDL2.dll放到生成的exe相同目录中去,就可以。可以是.c或者.cpp文件都可以,代码如下
#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; }
运行结果如下:
参考:https://www.cnblogs.com/flipped/p/5552899.html