I have a gluSphere generated in my display that is rotating, but having a problem with the texture rotating with the sphere as well. So in a nutshell, no matter how the sphere rotates, the texture around the sphere remains in the same position regardless.
How am able to update the texture along with the sphere so that it rotates?
private static Texture testTex;
...
// This method is called in init()
public void sphereTexture(GL2 gl)
{
InputStream iStream = null;
try
{
iStream = getClass().getResourceAsStream("cratepng.png");
TextureData data = TextureIO.newTextureData(iStream, false, null);
testTex = TextureIO.newTexture(data);
testTex.getImageTexCoords();
testTex.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
testTex.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
iStream.close();
}
catch(IOException e)
{
e.printStackTrace();
System.exit(1);
}
// Set material properties
gl.glEnable(GL2.GL_TEXTURE_GEN_S);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_NORMAL_MAP);
gl.glEnable(GL2.GL_TEXTURE_GEN_T);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
gl.glTexGeni(GL2.GL_T, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_NORMAL_MAP);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
testTex.setTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S);
testTex.setTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T);
}
// Draw Sphere (FILL, LINE, POINT) method called in display()
public void draw(GL2 gl, GLU glu)
{
gl.glTranslatef(1f, 0.0f, -20.0f);
gl.glRotatef(angleSphere, 1f, 0.0f, 0.0f); //90
GLUquadric sphere = glu.gluNewQuadric();
glu.gluQuadricDrawStyle(sphere, GLU.GLU_LINE);
glu.gluQuadricTexture(sphere, true);
glu.gluQuadricNormals(sphere, GLU.GLU_SMOOTH);
glu.gluQuadricOrientation(sphere, GLU.GLU_OUTSIDE);
testTex.enable(); // enable texture
testTex.bind(); // bind texture
glu.gluSphere(sphere, radius, slices, stacks);
testTex.disable();
glu.gluDeleteQuadric(sphere);
angleSphere += speed;
//System.out.println(angleSphere);
}
