本文介绍了SDL2窗口不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Visual Studio 2015中使用SDL2打开一个窗口.我已经在代码中设置了一个.bmp图像,以显示在窗口中的屏幕上,但是当我运行代码时,程序返回0并关闭没有窗户. .bmp图像位于项目文件夹中.您如何显示窗口?

I'm trying to open a window with SDL2 in visual studio 2015. I've set a .bmp image in my code to display to the screen in a window, but when I run my code the program returns 0 and closes without a window. The .bmp image is in the project folder. How do you display the window?

#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;
}

推荐答案

删除SDL_WINDOW_HIDDEN;就是这样.

这篇关于SDL2窗口不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 12:54
查看更多