在C中使用SDL-为什么窗口没有显示?

我编写了一个应用程序,该应用程序应该在紧密的游戏循环中渲染窗口。但是,尽管程序可以编译并正常运行,但它不会呈现在屏幕上。它仅显示在任务栏上。我有以下代码:

#include <stdio.h>
#include <stdlib.h>
#include "SDL2/SDL.h"
#include "constants.h"

int gameRunning = FALSE;
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;

int initialize_window(void){
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
        fprintf(stderr,"Error init SDL\n");
        return FALSE;
    };
    window = SDL_CreateWindow(
            NULL,SDL_WINDOWPOS_CENTERED,800,600,SDL_WINDOW_BORDERLESS
    );
    if (!window){
        fprintf(stderr,"Error\n");
        return FALSE;
    }
    // -1 is the default for all drivers
    renderer = SDL_CreateRenderer(window,-1,0);
    if (!renderer){
        fprintf(stderr,"Error\n");
        return FALSE;
    }

    return TRUE;
}

void process_input(){
    SDL_Event event;
    SDL_PollEvent(&event);

    switch (event.type){
        case SDL_QUIT:
            gameRunning = FALSE;
            break;
        case SDL_KEYDOWN:
            if (event.key.keysym.sym == SDLK_ESCAPE){
                gameRunning = FALSE;
            }
            break;
    }
}

void update(){

}

void render(){

}

void setup(){

}

void destroy_window(){
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
}

int main(int argc,char *argv[]) {
    gameRunning = initialize_window();

    setup();

    while (gameRunning){
        process_input();
        update();
        render();
    } 

    destroy_window();

    return (EXIT_SUCCESS);
}

代码本身可以很好地编译,但是我只能在任务栏中得到它:

在C中使用SDL-为什么窗口没有显示?

我看到有人在Linux中使用相同的代码,并且屏幕确实呈现出来。我使用的不是Cygwin,我使用的是MinGW(不确定POSIX标准是否可以与Linux相比发挥作用)。

基本上,我只是问我的代码是否错误?该窗口将不会显示在屏幕上。不幸的是,这是更难的一种,因为没有错误消息要显示。

iCMS 回答:在C中使用SDL-为什么窗口没有显示?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2292131.html

大家都在问