【问题标题】:SDL2 compiles but doen't open windowSDL2 编译但不打开窗口
【发布时间】:2020-03-21 02:41:03
【问题描述】:

我正在尝试在 Mac 上的 Eclipse 上设置 SDL2 项目。

我尝试了以下代码,但没有报告任何错误。但是,窗口并没有打开,而是打开了一个“幽灵”程序的图标。

“幽灵”计划:

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

int main(int argc, char** argv)
{
    if (SDL_Init(SDL_INIT_VIDEO) != 0 )
    {
        fprintf(stdout,"Failed to initialize the SDL (%s)\n",SDL_GetError());
        return -1;
    }

    {
        SDL_Window* pWindow = NULL;
        pWindow = SDL_CreateWindow("My first SDL2 application",SDL_WINDOWPOS_UNDEFINED,
                                                                  SDL_WINDOWPOS_UNDEFINED,
                                                                  640,
                                                                  480,
                                                                  SDL_WINDOW_SHOWN);

        if( pWindow )
        {
            SDL_Delay(3000);

            SDL_DestroyWindow(pWindow);
        }
        else
        {
            fprintf(stderr,"Error creating the window: %s\n",SDL_GetError());
        }
    }

    SDL_Quit();

    return 0;
}

【问题讨论】:

    标签: c eclipse macos sdl-2


    【解决方案1】:

    SDL 覆盖 main,但它希望 main 被声明为

    int main(int argc, char* argv[])
    

    如果将其声明为 char** 而不是 char* argv[],则模板将不会被拾取。

    延迟不会有太大影响:您将得到的只是一个标题和一个框架。将 SDL_Delay 更改为这样的事件处理程序

    bool running = true;
    while (running)
    {
        SDL_Event e;
        while (SDL_PollEvent(&e) != 0)
        {
            if (e.type == SDL_QUIT)
            {
                running = false;
                break;
            }
        }
     }
    

    然后您可以拖动窗口。它将包含背景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2019-05-31
      • 1970-01-01
      • 1970-01-01
      • 2022-01-27
      • 1970-01-01
      相关资源
      最近更新 更多