SDL window does not show

后端 未结 4 1304
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 11:08

This is my code:

#include 
#include 

int main(int argc, const char * argv[]) {

SDL_Init(SDL_INIT_VIDEO);

SDL_Window *_wi         


        
4条回答
  •  死守一世寂寞
    2020-12-09 11:08

    You have to load a bitmap image, or display something on the window, for Xcode to start displaying the window.

    #include 
    #include 
    
    using namespace std;
    
    int main() {
        SDL_Window * window = nullptr;
    
        SDL_Surface * window_surface = nullptr;
        SDL_Surface * image_surface = nullptr;
    
        SDL_Init(SDL_INIT_VIDEO);
    
        window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
    
        window_surface = SDL_GetWindowSurface(window);
        image_surface = SDL_LoadBMP("image.bmp");
    
        SDL_BlitSurface(image_surface, NULL, window_surface, NULL);
    
        SDL_UpdateWindowSurface(window);
    
        SDL_Delay(5000);
    
        SDL_DestroyWindow(window);
        SDL_FreeSurface(image_surface);
        SDL_Quit();
    }
    

提交回复
热议问题