c - SDL2 编译但不打开窗口
问题描述
我正在尝试在 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;
}
}
}
然后,您可以拖动窗口。它将包含背景。
推荐阅读
- macros - 是否有任何 Lisp 允许相互递归的宏?
- javascript - 了解 ReactJS 中的嵌套与父级
- google-cloud-platform - GCP IoT 授予设备访问其他云服务的权限
- javascript - 如何匹配 URL 中的字符串并使用 JavaScript 从匹配字符串的索引中拆分 URL?
- python - 如何避免 http.server 的控制台日志记录
- sqlite - global-messages-db.sqlite 中“日期”字段的格式是什么?
- vb.net - 将字符串格式化为更小的部分并在第二个字符串之前添加空格
- ruby-on-rails - ActiveStorage AnalyzeJob 未在测试环境中运行
- java - 如何在 try-catch 块中使用 .click() 命令 java android
- python - 如何确保 Qt 表格单元格上的所有数据都是可见的?