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.


libGDX texture load problem


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
11 replies to this topic

#1 Yago   Members   -  Reputation: 162

Like
0Likes
Like

Posted 19 September 2013 - 05:37 PM

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?



Sponsor:

#2 frob   Moderators   -  Reputation: 22683

Like
0Likes
Like

Posted 19 September 2013 - 05:53 PM

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. 


Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 Yago   Members   -  Reputation: 162

Like
0Likes
Like

Posted 19 September 2013 - 06:38 PM


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?



#4 L. Spiro   Crossbones+   -  Reputation: 14196

Like
0Likes
Like

Posted 19 September 2013 - 09:16 PM


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


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

#5 Yago   Members   -  Reputation: 162

Like
0Likes
Like

Posted 20 September 2013 - 09:06 AM


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.



#6 Glass_Knife   Moderators   -  Reputation: 4980

Like
0Likes
Like

Posted 20 September 2013 - 09:37 AM


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.


I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#7 Yago   Members   -  Reputation: 162

Like
0Likes
Like

Posted 20 September 2013 - 11:19 AM


Try adjusting the minimum and maximum heap sizes:

-Xms128m -Xmx256m

 

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



#8 Glass_Knife   Moderators   -  Reputation: 4980

Like
0Likes
Like

Posted 20 September 2013 - 02:56 PM

At this point, I would try just making a test main() method and try loading the image with the ImageIO class.  See if that either works or throws an error that will point you to the right direction.

 

http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read(java.io.InputStream)


I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#9 Yago   Members   -  Reputation: 162

Like
0Likes
Like

Posted 20 September 2013 - 03:27 PM


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?



#10 L. Spiro   Crossbones+   -  Reputation: 14196

Like
0Likes
Like

Posted 20 September 2013 - 07:18 PM

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, 20 September 2013 - 07:19 PM.

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

#11 tisdadd   Members   -  Reputation: 313

Like
0Likes
Like

Posted 20 September 2013 - 09:09 PM

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, 20 September 2013 - 09:10 PM.


#12 Yago   Members   -  Reputation: 162

Like
0Likes
Like

Posted 21 September 2013 - 07:37 AM


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.






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