- yum install SDL
- 安装的是SDL2
- include的文件也是SDL2
- yum install xclock
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(void)
{
SDL_Window *window = NULL;
SDL_Surface *surface = NULL;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL无法初始化 %s",SDL_GetError());
return -1;
}
window = SDL_CreateWindow("SDL Demo",
SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,//这两个是窗口的位置 x y(不在乎)
SCREEN_WIDTH,SCREEN_HEIGHT,//窗口的宽度和高度
SDL_WINDOW_SHOWN //确保在创建窗口时显示该窗口
);
if (window == NULL) {
printf("创建window失败");
return -1;
}
//接下来是获取窗口的屏幕 这样才能绘制
surface = SDL_GetWindowSurface(window);
if (surface == NULL) {
printf("获取屏幕失败");
return -1;
}
//填充为红色
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0xff, 0x00, 0x00));
//更新窗口操作
SDL_UpdateWindowSurface(window);
//等待2秒
SDL_Delay(5 * 1000);
//销毁资源退出
SDL_DestroyWindow(window);
return 0;
}
标签:return,SCREEN,surface,window,使用,SDL,NULL,安装
From: https://www.cnblogs.com/starcos/p/16909432.html