Author Topic: Textures in applets  (Read 4410 times)

Offline quixote_arg

  • byte
  • *
  • Posts: 9
    • View Profile
Textures in applets
« on: January 23, 2006, 03:12:55 pm »
Hi, I'm trying to make a simple applet based on the FPS code. The world so far consists only of a floor and a wall. I try to apply a brick like texture to the wall but it renders bad.

This is the texture I'm using:


And this is a screenshot of the result:


Here is the code of how the wall is initialized:

Code: [Select]

        wall = Primitives.getBox(150f, 0.01f);
        wall.rotateY((float) Math.PI / 4);
        wall.rotateX((float) Math.PI / 2);
        wall.setOrigin(new SimpleVector(800, -75, -300));
        wall.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
        wall.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
        wall.setTexture("wall");
        wall.setEnvmapped(Object3D.ENVMAP_ENABLED);
        wall.setEnvmapMode(Object3D.ENVMAP_CAMERASPACE);
        theWorld.addObject(wall);


And here is the initialization of the FrameBuffer:

Code: [Select]

        buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
        buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE,
                IRenderer.MODE_OPENGL);
        buffer.setBoundingBoxMode(FrameBuffer.BOUNDINGBOX_NOT_USED);

        buffer.optimizeBufferAccess();


Any ideas why is this happening?

Thanks a lot

Offline rolz

  • float
  • ****
  • Posts: 280
  • Technocrat
    • View Profile
Textures in applets
« Reply #1 on: January 23, 2006, 04:51:33 pm »
Looks like UV coordinates are not assigned properly for this object (box).
try object3D.calcTextureWrap();
Regards,
Andrei

Offline quixote_arg

  • byte
  • *
  • Posts: 9
    • View Profile
Textures in applets
« Reply #2 on: January 23, 2006, 06:35:06 pm »
I tried calling it, after and before setting the texture and with or without calling recreateTextureCoords but with no luck, the result is the same

 :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Textures in applets
« Reply #3 on: January 23, 2006, 07:29:54 pm »
You are using environment mapping on the wall. Disable it by commenting out:

Code: [Select]
       
wall.setEnvmapped(Object3D.ENVMAP_ENABLED);
wall.setEnvmapMode(Object3D.ENVMAP_CAMERASPACE);


And use one of the calcTextureWrap...()-methods. However, it may not produce 100% correct texturing for a cube. If you want a cube correctly textured, load one or create one on the fly. The primitives in jPCT are all simple lathe objects (except for the plane, which is the only one with "correct" texturing).

Offline quixote_arg

  • byte
  • *
  • Posts: 9
    • View Profile
Textures in applets
« Reply #4 on: January 23, 2006, 08:10:34 pm »
I tried it and still the same rendering.

This is the latest code:

Code: [Select]

        wall = Primitives.getBox(150f, 0.01f);
        wall.rotateY((float) Math.PI / 4);
        wall.rotateX((float) Math.PI / 2);
        wall.setOrigin(new SimpleVector(800, -75, -300));
        wall.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
        wall.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

        wall.setTexture("wall");
       
        wall.calcTextureWrap();

        theWorld.addObject(wall);


Any pointers on how to create the object on the fly?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Textures in applets
« Reply #5 on: January 23, 2006, 08:56:01 pm »
Are you calling wall.build() or world.buildAllObjects() somewhere later in your code? If not, you should do that. I've tried it myself and noticed that both calcTextureWrap()-methods are not very suitable to texture a box. So here's a "on the fly"-box with (almost) correct texturing:

Code: [Select]
   Object3D box=new Object3D(12);
   
    SimpleVector upperLeftFront=new SimpleVector(-1,-1,-1);
    SimpleVector upperRightFront=new SimpleVector(1,-1,-1);
    SimpleVector lowerLeftFront=new SimpleVector(-1,1,-1);
    SimpleVector lowerRightFront=new SimpleVector(1,1,-1);
   
    SimpleVector upperLeftBack = new SimpleVector( -1, -1, 1);
    SimpleVector upperRightBack = new SimpleVector(1, -1, 1);
    SimpleVector lowerLeftBack = new SimpleVector( -1, 1, 1);
    SimpleVector lowerRightBack = new SimpleVector(1, 1, 1);
   
    // Front
    box.addTriangle(upperLeftFront,0,0, lowerLeftFront,0,1, upperRightFront,1,0);
    box.addTriangle(upperRightFront,1,0, lowerLeftFront,0,1, lowerRightFront,1,1);
   
    // Back
    box.addTriangle(upperLeftBack,0,0, upperRightBack,1,0, lowerLeftBack,0,1);
    box.addTriangle(upperRightBack,1,0, lowerRightBack,1,1, lowerLeftBack,0,1);
   
    // Upper
    box.addTriangle(upperLeftBack,0,0, upperLeftFront,0,1, upperRightBack,1,0);
    box.addTriangle(upperRightBack,1,0, upperLeftFront,0,1, upperRightFront,1,1);
   
    // Lower
    box.addTriangle(lowerLeftBack,0,0, lowerRightBack,1,0, lowerLeftFront,0,1);
    box.addTriangle(lowerRightBack,1,0, lowerRightFront,1,1, lowerLeftFront,0,1);
   
    // Left
    box.addTriangle(upperLeftFront,0,0, upperLeftBack,1,0, lowerLeftFront,0,1);
    box.addTriangle(upperLeftBack,1,0, lowerLeftBack,1,1, lowerLeftFront,0,1);
   
    // Right
    box.addTriangle(upperRightFront,0,0, lowerRightFront,0,1, upperRightBack,1,0);
    box.addTriangle(upperRightBack,1,0, lowerRightFront, 0,1, lowerRightBack,1,1);

    box.setTexture("base");
    box.build();


Hope this helps.