Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Problem loading a particular .png file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Monkey_Missile   Members   -  Reputation: 104

Like
0Likes
Like

Posted 15 April 2013 - 02:18 PM

I've been using SDL with openGL to create a project and for some reason using IMG_Load followed by SDL_DisplayFormatAlpha causes a crash only when I use the attached file. I'm doing this in Code::Blocks so I'm not sure if the file is just too big or what. Any guesses as to what might be doing this and how to resolve it?

 

background.png



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8147

Like
0Likes
Like

Posted 15 April 2013 - 04:39 PM

What kind of GPU have you?


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 L. Spiro   Crossbones+   -  Reputation: 14027

Like
0Likes
Like

Posted 15 April 2013 - 05:34 PM

Never used SDL but that sounds like a loading bug, possibly a buffer overflow that doesn’t get caught until later.

A stack trace and any reported errors would be helpful.

 

Things to try in the meantime:

#1: Check the format of the .PNG (bits per pixel) and save it as 32 bits per pixel if it is not already.

#2: Modify the image to see which part of it is related to the crash.

#3: Save it as a .BMP or .TGA and see if it still happens.

 

These of course are only running away from the problem but would at least give you some idea as to where it could be.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 mhagain   Crossbones+   -  Reputation: 8147

Like
2Likes
Like

Posted 15 April 2013 - 05:48 PM

My thought is - because it's a 1024x800 image - the OP may have an older GPU that doesn't support non-power-of-two textures.  Now, OpenGL shouldn't cause a crash on an attempt to load that (error behaviour being well-specified) but that assumes a conformant (and non-buggy) driver, and we all know how many of those exist (hint: none).

 

Of course, we do need more info from the OP to diagnose this properly.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 Monkey_Missile   Members   -  Reputation: 104

Like
0Likes
Like

Posted 15 April 2013 - 08:44 PM

I'm using an NVIDIA GeForce GTX560 Ti. I've changed the image to a 1024x1024 and still no dice plus other non-power-of-two images still work. Changing it to a .bmp works but only if 32 bit. 16 and 24 bit still crash. Also .png files from what I gather can only be 8 bit but that can't be it since the other smaller 48x48 texture which is a .png works fine.

 

I was hoping to avoid .bmp files due to their size so I'll still try fixing this before doing that. If this is a problem in the beginning where openGL is being initialized then I'm not sure where to look. The code from the init is as follows:

 

    //Initialize SDL
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0){
        return false;
    }

    //Set OpenGL memory usage
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    //Set window caption
    SDL_WM_SetCaption("Test", NULL);

    //Size of the window
    if(SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_OPENGL) == NULL){
        return false;
    }

    //Specify the clear color and what portion of the screen will display
    glClearColor(0,0,0,1);
    glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);

    //Shader model
    glShadeModel(GL_SMOOTH);

    //2D rendering
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    //Depth testing only used with 3D rendering
    glDisable(GL_DEPTH_TEST);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


#6 Sik_the_hedgehog   Crossbones+   -  Reputation: 1817

Like
0Likes
Like

Posted 15 April 2013 - 11:04 PM

How are you loading the PNG? Also, are you making sure the PNG is being converted to 32-bit RGBA? If you're using libpng directly and you're using the "high level" loading functions, you can pass some flags to get it to convert to that format for you.

 

What format is this PNG, by the way?

 

PS: PNG supports a ton of formats (between paletted, grayscale and RGB along with alpha or not alpha and 8-bit or 16-bit components - or even 4-bit in one case). Be careful. Luckily you can still turn it into 32-bit RGBA only so don't bother much about that if you tell libpng to convert it on its own.


Edited by Sik_the_hedgehog, 15 April 2013 - 11:04 PM.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#7 Monkey_Missile   Members   -  Reputation: 104

Like
0Likes
Like

Posted 19 April 2013 - 07:47 PM

Ugh sorry about the delay there. Here's the image load function, which part would allow me to convert the format?

 

GLuint mainApp::OnLoad(const std::string &fileName){
    SDL_Surface *image = IMG_Load(fileName.c_str());

    SDL_DisplayFormatAlpha(image);
    unsigned object(0);

    glGenTextures(1, &object);
    glBindTexture(GL_TEXTURE_2D, object);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);

    SDL_FreeSurface(image);
    return object;
}


#8 Sponji   Members   -  Reputation: 1313

Like
0Likes
Like

Posted 20 April 2013 - 02:31 AM

Your image doesn't have alpha and you're using it as it would have it.

 

GLenum format;

if(image->format->BytesPerPixel == 3) format = GL_RGB;
else if(image->format->BytesPerPixel == 4) format = GL_RGBA;

glTexImage2D(GL_TEXTURE_2D, 0, format, image->w, image->h, 0, format, GL_UNSIGNED_BYTE, image->pixels); 

 

The SDL_Surface's format could be something else too, like BGR, but this is just an example. Google for SDL_Surface's manual and glTexImage2D and you should find some good information about the formats.

Derp

#9 Monkey_Missile   Members   -  Reputation: 104

Like
0Likes
Like

Posted 24 April 2013 - 04:53 PM

Great feedback! Thanks I will use this.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS