Texturing problem

Started by einherjer, April 27, 2010, 02:56:03 PM

Previous topic - Next topic

einherjer

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



einherjer

#1
FIXED:

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.

EgonOlsen

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.

bgilb

I am also having a problem with texturing. My cube is just showing up as one color instead of showing any texture.

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

EgonOlsen

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.