LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2019, 07:08 AM   #1
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 138

Rep: Reputation: 2
IMG_GetError() : Unsupported image format


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 format
mine 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;
}
 
Old 10-18-2019, 07:21 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,637

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by rahulvishwakarma View Post
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 format
mine 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;
}
Ok...it's telling you clearly that it can't read that file. Use a different image format for what you're trying to do, or change the name to something without spaces and try it. You've been asking about C++ programming for NINE YEARS now; after all that time you should know the basics of debugging your code.

::EDIT:: Did you read the documentation?
http://wiki.libsdl.org/SDL_CreateTexture

Last edited by TB0ne; 10-18-2019 at 07:28 AM.
 
Old 10-18-2019, 07:49 AM   #3
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 138

Original Poster
Rep: Reputation: 2
I've tried for passing images as jpg, bmp, png but all have same errors. what should i do
 
Old 10-18-2019, 08:31 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,637

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by rahulvishwakarma View Post
I've tried for passing images as jpg, bmp, png but all have same errors. what should i do
You should re-read the previous reply. Again, you were told to remove the spaces from the file name/path...did you? Did you read the documentation on how to do what you're after, because it appears as if your syntax is wrong.

Again: you've been coding for NINE YEARS; you should know how to debug your own code and read API documentation at this point.
 
Old 10-18-2019, 09:04 PM   #5
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 138

Original Poster
Rep: Reputation: 2
undefined reference to /usr/local/lib/libSDL2_ttf.so undefined reference to `SDL_RWseek

hi to all, I've centos7.5 in VM. I am trying to compile to SDL2 program. but having following problem :-
Code:
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWseek'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWclose'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWtell'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWsize'|
/usr/local/lib/libSDL2_ttf.so||undefined reference to `SDL_RWread'|
||error: ld returned 1 exit status|
mine source code is :-
Code:
#include <SDL.h>
#include <SDL/SDL_image.h>
#include <SDL_ttf.h>

#include <iostream>
#include <string>

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


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

    SDL_Texture *currentImagetexture = nullptr;
    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);
    }

    if(TTF_Init() < 0 )
    {
        cout << " Error ... TTF_Init() < 0 ) " << TTF_GetError() << endl;
        exit(4);
    }

    windowsurface = SDL_GetWindowSurface(sdlWindow);

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

    SDL_Event *ev = new SDL_Event;

    TTF_Font *font = TTF_OpenFont("Roboto-Black.ttf",20);
    SDL_Color color = {0,0,0,255};
    SDL_Surface *text_surface = TTF_RenderText_Solid(font, "rahul", color);
    SDL_Texture * text = SDL_CreateTextureFromSurface(renderer, windowsurface);

    SDL_Rect rect;
    rect.x = rect.y =0;

    SDL_QueryTexture(text, NULL, NULL,&rect.w, &rect.h);

    bool isRunning = true;

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

        }
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, text, NULL, &rect);
        SDL_RenderPresent(renderer);
    }


    SDL_FreeSurface(windowsurface);
    SDL_FreeSurface(currentImage);

    SDL_DestroyRenderer(renderer);

    SDL_DestroyTexture(currentImagetexture);
    SDL_DestroyWindow(sdlWindow);

    windowsurface = nullptr;
    currentImage = nullptr;
	sdlWindow = nullptr;
    SDL_Quit();

    return 0;
}
how to remove those errors
 
Old 10-18-2019, 11:55 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,266
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
The error indicates that you have either not told it to link the SDL libs, or have not installed the needed SDL package.

My knowledge is not current with SDL, but a quick search for the errors turns up many hits including this one which appears to be related.

In the case of linker errors, having the source code is often not particularly helpful to others trying to understand the problem. It would be more helpful if you could show the complete compiler command which produces the errors.

Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!

This thread is a continuation of your previous question about the same code. As neither thread actually asks a specific question which would distinguish them as separate issues they are being merged as duplicates.
 
1 members found this post helpful.
  


Reply

Tags
cpp, linux, sdl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenCV - Pixel format of incoming image is unsupported by OpenCV golmschenk Programming 1 04-01-2011 12:32 PM
Error 13 : Invalid or unsupported Executed Format. linuxnewbie82 Linux - Newbie 1 08-01-2006 07:19 AM
Unsupported wav format arubin Linux - Software 2 03-28-2005 02:12 AM
kernel 2.6.3 compile ends in grub error 13: unsupported executable format(?) browny_amiga Linux - General 4 03-06-2004 02:33 PM
k3b adding mp3 "Unable to handle the following files due to an unsupported format:" true_atlantis Linux - Software 3 01-31-2004 05:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration