Author Topic: Changing texture of an object create with addTriangle  (Read 1147 times)

Offline Enerccio

  • byte
  • *
  • Posts: 3
    • View Profile
Changing texture of an object create with addTriangle
« on: October 06, 2011, 12:32:25 am »
Hello, I have Object3D created via addTriangle methods and I assign a texture to it:

Code: [Select]
public class PlaneObject extends Object3D {
private static final long serialVersionUID = 156115212L;
private int textureId;

public PlaneObject(float sizeX, float sizeY, int textureId) {
super(2);
this.textureId = textureId;
float x = sizeX / 2f;
float y = sizeY / 2f;
// vecX - see numeric part of your keyboard
SimpleVector vec7 = new SimpleVector(0 - x, 0 - y, 0);
SimpleVector vec1 = new SimpleVector(0 - x, 0 + y, 0);
SimpleVector vec3 = new SimpleVector(0 + x, 0 - y, 0);
SimpleVector vec9 = new SimpleVector(0 + x, 0 + y, 0);
this.addTriangle(vec1, vec7, vec3, new TextureInfo(textureId,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f
));
this.addTriangle(vec1, vec3, vec9, new TextureInfo(textureId,
1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f
));
}

public int getTextureId() {
return textureId;
}

public float getX(){
return this.getTranslation().x;
}

public float getY(){
return this.getTranslation().y;
}

}


However, I later want to change the texture to something else, so I tried using this subclass and function flipFrame()

Code: [Select]
public abstract class AnimatedObject extends PlaneObject {

private static final long serialVersionUID = -768657798172821902L;

private int[] frames;
private int fCount=1;

public AnimatedObject(float sizeX, float sizeY, int[] textureIds) {
super(sizeX, sizeY, textureIds[0]);
frames = textureIds;
AnimationManager.registerAnimation(this);
}

public void flipFrame(){
if (fCount >= frames.length){
fCount = 0;
}

setTexture(TextureManager.getInstance().getNameByID(frames[fCount]));
}

}

however, it does nothing...
What am I doing wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Changing texture of an object create with addTriangle
« Reply #1 on: October 06, 2011, 08:44:43 am »
Some log output available?

Offline Enerccio

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Changing texture of an object create with addTriangle
« Reply #2 on: October 06, 2011, 09:21:37 am »
This is out whole output:

Code: [Select]
Java version is: 1.6.0_22
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Loading: net.java.games.input.LinuxEnvironmentPlugin
Failed to open device (/dev/input/event12): Failed to open device /dev/input/event12 (13)

Failed to open device (/dev/input/event11): Failed to open device /dev/input/event11 (13)

Failed to open device (/dev/input/event10): Failed to open device /dev/input/event10 (13)

Failed to open device (/dev/input/event9): Failed to open device /dev/input/event9 (13)

Failed to open device (/dev/input/event8): Failed to open device /dev/input/event8 (13)

Failed to open device (/dev/input/event7): Failed to open device /dev/input/event7 (13)

Failed to open device (/dev/input/event6): Failed to open device /dev/input/event6 (13)

Failed to open device (/dev/input/event5): Failed to open device /dev/input/event5 (13)

Failed to open device (/dev/input/event4): Failed to open device /dev/input/event4 (13)

Failed to open device (/dev/input/event3): Failed to open device /dev/input/event3 (13)

Failed to open device (/dev/input/event2): Failed to open device /dev/input/event2 (13)

Failed to open device (/dev/input/event1): Failed to open device /dev/input/event1 (13)

Failed to open device (/dev/input/event0): Failed to open device /dev/input/event0 (13)

Linux plugin claims to have found 0 controllers
Loading file res/glsl_empty_v.sha
Text file res/glsl_empty_v.sha loaded...92 bytes
Loading file res/glsl_empty_f.sha
Text file res/glsl_empty_f.sha loaded...270 bytes
Loading file res/glsl_test_v.sha
Text file res/glsl_test_v.sha loaded...153 bytes
Loading file res/glsl_test_f.sha
Text file res/glsl_test_f.sha loaded...284 bytes
Time per frame set to 20ms
Loading Texture...res/ship.png
[ Thu Oct 06 09:20:22 CEST 2011 ] - WARNING: Unsupported Texture width (96)...resizing to a width of 256 pixels!
Loading Texture...res/background.jpg
[ Thu Oct 06 09:20:22 CEST 2011 ] - WARNING: Unsupported Texture width (600)...resizing to a width of 256 pixels!
Loading Texture...res/basic-bullet.png
Loading Texture...res/ufo.png
[ Thu Oct 06 09:20:22 CEST 2011 ] - WARNING: Unsupported Texture width (84)...resizing to a width of 256 pixels!
Loading Texture...res/ufo-2.png
[ Thu Oct 06 09:20:22 CEST 2011 ] - WARNING: Unsupported Texture width (85)...resizing to a width of 256 pixels!
Loading Texture...res/ufo-3.png
[ Thu Oct 06 09:20:22 CEST 2011 ] - WARNING: Unsupported Texture width (85)...resizing to a width of 256 pixels!
Loading Texture...res/ufo-4.png
[ Thu Oct 06 09:20:22 CEST 2011 ] - WARNING: Unsupported Texture width (85)...resizing to a width of 256 pixels!
> test-ufo1 5
> test-ufo2 6
> test-ufo3 7
> test-ufo4 8
Loading Texture...from Image
Software renderer disposed
Can't find desired videomode (800 x 600 x 32) - searching for alternatives
Can't find alternative videomode (800 x 600 x 32) - trying something else
Current mode:800 x 600 x 24 @60Hz
Driver is: unknown OpenGL driver on ATI Technologies Inc. / ATI Mobility Radeon HD 5800 Series
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
VBO not supported or disabled!
OpenGL renderer initialized (using 4 texture stages)
OpenGL renderer disposed
Can't find desired videomode (800 x 600 x 32) - searching for alternatives
Can't find alternative videomode (800 x 600 x 32) - trying something else
Current mode:800 x 600 x 24 @60Hz
Driver is: unknown OpenGL driver on ATI Technologies Inc. / ATI Mobility Radeon HD 5800 Series
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
VBO not supported or disabled!
OpenGL renderer initialized (using 4 texture stages)
Checking for triangle strip...
Not a triangle strip at position 1!
Subobject of object 0/object2 compiled using 6 vertices in 1ms!
Object 0/object2 compiled to 1 subobjects in 10ms!
Compiled 1 display lists!
OpenGL renderer disposed
Visibility lists disposed!
Good bye
« Last Edit: October 06, 2011, 09:23:47 am by Enerccio »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Changing texture of an object create with addTriangle
« Reply #3 on: October 06, 2011, 09:02:47 pm »
Looks fine at first glance. Have you tried to output the actual names that are used in the setTexture()-call to see that they really differ?

Offline Enerccio

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Changing texture of an object create with addTriangle
« Reply #4 on: October 06, 2011, 10:51:26 pm »
Looks fine at first glance. Have you tried to output the actual names that are used in the setTexture()-call to see that they really differ?

Yes, the ids will be different when it is called. Thus, it should work, but all it does it makes the object look as it was before, nothing has changed.

I was wondering if it is problem with using TextureInfo with addTriangle...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Changing texture of an object create with addTriangle
« Reply #5 on: October 06, 2011, 11:05:53 pm »
No, that shouldn't matter. I can't reproduce this...can you provide me with a simply test case that shows the problem?