无法看到SDL窗口在C中

huangapple go评论108阅读模式
英文:

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&#39;m just trying to test my SDL installation (I&#39;ve used apt install libsdl2-dev), I&#39;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&#39;t see any window showing up : 

        #include &lt;stdio.h&gt;
    #include &lt;SDL2/SDL.h&gt;
    
    int main()
    {
        printf(&quot;%d&quot;, SDL_Init(SDL_INIT_EVERYTHING));
    }

this is the compilation flag that I&#39;m using :

    gcc -c lol.c `pkg-config sdl2 --cflags`
 
I&#39;ve tried also this but it doesn&#39;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&#39;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>



huangapple
  • 本文由 发表于 2023年6月19日 05:22:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定