#include <SDL.h>
int main(int argc, char* args[])
{
// 初始化SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL 初始化失败,错误信息:%s\n", SDL_GetError());
return -1;
}
// 创建窗口
SDL_Window* window = SDL_CreateWindow("SDL2 Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
if (!window)
{
printf("窗口创建失败,错误信息:%s\n", SDL_GetError());
return -1;
}
// 创建渲染器
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer)
{
printf("渲染器创建失败,错误信息:%s\n", SDL_GetError());
return -1;
}
// 渲染颜色
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
// 清屏
SDL_RenderClear(renderer);
// 更新屏幕
SDL_RenderPresent(renderer);
// 延迟关闭
SDL_Delay(2000);
// 释放资源
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}