2016-10-08 165 views
-1

我試圖在visual studio 2015中打開一個帶有SDL2的窗口。我在代碼中設置了一個.bmp圖像以顯示到窗口中的屏幕,但是當我運行我的代碼時,程序返回0並在沒有窗口的情況下關閉。 .bmp圖像位於項目文件夾中。你如何顯示窗口?SDL2窗口不顯示

#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

刪除SDL_WINDOW_HIDDEN;就這樣。