gpt4 book ai didi

c++ - Windows 10 中的 SDL2 图像加载

转载 作者:行者123 更新时间:2023-11-30 05:22:15 24 4
gpt4 key购买 nike

#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(renderer,"grass.bmp");不起作用并返回 NULL 图像的路径是好的。

请告诉我我是否做错了什么,或者是否可以修复与我的 Windows 10 或我的 visual studio 2015 update 3 不兼容的问题请注意,当我运行它时,我的窗口是白色的而不是黑色的。

最佳答案

您的渲染器 为 NULL。像这样初始化它:

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

关于c++ - Windows 10 中的 SDL2 图像加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39729883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com