Sign in to follow this  
Yago

libGDX texture load problem

Recommended Posts

Yago    177

Hello, this is my first post here. At least, I think it is.

 

I'm developing a 2D game with libgdx. I have a PNG that contains the animation sheet for the player character. Naturally, it has transparency. At first, it was 8192*4096, but I needed to add bigger animations that didn't fit in 8192 pixels. So I increased the width to 16384.

 

That's when the problem started: some exception popped up in an irrevelant part of the code. I made sure that THAT part wasn't faulty, and tracked the problem to the Texture object. libgdx refuses to load that image to GPU. No exceptions or anything about this, I just have a null Texture object. The weird thing is that it DOES work if I modify the PNG to one that doesn't have transparency.

 

So if I have a PNG that's 8192 pixels wide, it works, transparent or not. But if the PNG is 16384 pixels wide, it doesn't work if it has transparent pixels. What's up with that?

Share this post


Link to post
Share on other sites
frob    44904

Modern cards support many compressed formats, but png is not one of them. Likely you have decompressed the data and pushed it to memory.

 

You are attempting to push 268 megabytes into a single texture.

 

You might have better luck with a dxt4/dxt5 compressed image.

 

It is possible to create a megatexture atlas, but it requires some work to actually implement. 

Share this post


Link to post
Share on other sites
Yago    177


You are attempting to push 268 megabytes into a single texture.

 

The PNG seems to be taking up 1,41 MB of space on my drive. Or do you mean that it goes through some sort of decompression process which results in the image being 268 MB?

 

Anyway, I installed the .dds plug-in for my CS4, but it didn't save the file as a .dds no matter what I tried. Do you know of another method instead of dxt compression?

Share this post


Link to post
Share on other sites
L. Spiro    25620


The PNG seems to be taking up 1,41 MB of space on my drive

It’s not a run-time-compressed format, so it doesn’t matter how much it takes up on your drive.  It consumes 8,192×16,384×4=512 megabytes of GPU memory.

 

I don’t know that size is the issue here though because it will consume the same amount of GPU RAM whether it is RGB or RGBA, but the layer of software that is decompressing it may be running out of memory or something during load and not telling you.

I don’t know libGDX but any library worth its weight in salt should have a way to print or retrieve error messages.

 

frob suggested DXT compression which would be another way to go, and it probably will solve your problems in the long run.

 

I happened to have written one: http://lspiroengine.com/?p=516

Run it with the command line:

lsdxt -file "C:/PATH/MyImage.png" -dxt5 -quick

 

You have a large file, so it will take time.

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Yago    177


I happened to have written one: http://lspiroengine.com/?p=516

Run it with the command line:

lsdxt -file "C:/PATH/MyImage.png" -dxt5 -quick

 

It worked with some random image I picked that was 1024*1024, but not with the 16384*4096 image that I need. The error is "Failed to open image <file>." Which leads me to think that my image might be corrupted in some way.

Share this post


Link to post
Share on other sites
Glass_Knife    8636


It worked with some random image I picked that was 1024*1024, but not with the 16384*4096 image that I need. The error is "Failed to open image ." Which leads me to think that my image might be corrupted in some way.

 

Are you sure this doesn't have anything to do with Java's heap size being too small to load the image into memory?  Try adjusting the minimum and maximum heap sizes:

 

-Xms128m -Xmx256m

 

Anytime you try to load anything in memory, such as a very large image, but you haven't allowed the max heap size to grow, you'll get weird errors.

Share this post


Link to post
Share on other sites
Yago    177


Try adjusting the minimum and maximum heap sizes:

-Xms128m -Xmx256m

 

Also tried with other values like 512|1024. Didn't have an effect.

Share this post


Link to post
Share on other sites
Yago    177


At this point, I would try just making a test main() method and try loading the image with the ImageIO class.

 

Yup, the console told me about an out of memory exception when I used ImageIO. But I still can't get the program to run. I set the heap size, it's not enough to make a difference. And Eclipse can't create VM if I increase it. Does it have to be powers of 2?

Share this post


Link to post
Share on other sites
L. Spiro    25620

Convert the image to .TGA and use it in my program again to create a .DDS.

And also try loading the .TGA directly.

Also if you send me the image I can debug it to see what caused it to fail specifically.

 

 

L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites
tisdadd    313

Quick question... why are you using a texture instead of TextureAtlas? If you are simply trying to do a sprite sheet, I recommend giving a TextureAtlas a quick try, then using the findRegion method to load in your texture regions... 

There is a nice texturepacker available... https://code.google.com/p/libgdx-texturepacker-gui/'

Very easy to use, just point it at a folder and go. Then make AtlasRegions based off of name of texture and index. May need to rotate if it was rotated... [edit:easier when starting just not to let the packer pack it rotated, but it does make smaller files...]

 

Haven't ever tried that large of a texture, but I believe this is the recommended route by libgdx.

 

Anyway, it probably is a memory issue as mentioned. As the TextureAtlas can have many textures put together but easily accessed, I recommend giving it a try really quickly.

Seems that they recently moved to gethub, so not sure where the reference I was going to give about this was.

Edited by tisdadd

Share this post


Link to post
Share on other sites
Yago    177


And also try loading the .TGA directly.

Also if you send me the image I can debug it to see what caused it to fail specifically.

 

Didn't make a difference. And I sent a message with the links to the files.

 


Quick question... why are you using a texture instead of TextureAtlas?

 

Because I didn't know about TextureAtlas before, and the player character's texture is pretty much the ONLY texture in the game at this stage. Hehe.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this