Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Libgdx rendering white instead of an image  (Read 3891 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Posted 2012-11-12 19:25:52 »

Hey guys.

I was just getting excited about creating a tower defence game in libgdx, and everything was going well, but then I realized my backgrounds weren't being rendered correctly on my Samsung Galaxy S2 (Android 4.0.3).
They are replaced by nothing but white (with OpenGL 2.0 it gets all black instead). I clear with black color.
The towers, which are rendered in the same way just after the background, render just fine. The stage on top of it all also renders neatly.

The weird thing is that it all works and looks perfect on desktop (see image below).

What could be causing this?

I'm using TexturePacker to pack my png's, and batch.draw() to draw them.


- Jonas
Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-11-12 19:38:43 »

The desktop environment is a lot more forgiving, especially if you have an nvidia card.  How big are your backgrounds?  One common reason for a bad texture on a phone is that it's too big.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #2 - Posted 2012-11-12 19:45:15 »

The desktop environment is a lot more forgiving, especially if you have an nvidia card.  How big are your backgrounds?  One common reason for a bad texture on a phone is that it's too big.
Really? Well, my background-texture is 2048x8192. It holds 6 different backgrounds. I thought I was being helpful to the system Sad
Well, I'll split them up, and report back.

Thanks for the tip!

- Jonas
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #3 - Posted 2012-11-12 20:22:16 »

That was the problem! All fixed!

Thanks a lot!

I would've thought I would get some kind of error if the images couldn't load, but I got nothing.

- Jonas
Offline matheus23

JGO Kernel


Medals: 107
Projects: 3


You think about my Avatar right now!


« Reply #4 - Posted 2012-11-12 22:05:57 »

2048x8192.

Woah f**k... as soon as I read that I just hardly face-palmed... my head hurts...

But yeah, even some desktop environments only support texture with sizes up to 4096*4096...

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline theagentd
« Reply #5 - Posted 2012-11-13 15:00:21 »

2048x8192.

Woah f**k... as soon as I read that I just hardly face-palmed... my head hurts...

But yeah, even some desktop environments only support texture with sizes up to 4096*4096...
OGL 4 supports up to 16k x 16k textures. Tongue

Batching the textures in your case probably won't win you anything at all. The main reason to combine smaller textures into atlases is to avoid having to bind textures between each draw call so you can batch them to improve CPU performance. For a fullscreen background, that texture bind is almost nothing compared to the GPU time it takes to actually render it, so it's definitely a premature optimization to say the least.

There is a way to check if your texture was loaded correctly but it's pretty much a simple hack. After calling glTexImage2D() and creating the texture, you can then read that texture's width or height and see if it's the correct value. If it's 0 (or was it -1?), that means it failed to load. Hacky, but it might be worth putting it into your Texture class to avoid the same problem again, especially on Android since it's only run at load time and of course almost free anyway.

Myomyomyo.
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #6 - Posted 2012-11-13 16:09:07 »

There is a way to check if your texture was loaded correctly but it's pretty much a simple hack. After calling glTexImage2D() and creating the texture, you can then read that texture's width or height and see if it's the correct value. If it's 0 (or was it -1?), that means it failed to load. Hacky, but it might be worth putting it into your Texture class to avoid the same problem again, especially on Android since it's only run at load time and of course almost free anyway.
Well, I don't think that command is available to me in libgdx, but I could do something similar with my AtlasRegions I think. I might try that out later. For now, this is working perfectly.

I've packed all my backgrounds into 2 different images now, which are combined in an atlas-file. You're saying it won't give me much of a boost, which makes sense when the images are so big. The 2 packed images use up about 200kb more space than the separated background images (probably because of the extra transparent space), so is the minimal boost enough to merit this minimal increase in bulk?

- Jonas
Offline davedes
« Reply #7 - Posted 2012-11-13 17:25:00 »

Quote
There is a way to check if your texture was loaded correctly but it's pretty much a simple hack. After calling glTexImage2D() and creating the texture, you can then read that texture's width or height and see if it's the correct value. If it's 0 (or was it -1?), that means it failed to load. Hacky, but it might be worth putting it into your Texture class to avoid the same problem again, especially on Android since it's only run at load time and of course almost free anyway.
GL_INVALID_VALUE is generated if you try to use a width/height greater than GL_MAX_TEXTURE_SIZE. I think you are thinking of GL_PROXY_TEXTURE_2D.

The idea is that GL_MAX_TEXTURE_SIZE is a rough estimate, since you may be using different format and type parameters. So you can more safely check by loading a proxy texture first; then read back the width or height values with glGetTexLevelParameter -- if zero, it means the texture will fail.

Easiest thing to do is just ensure your textures are a reasonable size, no larger than GL_MAX_TEXTURE_SIZE.

LibGDX might have a utility for this already, but if not:
1  
2  
3  
IntBuffer buf = BufferUtils.newIntBuffer(16);
Gdx.gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, buf);
int maxSize = buf.get();


Quote
I've packed all my backgrounds into 2 different images now, which are combined in an atlas-file. You're saying it won't give me much of a boost, which makes sense when the images are so big. The 2 packed images use up about 200kb more space than the separated background images (probably because of the extra transparent space), so is the minimal boost enough to merit this minimal increase in bulk?
At the expense of startup time (should be pretty speedy), you could pack your textures together on the fly. I believe LibGDX includes this in one of their TexturePacker utility classes.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (25 views)
2014-09-07 01:12:14

Longarmx (31 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (38 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!