簡體   English   中英

SDL2 編譯但不打開窗口

[英]SDL2 compiles but doen't open window

我正在嘗試在 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;
}

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;
        }
    }
 }

然后,您可以四處拖動窗口。 它將包含背景。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM