Strange texture rendering.

Started by kiffa, March 27, 2013, 10:33:24 AM

Previous topic - Next topic

kiffa

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:


scene 2:


scene 1:


at last:

kiffa

#1
Any hint?

My codes:


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.

EgonOlsen

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.

EgonOlsen

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?

EgonOlsen

...and please set Logger to debug mode and post the log output.

kiffa

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);


EgonOlsen

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.