7
« on: August 19, 2011, 12:53:23 pm »
Hi,
I've just moved from SDL to SFML to make use of the awesome multiple windows capability.
My problem is that I was loading in textures using SDL before and so now want to do it with SFML. I have the following code but when the method exits I get an error saying the program has triggered a breakpoint, with one of the possible errors being that there is corruption of the heap.
When I step through the method, I can see that for some reason the sf::Image object has about 1000000 pointers to rgba values which are all ERROR and says the width of the image is about 3200000 and the height the same amount.
What has happened to sf::Image? Is what I am doing the correct way of using it?
Thanks for your time,
Poncho
Here is my code:
sf::Image myImage;
if(myImage.LoadFromFile("testimage.png")) {
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &texture );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, myImage.GetWidth(), myImage.GetHeight(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, myImage.GetPixelsPtr());
} else {
printf("ERROR: Could not load image\n");
}
EDIT: I also just tried the opengl sample code that comes in the zip of SFML and I see a spinning cube but no texture mapped to it. I've even tried creating my own texture and loading it in to be mapped to it. It seems it is doing the same this as in my program, it passes the if(image.load...) test but hasn't actually loaded anything in as nothing is initialised so the width is 3435873836 etc.
EDIT: I was just trying it again and where I get the dialog box saying "triggered a breakpoint..." I then get another dialog saying "The stack around myImage is corrupted.". Not sure if that helps.