I have been working through one of the NeHe tutorials (Lesson06) with texture mapping and was trying to modify the code to allow different images on the already created 3D cube. After looking through the code, this is the only place were the code actually uses the image file:
TextureReader.Texture image = null;
try {
image = TextureReader.readTexture("nehe/dice1.png");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
What I'm asking is how can you load 6 different images instead of just 1 to cover the entire cube? I am trying to make a "die" I have the images for 1 through 6. If you need to view the full code, you can find it at: http://www.java-tips.org/other-api-tips/jogl/texture-mapping-nehe-tutorial-jogl-port.html
You would have to create 6 separate texture IDs and bind to a specific texture ID before you draw each face. The call that actually creates a texture ID is here:
texture = genTexture(gl);
And then all the stuff that follows that call actually sets up the texture.
It would be easier for you to load a single texture that contains the unwrapped die, or just simply contains the faces for 1 thru 6 in a line. Then it's just a matter of specifying the correct texture co-ordinates to select the right part of the texture for each face.
Instead of a face's texture co-ords going from (0,0)
to (1,1)
, they could go from ((num-1.0)/6.0, 0)
to (num/6.0, 1)
where num
is a double between 1 and 6. In this case, you would line the images up horizontally.