欢迎来到 SDL2 !这是 SDL2 跨平台多媒体开发库。检查 SDL2官网 了解更多信息。

如果在使用 SDL2 时遇到任何问题,可以在中找到答案:

SDL团队 GitHub

(Longan官方群 | C/C++语言革命)QQ群:780414678

(C/C++游戏开发)QQ群:307191262

快速入门

使用 SDL2 跨平台多媒体开发库

SDL2 学习(1): 第一个程序

#include <SDL2/SDL.h>

int main(int argc, char *argv[]) {
SDL_Window *Window = NULL;
SDL_Renderer *Renderer = NULL;

SDL_Init(SDL_INIT_VIDEO);

Window = SDL_CreateWindow(
"hello,word",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800,
600,
SDL_WINDOW_RESIZABLE
);

Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);

SDL_Event event;
bool quit = false;

while (!quit) {
if (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
SDL_SetRenderDrawColor(Renderer, 0,180,180,255);
SDL_RenderClear(Renderer);
SDL_RenderPresent(Renderer);
}
SDL_DestroyRenderer(Renderer);
SDL_DestroyWindow(Window);
SDL_Quit();
return 0;
}

更多信息: 第一个程序

SDL2 学习(2): 显示图片

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

int main(int argc, char *argv[]) {
SDL_Window *Window = NULL;
SDL_Renderer *Renderer = NULL;

SDL_Init(SDL_INIT_VIDEO);

SDL_Surface *Image = IMG_Load("images/car.png");

Window = SDL_CreateWindow(
"hello,word",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800,
600,
SDL_WINDOW_RESIZABLE
);

Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

SDL_Texture * Texture = SDL_CreateTextureFromSurface(Renderer, Image);
SDL_FreeSurface(Image);

SDL_Rect SpriteRect = {0, 0, 64, 32};

SDL_Event event;
bool quit = false;

while (!quit) {
if (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
SDL_SetRenderDrawColor(Renderer, 0, 180, 180, 255);
SDL_RenderClear(Renderer);

SDL_RenderCopy(Renderer, Texture, NULL, &SpriteRect);

SDL_RenderPresent(Renderer);
}

SDL_DestroyTexture(Texture);
SDL_DestroyRenderer(Renderer);
SDL_DestroyWindow(Window);
IMG_Quit();
SDL_Quit();
return 0;
}

更多信息: 显示图片

SDL2 学习(3):

// 等会,豆焰正在写教程

更多信息: 学习

SDL2 学习(4):

// 等会,豆焰正在写教程

更多信息: 学习