#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <iostream>
int main(int argc, char* args[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window;
window = SDL_CreateWindow("Titlu",
100,
100,
600,
400,
SDL_WINDOW_RESIZABLE
);
SDL_Renderer* renderer = nullptr;
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
int p = 0;
SDL_Event* mainEvent = new SDL_Event();
SDL_Texture* grass_image = nullptr;
grass_image = IMG_LoadTexture(renderer,"grass.bmp");
if (grass_image == NULL)
std::cout << "FAILED";
SDL_Rect grass_rect;
grass_rect.x = 10;
grass_rect.y = 50;
grass_rect.w = 250;
grass_rect.h = 250;
while (!p && mainEvent->type != SDL_QUIT)
{
SDL_PollEvent(mainEvent);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer,grass_image,NULL,&grass_rect);
SDL_RenderPresent(renderer);
}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;
return 0;
}
grass_image = IMG_LoadTexture(渲染器,“grass.bmp”);不起作用并返回NULL,图像的路径是好的。
请告诉我,如果我做错了什么或者是否可以解决我与Windows 10或我的visual studio 2015更新3不兼容的问题 请注意,当我运行它时,我的窗口是白色而不是黑色。
答案 0 :(得分:1)
您的renderer
为空。像这样初始化它:
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);