Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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 sprites show up as white blocks  (Read 2783 times)
0 Members and 1 Guest are viewing this topic.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Posted 2013-01-14 21:24:52 »

I've been busy making a new version of my 'hyper-blazer' game; 'hyper-blazer 2' if you will. This time with lots more eye-candy Smiley

I'm using libgdx, which so far is great. Running on both desktop and android Just Works, awesome! Smiley

I'm using 2 cameras; one for 3D and one for 2D.
First I render the 3D scene using the perspective camera, which works fine.
Then I switch to the ortho camera and use SpriteBatch to draw my overlays (virtual sticks for Android in this case).

Now the problem is that the textures I want to draw just show up as white blocks.
The problem is not the textures themselves; in a simple standalone test they show up fine.

I read that SpriteBatch requires a 'clean' OpenGL state, so I disable culling, lighting etc before using the SpriteBatch, but this didn't seem to help.

Any hints?

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #1 - Posted 2013-01-14 22:05:53 »

update: it seems the problem only appears with textures with alpha. Textures without alpha show up fine...

Offline ~Spaceaholic

Senior Devvie


Medals: 3
Projects: 1



« Reply #2 - Posted 2013-01-14 22:35:06 »

1. are your textures in a base 2 dimention? with some devices if you texture is not 128x128 or 256x256 etc... then they will be rendered in all white....
2. make sure you have blending enabled.... and set the correct blending func
3. make sure you enabled texture 2d
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #3 - Posted 2013-01-14 23:03:48 »

Thanks for your response!

1. Yes, the textures are in base2 dimension. They show up fine in a small trivial test program, and I can also see these textures in the 3D scene.
2. Blending is indeed enabled. Interestingly in my small test program I didn't explicitly enable blending, yet the texture shows up fine still (and with blending).
3. Texture2D is also enabled. Textures without alpha show up fine.

I guess I'll have to check in the SpriteBatch source to see what it's actually doing. I have the feeling there is something in my OpenGL state when I use SpriteBatch that it doesn't expect, but so far I couldn't deduce what it actually is that is screwing things up.


Offline davedes
« Reply #4 - Posted 2013-01-14 23:53:01 »

Disable depth, disable alpha test, disable lighting, ensure that face culling is properly set, ensure that GL_TEXTURE0 is active, etc. Basically: check your states.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2013-01-15 00:49:48 »

it now looks like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
        Gdx.gl.glDisable(GL10.GL_ALPHA_TEST);
        Gdx.gl.glDisable(GL10.GL_DEPTH_TEST);
        Gdx.gl.glDisable(GL10.GL_LIGHTING);
        Gdx.gl.glDisable(GL10.GL_CULL_FACE);
        Gdx.gl.glEnable(GL10.GL_BLEND);
        Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
        Gdx.gl10.glActiveTexture(GL10.GL_TEXTURE0);

        sprites.setProjectionMatrix(Engine.GLOBAL.cam2D.combined);

        sprites.begin();
        sprites.draw(texStick, recStickL.x, recStickL.y);
        sprites.draw(texStick, recStickR.x, recStickR.y);
        sprites.draw(texThumb, recThumbL.x, recThumbL.y);
        sprites.end();


...still just white blocks for the textures with alpha channel (or nothing at all)...
I'm a bit stumped, but I'll check if I can get it to work without SpriteBatch and with straight openGL code.

Offline ReBirth
« Reply #6 - Posted 2013-01-15 01:55:26 »

Do you cache the texture manually, for example on Map rather depends on Atlas cache? or you use AssetManager and called dispose() rather unload()?

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #7 - Posted 2013-01-15 10:24:58 »

It turned out to be a general OpenGL issue that had nothing to do with SpriteBatch (a really stupid bug in my code in the way I binded textures), which I eventually found by putting LWJGL in debug mode.
Now all works fine Smiley

Anyway, thanks for the responses.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #8 - Posted 2013-01-15 11:40:41 »

Strangely enough it only works the first time on android (on desktop it's all fine).
When I start the game a second time without re-installing, no textures are rendered at all Huh (as if enabling textures is completely ignored; it's all just coloured blocks)
If I re-install, it looks fine again...

Offline ReBirth
« Reply #9 - Posted 2013-01-15 11:46:23 »

maybe it's the time for you to post the code.

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

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #10 - Posted 2013-01-15 12:13:55 »

Yes, well it's a bit much code to post now, so I'll first try to deduce the issue myself.
I'll post when I've got something small that has the issue and I still can't figure it out.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #11 - Posted 2013-01-15 13:11:25 »

Ok, found it.
My engine was a singleton implemented as an enum. It seems Android doesn't necessarily re-initialize this enum when the app starts, so its state was all wrong the second run. Now I initialize the engine in the resize() method and all is fine now.

Offline davedes
« Reply #12 - Posted 2013-01-15 13:59:59 »

What do you mean "reinitialize an enum"?

Offline Nate

« JGO Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #13 - Posted 2013-01-15 15:16:17 »

Probably that static blocks aren't run when Android reuses an existing VM to launch a new app.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #14 - Posted 2013-01-15 15:47:53 »

exactly that, yes
More specifically, the enum's constructor wasn't called again the second run; it was just reused, leaving the enum in the state it was when the previous run of the app was stopped.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #15 - Posted 2013-01-15 19:21:23 »

Ouch, I could see that biting me, since I also use the Holder pattern in my code for singletons.  Or maybe not, since the singleton I'm statically initializing is literally a solid white texture Grin

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #16 - Posted 2013-01-16 21:03:56 »

Yes, android has some gotchas to be aware of.
Another thing that bit me in the past is that static values can just be reset at any time, so for example a traditional singleton or a class with static values doesn't really work in Android (not reliably anyway).

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.

toopeicgaming1999 (66 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (12 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (28 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (53 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!