英文:
Can't see window of SDL in c
问题
I'm just trying to test my SDL installation (I've used apt install libsdl2-dev), I've included the library and tried this code to see if it works, I even got no errors and the return of SDL_Init is successful, but I can't see any window showing up:
#include <stdio.h>
#include <SDL2/SDL.h>
int main()
{
printf("%d", SDL_Init(SDL_INIT_EVERYTHING));
}
this is the compilation flag that I'm using:
gcc -c lol.c `pkg-config sdl2 --cflags`
I've tried also this but it doesn't work too:
gcc -o program_name lol.c -std=c99 -I/usr/include/SDL2 -lSDL2main -lSDL2
<details>
<summary>英文:</summary>
I'm just trying to test my SDL installation (I've used apt install libsdl2-dev), I've included the library and tried this code to see if it works, I even got no errors and the return of SDL_Init is successful, but I can't see any window showing up :
#include <stdio.h>
#include <SDL2/SDL.h>
int main()
{
printf("%d", SDL_Init(SDL_INIT_EVERYTHING));
}
this is the compilation flag that I'm using :
gcc -c lol.c `pkg-config sdl2 --cflags`
I've tried also this but it doesn't work too :
gcc -o program_name lol.c -std=c99 -I/usr/include/SDL2 -lSDL2main -lSDL2
</details>
# 答案1
**得分**: 5
你的代码运行正常。`SDL_Init` 不会创建任何窗口或类似的东西,它只是设置了一些后台状态,以便库的其余部分能够工作。
你需要使用 `SDL_CreateWindow` 来创建一个窗口(如果需要,SDL 可以用于创建多个窗口,或者根本不创建窗口)。
<details>
<summary>英文:</summary>
Your code is working fine. `SDL_Init` doesn't create any windows or anything like that, it just sets up some background state needed for the rest of the library to work.
You need `SDL_CreateWindow` to create a window (Sdl can be used with multiple windows or no Windows at all if you like).
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论