SDL2窗口不显示

时间:2016-10-08 06:02:45

标签: c++ visual-studio sdl-2

我试图在visual studio 2015中使用SDL2打开一个窗口。我在我的代码中设置了一个.bmp图像,以便在一个窗口中显示到屏幕上,但是当我运行我的代码程序时返回0并在没有窗口的情况下关闭。 .bmp图像位于项目文件夹中。你如何显示窗口?

#include <SDL.h>
#include <iostream>

int main(int argc, char* args[])
{
    SDL_Window *window = nullptr;
    SDL_Surface *windowSurface = nullptr;
    SDL_Surface *imageSurface = nullptr;

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        std::cout << "Game Initialization error: " << SDL_GetError() << std::endl;
    {
        window = SDL_CreateWindow("Contrast Beta 0.0.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 920, SDL_WINDOW_HIDDEN | SDL_WINDOW_FULLSCREEN);
        if (window == NULL)
            std::cout << "Window Creation Failed, Error: " << SDL_GetError() << std::endl;
        else
        {
            //Window Created
            windowSurface = SDL_GetWindowSurface(window);
            imageSurface = SDL_LoadBMP("Background.bmp");

            if (imageSurface == NULL)
                std::cout << "Error loading background: " << SDL_GetError() << std::endl;
            else
            {
                SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
                SDL_UpdateWindowSurface(window);
                SDL_Delay(2000);
            }
        }
    }
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

1 个答案:

答案 0 :(得分:1)

删除SDL_WINDOW_HIDDEN;这就是全部。