Author Topic: noob question: texture mapping  (Read 2499 times)

Offline sokobozz

  • byte
  • *
  • Posts: 5
    • View Profile
noob question: texture mapping
« on: January 08, 2010, 07:09:19 pm »
Hi!

All best in new 2010.


I am trying to play with adding triangle and applying texture on Object3D, but currenty I can't see that my texture is apllied.

Here is result:


Here is texture:


Code: [Select]
import java.awt.Color;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;

public class Template {

  /**
   * @param args
   * @throws InterruptedException
   */
  public static void main(String[] args) throws InterruptedException {
    Template.setupAndRun();
  }

  private static void setupAndRun() throws InterruptedException {

    TextureManager tm = TextureManager.getInstance();
    String texName = "tex3.jpg";
    Texture tex = new Texture(texName);
    tm.addTexture(texName, tex);
    int texID = tm.getTextureID(texName);

    Object3D obj1 = new Object3D(2);

    obj1.addTriangle(V(100, -100, 0), 0f, 0f, V(100, 0, 0), 0f, 1f, V(-100, 0, 0), 1f, 1f, texID);

    obj1.build();
    obj1.setEnvmapped(Object3D.ENVMAP_ENABLED);

    World world = new World();
    world.addLight(new SimpleVector(0, -50, 130), Color.WHITE);
    world.setAmbientLight(255, 255, 255);
    world.getCamera().setPosition(0, 0, 250);
    world.getCamera().lookAt(V(0, 0, 0));

    world.addObject(obj1);

    FrameBuffer buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
    buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
    buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

    while (!org.lwjgl.opengl.Display.isCloseRequested()) {

      buffer.clear(java.awt.Color.BLACK);
      world.renderScene(buffer);
      world.draw(buffer);
      buffer.update();
      buffer.displayGLOnly();
      Thread.sleep(10);
    }
    buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
    buffer.dispose();
    System.exit(0);

  }

  public static SimpleVector V(float x, float y, float z) {
    return new SimpleVector(x, y, z);
  }

}



No idea what is problem...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: noob question: texture mapping
« Reply #1 on: January 08, 2010, 07:21:53 pm »
Remove this line:

Code: [Select]
obj1.setEnvmapped(Object3D.ENVMAP_ENABLED);

It enables environment mapping which creates uv-coordinates on the fly based on the objects position and shape. It's not what you want in this case.
« Last Edit: January 08, 2010, 07:37:41 pm by EgonOlsen »

Offline sokobozz

  • byte
  • *
  • Posts: 5
    • View Profile
Re: noob question: texture mapping
« Reply #2 on: January 08, 2010, 07:55:10 pm »
That's it......

Thx!