SDL2 编译但打不开 window
SDL2 compiles but doen't open window
我正在尝试在 Mac 上的 Eclipse 上设置一个 SDL2 项目。
我试过下面的代码,没有报错。但是,window 没有打开,而是打开了一个 "ghost" 程序的图标。
"ghost" 程序:
#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;
}
}
}
然后您可以拖动 window。它将包含背景。
我正在尝试在 Mac 上的 Eclipse 上设置一个 SDL2 项目。
我试过下面的代码,没有报错。但是,window 没有打开,而是打开了一个 "ghost" 程序的图标。
"ghost" 程序:
#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;
}
}
}
然后您可以拖动 window。它将包含背景。