Article 4SSXP IMG_GetError() : Unsupported image format

IMG_GetError() : Unsupported image format

by
rahulvishwakarma
from LinuxQuestions.org on (#4SSXP)
hi to all, UI've centos 7.5 in VM for SDL2 programming. while this error is in "IMG_Load(filepath.c_str());" error is following
Code:[rahul@centos75client Release]$ ./diffrent\ iamge\ formats
file path = /opt/projects/codeblocks/sdl/diffrent iamge formats/1.bmp window surface = 0
Error in windowSurface == nullptr : Unsupported image formatmine cpp file is :-
Code:#include <SDL.h>
#include <SDL/SDL_image.h>

#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;

SDL_Texture *OptimizeTexture(std::string filepath, SDL_Renderer *windowRenderer)
{
SDL_Texture * texture = nullptr;

SDL_Surface * windowSurface = IMG_Load(filepath.c_str());
cout << " file path = " << filepath.c_str() << " window surface = "<< windowSurface<<endl;

if( windowSurface == nullptr)
{
cout << "Error in windowSurface == nullptr : " << IMG_GetError() << endl;
exit(4);
}

texture = SDL_CreateTextureFromSurface(windowRenderer,windowSurface);

if(texture == nullptr)
{
cout << " Error : in SDL_CreateTextureFromSurface(windowRenderer,windowSurface); ... " << SDL_GetError() << endl;
exit(5);
}

return texture;

}

int main(int argc, char ** argv)
{

SDL_Surface * currentImage = nullptr;
SDL_Renderer *renderer = nullptr;
SDL_Window * sdlWindow = nullptr;
SDL_Surface *windowsurface = SDL_GetWindowSurface(sdlWindow);

if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
std ::cout <<"Error in ... if(SDL_Init(SDL_INIT_EVERYTHING) <0) : " << SDL_GetError() << endl;
}

if((sdlWindow = SDL_CreateWindow("Game engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,1024, 768, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL)) < 0)
{
std ::cout <<"Error in ... sdlWindow = SDL_CreateWindow : "<< SDL_GetError() << endl;
exit(2);
}

int imgFlags = IMG_INIT_JPG | IMG_INIT_PNG;

if(!((IMG_Init(imgFlags)) & imgFlags))
{
cout << "Error in ... if(!(IMG_Init(imgFlags)&imgFlags)) : " << IMG_GetError() << endl;
exit(3);
}

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

currentImagetexture = OptimizeTexture("/opt/projects/codeblocks/sdl/diffrent image formats/1.bmp", renderer);

SDL_Event *ev = new SDL_Event;

bool isRunning = true;

while(isRunning)
{
while (SDL_PollEvent(ev))
{
if(ev->type == SDL_QUIT)
{
isRunning = false;
}

}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, currentImagetexture, NULL, NULL);
SDL_RenderPresent(renderer);
}

SDL_FreeSurface(windowsurface);
windowsurface = nullptr;
currentImage = nullptr;

SDL_DestroyWindow(sdlWindow);
sdlWindow = nullptr;
SDL_Quit();

return 0;
}latest?d=yIl2AUoC8zA latest?i=dVIp7_SUNwA:h-rXCmQdms8:F7zBnMy latest?i=dVIp7_SUNwA:h-rXCmQdms8:V_sGLiP latest?d=qj6IDK7rITs latest?i=dVIp7_SUNwA:h-rXCmQdms8:gIN9vFwdVIp7_SUNwA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments