www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: kiffa on March 27, 2013, 10:33:24 am

Title: Strange texture rendering.
Post by: kiffa on March 27, 2013, 10:33:24 am
My game have a car and 2 scenes, i keep the car-Object3D in memory permanently, and unload the texture when scene changing, the problem is:

1, In scene 1, all are fine, then change to scene2, unload the texture.
2, In scene 2, reload the car-texture(which is the same as scene 1), reassign it to the car.
3, The car seems rendering with another texture. For example, there are other objects in my scene, road\sky\building\tree..., the car seems rendering with the texture of the road.
4, Chang to scene 1 again, unload\reload\reassign, the car seems rendering with the texture of the tree.
5, Chang to scene 2 again, the car seems rendering with the texture of the tree(of scene 2, which is different from the tree of scene 1).
6, Repeat changing scenes, at last, the car will be black and doesn't change any more.

scene 1:
(http://p13.freep.cn/p.aspx?u=v20_p13_photo_1303271731289505_0.jpg)

scene 2:
(http://p13.freep.cn/p.aspx?u=v20_p13_photo_1303271732197195_0.jpg)

scene 1:
(http://p13.freep.cn/p.aspx?u=v20_p13_photo_1303271732439877_0.jpg)

at last:
(http://p13.freep.cn/p.aspx?u=v20_p13_photo_1303271733108458_0.jpg)
Title: Re: Strange texture rendering.
Post by: kiffa on March 27, 2013, 10:53:31 am
Any hint?

My codes:

Code: [Select]
Texture.defaultToKeepPixels(false);
Config.unloadImmediately = true;

// when changing the scene:
// destroy current scene
TextureManager tm = TextureManager.getInstance();
tm.unloadTexture(framebuffer, tm.getTexture(textureName));
tm.replaceTexture(textureName, tm.getDummyTexture());

// entry new scene:
Texture texture = new Texture(in, alpha);
tm.replaceTexture(textureName, texture);
car.setTexture(textureName);

// and i printed the texture id, the texture of the car remains the same.

// and if i do this:
car.setTexture("car");
road.setTexture("car");
// the road will rendering right(with the car texture), but the car is incorrect.


// and if i remove the car-obj, and reload in new scene, all are fine.
Title: Re: Strange texture rendering.
Post by: EgonOlsen on March 27, 2013, 12:19:27 pm
Might be caused by the fact that you actually assign one texture (the dummy) to two different entries in the manager. This isn't supposed to happen and it might cause confusion in the manager. It should work though, i'll look into it. However, in this case, it's not needed. Just remove the call to tm.replaceTexture(textureName, tm.getDummyTexture()); and see if that helps.
Title: Re: Strange texture rendering.
Post by: EgonOlsen on March 27, 2013, 01:02:55 pm
Looking at in more detail, i don't see a reason why this should happen. Can you provide a test case that shows this problem?
Title: Re: Strange texture rendering.
Post by: EgonOlsen on March 27, 2013, 01:05:49 pm
...and please set Logger to debug mode and post the log output.
Title: Re: Strange texture rendering.
Post by: kiffa on March 27, 2013, 01:40:00 pm
I have found the reason:

// if i add this, then the strange texture rendering will happen, if i remove it, all are fine.
car.setEnvmapped(true);

Title: Re: Strange texture rendering.
Post by: EgonOlsen on March 27, 2013, 07:22:39 pm
Well, i don't see why or how this method should have an effect on the texture used but it's not really supported in jPCT-AE anyway and even if it where, calling it makes no sense at all in this context. So if removing that call fixes the problem, all is fine.