SDL窗口不显示

编程入门 行业动态 更新时间:2024-10-22 04:46:52
本文介绍了SDL窗口不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码:

#include <iostream> #include <SDL2/SDL.h> int main(int argc, const char * argv[]) { SDL_Init(SDL_INIT_VIDEO); SDL_Window *_window; _window = SDL_CreateWindow("Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 700, 500, SDL_WINDOW_RESIZABLE); SDL_Delay(20000); SDL_DestroyWindow(_window); SDL_Quit(); return 0; }

我已经下载了SDL2并将库导入到项目构建阶段。我测试了SDL2工作正常。

Im working in Xcode. I've downloaded SDL2 and imported the library to the projects build phases. I've tested that the SDL2 works correctly.

问题是窗口从不显示。我只是得到一个spin-mac-wheel,然后程序退出延迟后。

The problem is that window never shows up. I just get a "spinning-mac-wheel" and then the program quits after the delay. I've made sure that the window is not hidden behind somewhere.

想法?

推荐答案

您必须加载位图图像或在窗口上显示某些内容,以便Xcode开始显示窗口。

You have to load a bitmap image, or display something on the window, for Xcode to start displaying the window.

#include <SDL2/SDL.h> #include <iostream> using namespace std; int main() { SDL_Window * window = nullptr; SDL_Surface * window_surface = nullptr; SDL_Surface * image_surface = nullptr; SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN); window_surface = SDL_GetWindowSurface(window); image_surface = SDL_LoadBMP("image.bmp"); SDL_BlitSurface(image_surface, NULL, window_surface, NULL); SDL_UpdateWindowSurface(window); SDL_Delay(5000); SDL_DestroyWindow(window); SDL_FreeSurface(image_surface); SDL_Quit(); }

更多推荐

SDL窗口不显示

本文发布于:2023-07-18 12:52:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1144969.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   SDL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!