SDL2窗口未打开

时间:2016-10-08 06:17:16

标签: 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;
}

0 个答案:

没有答案