I’ve been having problems getting my textures to appear and I’m not sure if If I’m making the mistake in the actual generation of the texture coordinates or in applying them to the geom.
The following code generates the coordinates
private void generateTextureCoordinates(int sizeX, int sizeZ){
//SizeX is the number of coordinates in the X Direction
//SizeZ is the number of coordinates in the Z Direction
texCoords = new TexCoord2f[MAX_COORDINATES];
int index=0;
for(int z = 0; z < sizeZ; z++){
for(int x = 0; x < sizeX; x++){
texCoords[index++] = new TexCoord2f((float)x / (float)sizeX, (float)z / (float)sizeZ);
}
}
}
When I create the geometry I do the following.
private void generateGeometry() {
geo = new IndexedTriangleArray(MAX_COORDINATES, TriangleArray.COORDINATES |
TriangleArray.NORMALS |
TriangleArray.COLOR_3 |
TriangleArray.TEXTURE_COORDINATE_2, MAX_INDICES);
geo.setValidVertexCount(MAX_COORDINATES);
geo.setCoordinates(0, coordinates);
geo.setValidIndexCount(MAX_INDICES);
geo.setIndex(indices);
geo.setNormals(0, normals);
geo.setColors(0, colors);
geo.setTexCoordRef2f(0,texCoords);
}
Finally when I set up the texture I do the following …
TextureLoader.tf.registerPath(".");
TextureLoader.tf.registerPath("..");
texture = (Texture2D) TextureLoader.tf.getMinMapTexture("checkerboard.jpg");
TextureAttributes ta = new TextureAttributes();
ta.setTextureMode(TextureAttributes.MODULATE);
app = new Appearance();
app.setTexture(texture);
app.setTextureAttributes(ta);
Of course I realize being just code fragments its probably difficult to figure out what is wrong. Hopefully, it’s something very obvious and someone can catch it right away. If not I’ll try to extract the relevant code into something executable. Thanks for the help!