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();
}
}