0

I'm trying using visual studio 2019, c++, read(show) WebP image, but nothing happens. I can open, gif, jpg, png, but not WebP I'm using visual studio 2019, added sld, sdl_image, WebP, include's, libs, and dlls's. console mesage -- Failed to decode WEBP --

#include <iostream>

#include <SDL.h>
#include <SDL_image.h>

const int WIDTH = 640, HEIGHT = 360;

int main(int argc, char* argv[])
{
    SDL_Surface* imageSurface = NULL;
    SDL_Surface* windowSurface = NULL;

    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window* window = SDL_CreateWindow("Hello SDL World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);
    windowSurface = SDL_GetWindowSurface(window);

    // Check that the window was successfully created
    if (NULL == window)
    {
        // In the case that the window could not be made...
        std::cout << "Could not create window: " << SDL_GetError() << std::endl;
        return 1;
    }

    if (!(IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP))
    {
        std::cout << "Could not create window: " << IMG_GetError() << std::endl;
        return 1;
    }

    SDL_Event windowEvent;

    imageSurface = IMG_Load("logo.webp");

    if (NULL == imageSurface)
    {
        std::cout << "SDL could not load image! SDL Error: " << SDL_GetError() << std::endl;
    }

    while (true)
    {
        if (SDL_PollEvent(&windowEvent))
        {
            if (SDL_QUIT == windowEvent.type)
            {
                break;
            }
        }

        SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);

        SDL_UpdateWindowSurface(window);
    }

    SDL_FreeSurface(imageSurface);
    SDL_FreeSurface(windowSurface);

    imageSurface = NULL;
    windowSurface = NULL;

    SDL_DestroyWindow(window);
    SDL_Quit();

    return EXIT_SUCCESS;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
RFS Vieira
  • 11
  • 1
  • 1
    This error message only happens when libwebp can't decode given file. Are you sure your file is correct webp image? Could you test with another one? What are your SDL/SDL_image versions? – keltar Nov 10 '22 at 04:17
  • Thanks, for the alert, i was testing for mistake animated.webp image, and thats outher topic, as im still trying to see how to do that with SDL_image. my mistake wrong webp – RFS Vieira Nov 10 '22 at 15:33

0 Answers0