Hiện tại tôi đang học SDL 2.0 và tôi đã thấy phương pháp này để tải BMP:
SDL_Texture* LoadImage(std::string file)
{
    SDL_Surface *loadedImage = nullptr;
    SDL_Texture *texture = nullptr;
    loadedImage = SDL_LoadBMP(file.c_str());
    if (loadedImage != nullptr)
    {
        texture = SDL_CreateTextureFromSurface(renderer, loadedImage);
        SDL_FreeSurface(loadedImage);
    } 
    else
        std::cout << SDL_GetError() << std::endl;
        return texture;
}
Làm cách nào tôi có thể chuyển nó lên để tải các tệp PNG?
EDIT: Rất tiếc, quên thêm phương pháp tải PNG của tôi.
SDL_Texture* grass_image = nullptr;
grass_image = IMG_LoadTexture(renderer, "res/grass.bmp");
SDL_Rect grass_rect;
    grass_rect.x = 0;
    grass_rect.y = 0;
    grass_rect.w = SCREEN_WIDTH;
    grass_rect.h = SCREEN_HEIGHT;
if (grass_image == NULL)
    std::cout << "Couldn't load grass_image" << std::endl;
while (!quit && mainEvent -> type != SDL_Quit)
{
    SDL_RenderCopy(renderer, grass_image, NULL, &grass_rect);
}
Tôi chỉ không muốn phải làm điều đó cho MỌI hình ảnh. Vì vậy, làm thế nào tôi có thể đặt nó vào một chức năng?
Cảm ơn!
