C ++ / SDL,一切都呈现白色

时间:2015-01-02 00:35:43

标签: c++ screen sdl sdl-2

所以这是我的代码:

#include "stdafx.h"


int main(int argc, char *argv[])
{
bool quit = false;

SDL_Init(SDL_INIT_EVERYTHING);

SDL_Window* window = NULL;

window = SDL_CreateWindow("RPG GAME", 100, 100, 600, 400, SDL_WINDOW_SHOWN );
if (window = NULL)
{
    std::cout << "Window couldn't be created" << std::endl;

    return 0;

}
SDL_Renderer* renderer = NULL;

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

SDL_Event* mainEvent = new SDL_Event();
SDL_Texture* grass_image = NULL;
grass_image = IMG_LoadTexture(renderer, "grass.bmp");
SDL_Rect grass_rect;
grass_rect.x = 10;
grass_rect.y = 50;
grass_rect.w = 250;
grass_rect.h = 250;


while (!quit && mainEvent->type != SDL_QUIT)
{
    SDL_PollEvent(mainEvent);
    SDL_RenderClear(renderer);
    //Cia darom
    SDL_RenderCopy(renderer, grass_image, NULL, &grass_rect);


    SDL_RenderPresent(renderer);

}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;

return 0;

}

每当我运行该应用程序时,窗口会弹出,但它是完全白色的,我最近设置了一个双显示器,现在在播放GIF时出现了一些问题,但我认为它没有&#39无所谓谢谢!

1 个答案:

答案 0 :(得分:1)

您需要区分'='和'=='。如在

if (window = NULL)   // bad news cause you just nuked window

if (window == NULL)  // is window null?