need texture help

Hi all, I’m new to Xith and still fairly new to 3D programming. Using the tutorials I came up with this simple program. I’m trying to display texture on a quad instead of the cube used in the tutorial, it changes the quad’s color, but the texture doesn’t show. I’m using the glass.png texture from the tutorial:

package xith;

import javax.vecmath.*;

// Xith3D
import com.xith3d.scenegraph.*;
import com.xith3d.test.*;

// use Jogl
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
import com.xith3d.loaders.texture.*; 

public class Xith
{
      private int SCREEN_WIDTH = 1024;
      private int SCREEN_HEIGHT = 768;
      private int MAP_WIDTH = 40;
      private int MAP_HEIGHT = 40;
      private int STARTING_VIEW_X = 10;
      private int STARTING_VIEW_Z = 10;
      
      public static void main (String[] args)
      {
            new Xith();
      }
      
      public Xith()
      {
            // Texture and TextureLoader
            Texture2D textureTerrain = null;
            TextureLoader tl = new TextureLoader();
            
            // Specify paths for textures, there can be more than one path
            tl.registerPath("./textures");
            
            //load the texture, program will crash if texture doesn't exist
            textureTerrain = (Texture2D)tl.getMinMapTexture("glass.png");
            
            //create virtual univers
            VirtualUniverse universe = new VirtualUniverse();
            
            // add a view to universe
            View view = new View();
            universe.addView(view);
            
            // add a locale
            Locale locale = new Locale();
            universe.addLocale(locale);
            
            // create a BranchGroup
            BranchGroup scene = new BranchGroup();
            locale.addBranchGraph(scene);
            
            // draw Terrain
          Point3f[] coords = new Point3f[] {
                      new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, 0, MAP_HEIGHT),
                        new Point3f(0, 0, MAP_HEIGHT),
          };

          QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES);
          g.setCoordinates(0,coords);
            
            Appearance a = new Appearance();
            a.setTexture(textureTerrain);
            
          Shape3D Terrain = new Shape3D(g, a);
            scene.addChild(Terrain);
            
            // turn the scene into a render friendly format
            scene.compile();
            
            //create a canvas for our graphics
            RenderPeer rp = new RenderPeerImpl();
            CanvasPeer cp = rp.makeCanvas(null,SCREEN_WIDTH,SCREEN_HEIGHT,16,false);
            Canvas3D canvas = new Canvas3D();
            canvas.set3DPeer(cp);
            
            //modify our view
            view.addCanvas3D(canvas);
            view.getTransform().lookAt(
                        new Vector3f( STARTING_VIEW_X, 15, STARTING_VIEW_Z),            // location of eye
                        new Vector3f( STARTING_VIEW_X, 0, STARTING_VIEW_Z+3),            // center of view
                        new Vector3f( 0, 1, 0));      // vector pointing up
            view.startView();
            
      }
}

I think you need to tell the quad constructor your data contains textures coords

QuadArray quad = new QuadArray(…
GeometryArray.COORDINATES |
GeometryArray.TEXTURE_COORDINATE_2 |

you need to generate some texture coords and add them to the coords array passed to the quad construtor

TexCoord2f[] texCoords = new TexCoord2f[] {
new TexCoord2f(0f, 0f),
new TexCoord2f(1f, 0f),
new TexCoord2f(1f, 1f),
new TexCoord2f(0f, 1f) };

take a look at texture tuts on xith.org, comes with pretty pictures and source code…heh heh I know the author.

http://xith.org/tutes/GettingStarted/html/more_fun_with_textures.html#SECTION00071000000000000000

Thanks hawk, I was trying to use the code from the simple texture tutorial, I guess it doesn’t work with the quad. Here is my working code snippet if anyone else was having this problem:


            // create a BranchGroup
            BranchGroup scene = new BranchGroup();
            locale.addBranchGraph(scene);
            
            // Define Texture coords for a square shape
          TexCoord2f[] texCoords = new TexCoord2f[] {
                      new TexCoord2f(0f, 0f),
                        new TexCoord2f(1f, 0f),
                        new TexCoord2f(1f, 1f),
                        new TexCoord2f(0f, 1f) };
            
            // draw Terrain
          Point3f[] coords = new Point3f[] {
                      new Point3f(0, 0, 0),
                        new Point3f(MAP_WIDTH, 0, 0),
                        new Point3f(MAP_WIDTH, 0, MAP_HEIGHT),
                        new Point3f(0, 0, MAP_HEIGHT),
          };

          QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES |
                                                                            GeometryArray.TEXTURE_COORDINATE_2);
          g.setCoordinates(0,coords);
          g.setTextureCoordinates(0,0,texCoords);
            
            Appearance a = new Appearance();
            a.setTexture(textureTerrain);