Author Topic: Texturing problem  (Read 2847 times)

Offline einherjer

  • byte
  • *
  • Posts: 2
    • View Profile
Texturing problem
« on: April 27, 2010, 02:56:03 pm »
Hello guys..
My model comes with 5 different texture files, RGBA png-s + lightmapping texture.
How should code it so that all textures go on the "right place"?
One more question.. Why is my model rotated 180 degrees? (I had to rotate model.rotateX(3.14f); )
Code: [Select]
Object3D[] modeldata = Loader.loadOBJ("models/map/Home01.obj", "models/map/Home01.mtl", 0.01f);
model = modeldata[0];
model.rotateX(3.14f);
model.build();
world.addObject(model);
world.getCamera().setPosition(new SimpleVector(0,6,-15));


Offline einherjer

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Texturing problem
« Reply #1 on: April 27, 2010, 06:48:30 pm »
FIXED:

Code: [Select]
private final String[] tName = { "glass01", "roof01", "stone03", "wall01", "wood01" };
tManager = TextureManager.getInstance();
for( int i = 0; i < tName.length; i++ ) {
tManager.addTexture( tName[i]+".png", new Texture( "models/map/"+tName[i]+".png" ) );
}

Works fine. JPCT is so cool :D

I got another question... What about directional lighting?
I mean without shadows. Just global object shading, the same effect that the point lights create.
« Last Edit: April 27, 2010, 06:57:50 pm by einherjer »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texturing problem
« Reply #2 on: April 27, 2010, 08:45:26 pm »
You can add a light source to the scene. Either directly via your instance of World or, which i prefer, via the Light-class in the util-package.

Offline bgilb

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Texturing problem
« Reply #3 on: May 10, 2010, 10:58:54 pm »
I am also having a problem with texturing. My cube is just showing up as one color instead of showing any texture.
Code: [Select]
private World world;
private FrameBuffer buffer;
private Object3D box;

public static void main(String[] args) throws Exception {
new HelloWorld().loop();
}

public HelloWorld() throws Exception {
world = new World();
world.setAmbientLight(0, 255, 0);

TextureManager.getInstance().addTexture("box", new Texture("res/grass.png"));

box = Primitives.getBox(4f, 4f);

box.build();
box.setTexture("box");
world.addObject(box);

world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
}


private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

while (!org.lwjgl.opengl.Display.isCloseRequested()) {
box.rotateY(0.01f);
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
System.exit(0);
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texturing problem
« Reply #4 on: May 10, 2010, 11:56:21 pm »
That's because the objects created by the Primitive class have no texture coordinates other than 0/0 (except for the plane). A quick and dirty solution is to use one of those calcTextureWrap...()-methods in Object3D, but they won't give you a proper texturing for a cube. If you want that, you have to load a some from a file instead that has proper u/v-coordinates.