Author Topic: Strange texture rendering.  (Read 1073 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Strange texture rendering.
« 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:


scene 2:


scene 1:


at last:

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Strange texture rendering.
« Reply #1 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.
« Last Edit: March 27, 2013, 11:17:13 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Strange texture rendering.
« Reply #2 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Strange texture rendering.
« Reply #3 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Strange texture rendering.
« Reply #4 on: March 27, 2013, 01:05:49 pm »
...and please set Logger to debug mode and post the log output.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Strange texture rendering.
« Reply #5 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);


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Strange texture rendering.
« Reply #6 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.