Texture tiling

Started by VT900, December 05, 2010, 08:45:52 PM

Previous topic - Next topic

VT900

Hi,
Apologies if this has been asked already (I couldnt find a solution by searching, maybe its just me), but theres a really annoying bug in my program. I have isolated it to one cause, and basically, the texture I have assigned the Object3D is tiling. I want it to stretch to cover the object instead of tiling to fill that space. Any way I could do this? This must sound really trivial, but I can't find anything to solve it (although, it seems like a question that would have been asked already)

Regards,
Barry

EgonOlsen

Which kind of object and which renderer are you using? Any screen shot?

VT900

Well, I have a plane from Primitives.getPlane(2, 40f) and using the hardware renderer, though the software renderer seems to do it too. The texture is 256x256px.

EgonOlsen

A plane created by Primitives shouldn't tile the texture. Are you sure that that's all you do to it? Some examples contain code to introduce that tiling by modifying the texture coordinates are an object has been created. Are you sure that you are not using such method?

VT900

#4
Ok, I made some code to demonstrate this problem. I based it off the applet demo in the wiki, and hacked it together really quickly!

Test.jpg - http://img193.imageshack.us/img193/3902/testn01.jpg
The display - http://img340.imageshack.us/img340/4184/runw.png
The problem zoomed in - http://img697.imageshack.us/img697/5651/highlightm.png

Call me a bit of a perfectionist! You can see the yellow pixels showing up in at the bottom, when they are meant to be at the top only.


import java.awt.Graphics;

import javax.swing.JApplet;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;

public class Test extends JApplet implements Runnable
{
   private Object3D box;

   private FrameBuffer buffer = null;
   private World world = null;

   private boolean alive = true;
   private boolean initialized = false;

   @Override
   // Initialize all components of the applet
   public void init()
   {
       world = new World();  // create a new world
       World.setDefaultThread( Thread.currentThread() );

       // Add some light to the scene
       world.setAmbientLight(255, 255, 255);
setSize(640,480);

       // create a new buffer to draw on:
       buffer = new FrameBuffer( getWidth(), getHeight(),
                                 FrameBuffer.SAMPLINGMODE_NORMAL );

       // Create the box:
       Texture tex = new Texture("../dat/test.jpg");
       TextureManager.getInstance().addTexture("test", tex);
       box = Primitives.getPlane(2, 40f);
       box.rotateX((float)Math.PI/2);
       box.setTexture("test");
       box.build();
       world.addObject( box );

       // set the camera's position:
       world.getCamera().setPosition( 50, -250, -200 );

       // Look at the box:
       world.getCamera().lookAt( box.getTransformedCenter() );

       // Finished initializing.  Now it is safe to paint.
       initialized = true;

       // Start the main "Game Loop":
       new Thread( this ).start();
   }

   // Main Game Loop:
   @Override
   public void run()
   {
       while( alive )
       {
           // Have the box rotate:
           //box.rotateY( 0.01f );

           // Tell the applet to repaint itself:
           this.repaint();

           // Sleep for a bit:
           try
           {
               Thread.sleep( 10 );
           }
           catch( Exception e )
           {}
       }
   }

   // Draw the scene:
   @Override
   public void paint( Graphics g )
   {
       // Make sure jPCT is finished initializing:
       if( !initialized )
           return;

       buffer.clear();   // erase the previous frame

       // render the world onto the buffer:
       world.renderScene( buffer );
       world.draw( buffer );
       buffer.update();

       buffer.display( g, 0, 0 );
   }

   // End the main game loop:
   @Override
   public void destroy()
   {
    alive = false;
   }
}

EgonOlsen

You are a perfectionist... ;) That's actually normal behaviour cased by the filtering. For the software renderer, there's not much you can do. For hardware, you can call enableGLClamping on the texture and the effect should be gone.

VT900

Haha, thanks again Egon, the bug was driving me up the wall :P
It's fixed now, at last.

Barry.