SDL_BlitSurface不会绘制到屏幕

时间:2017-06-05 22:20:38

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

我试图简单地创建一个窗口并将图像blit到屏幕,但由于某种原因图像没有显示,屏幕仍然是白色的。我一直在使用lazyfoo的教程作为参考,以便弄清楚这一点。我在下面发布了我的所有代码,希望它足够可读。如果我被困在这一两个小时,我将不胜感激,谢谢。

#include <SDL.h>
#include <SDL_audio.h>
#include <cstdio>
#include <iostream>
#include <Windows.h>


// creates Load_surface function
SDL_Surface *loadSurface(std::string path) {
    SDL_Surface *loadedSurface = SDL_LoadBMP(path.c_str());
    if (loadedSurface == NULL) {
       printf("Unable to load image %s! SDL Error: %s\n", path.c_str(), 
         SDL_GetError());
    }
    return loadedSurface;

}



int main(int argc, char ** argv)
{


    // pointer variable for window
    SDL_Window *window;
    SDL_Surface *surface = NULL;
    SDL_Surface *media = 
         loadSurface("C:\\Users\\nickl\\Desktop\\buttonpressed.bmp");


    // initialize and test for failure
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) {

        return 1;
    }





    // create the window
    window = SDL_CreateWindow(
        "Ice Cream Boys Software",
        48,
        48,
        640,
        480,
        SDL_WINDOW_OPENGL
     );

    // safety check, see if window was created, otherwise throw an error
    if (window = NULL) {
        printf("Could not create window: %s", SDL_GetError());
        return 1;
    }
    else {
        OutputDebugString(TEXT("Surface loaded.\n"));
        surface = SDL_GetWindowSurface(window);
    }

    SDL_BlitSurface(media, NULL, surface, NULL);
    SDL_UpdateWindowSurface(window);

    /* ************************************** loop  **************************** */
    // bool to keep window open and event handler
    bool quit = false;
    SDL_Event e;





    // loop to keep window open
    while (!quit) {
         while (SDL_PollEvent(&e) != 0) {
             if (e.type == SDL_QUIT) {
                 quit = true;
            }
             else if (e.type == SDL_KEYDOWN) {
                 OutputDebugString(TEXT("My output string.\n"));


             }

         }
     }

    /* ************************************************************************** */



    // close and destroy window
    SDL_DestroyWindow(window);

    // quit
    SDL_Quit();






    return 0;
}

0 个答案:

没有答案