Textures in applets

Started by quixote_arg, January 23, 2006, 03:12:55 PM

Previous topic - Next topic

quixote_arg

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:


       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:


       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

rolz

Looks like UV coordinates are not assigned properly for this object (box).
try object3D.calcTextureWrap();
Regards,
Andrei

quixote_arg

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

:(

EgonOlsen

You are using environment mapping on the wall. Disable it by commenting out:

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

quixote_arg

I tried it and still the same rendering.

This is the latest code:


       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?

EgonOlsen

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:

   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.