首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SDL窗口根本不显示

SDL窗口根本不显示
EN

Stack Overflow用户
提问于 2016-06-16 08:41:12
回答 1查看 4.2K关注 0票数 3

我现在正在学习SDL,已经下载了库,并用MinGW将它们添加到我的链接器中,等等,我正在尝试运行一个简单的演示程序来显示一个窗口,但它根本不会显示。我没有得到任何错误,窗口就是不显示。

代码语言:javascript
复制
#include "SDL.h"
#include <stdio.h>

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

SDL_Window *window;                    // Declare a pointer

SDL_Init(SDL_INIT_VIDEO);              // Initialize SDL2

// Create an application window with the following settings:
window = SDL_CreateWindow(
    "An SDL2 window",                  // window title
    SDL_WINDOWPOS_UNDEFINED,           // initial x position
    SDL_WINDOWPOS_UNDEFINED,           // initial y position
    640,                               // width, in pixels
    480,                               // height, in pixels
    SDL_WINDOW_OPENGL                  // flags - see below
);

// Check that the window was successfully created
if (window == NULL) {
    // In the case that the window could not be made...
    printf("Could not create window: %s\n", SDL_GetError());
    return 1;
}

// The window is open: could enter program loop here (see SDL_PollEvent())

SDL_Delay(3000);  // Pause execution for 3000 milliseconds, for example

// Close and destroy the window
SDL_DestroyWindow(window);

// Clean up
SDL_Quit();
return 0;

}

EN

回答 1

Stack Overflow用户

发布于 2016-06-20 00:01:50

我刚刚在Linux和MinGW上进行了测试。在窗口有机会显示之前,可能是SDL_Delay阻塞的问题。尝试添加一个基本的主循环,看看它是否工作。这将创建一个空窗口。

代码语言:javascript
复制
#include "SDL.h"
#include <stdio.h>

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

SDL_Window *window;                    // Declare a pointer

SDL_Init(SDL_INIT_VIDEO);              // Initialize SDL2

// Create an application window with the following settings:
window = SDL_CreateWindow(
    "An SDL2 window",                  // window title
    SDL_WINDOWPOS_UNDEFINED,           // initial x position
    SDL_WINDOWPOS_UNDEFINED,           // initial y position
    640,                               // width, in pixels
    480,                               // height, in pixels
    SDL_WINDOW_OPENGL                  // flags - see below
);

// Check that the window was successfully created
if (window == NULL) {
    // In the case that the window could not be made...
    printf("Could not create window: %s\n", SDL_GetError());
    return 1;
}

// A basic main loop to prevent blocking
bool is_running = true;
SDL_Event event;
while (is_running) {
    while (SDL_PollEvent(&event)) {
        if (event.type == SDL_QUIT) {
            is_running = false;
        }
    }
    SDL_Delay(16);
}

// Close and destroy the window
SDL_DestroyWindow(window);

// Clean up
SDL_Quit();
return 0;

}
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37848065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档