Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

} 
share|improve this question
    
I think the code you have posted seems correct. If you are still having problems, you should try to post some more code (glEnables etc.). The problems most probably comes from other parts of your code. You should also make sure your sphere is really rotating, but from the looks of your code you must have already checked that out. –  Grieverheart Jan 7 '13 at 17:07
    
@Grieverheart Thats for the input. I've checked to see if the sphere itself was rotating and it is, but the texture still remains in the same position. I've updated the question to show the glEnables. –  ChocoMan Jan 8 '13 at 4:22
add comment

1 Answer

up vote 1 down vote accepted

After posting your glEnables I see that you are enabling sphere mapping with glEnable(GL_TEXTURE_GEN_S) and glEnable(GL_TEXTURE_GEN_T) and generate texture coordinates. You shouldn't need to do this since this is done by glu (see here).

Nonetheless, what looks more suspicious is your use of GL_NORMAL_MAP in the glTexGeni function. In the openGL reference page there is no description of how the texture coordinates are calculated using this parameter. You should either remove these two texture generation blocks or try a different parameter in the glTexGeni i.e. GL_OBJECT_LINEAR.

share|improve this answer
    
That was the problem! Thanks for the help! Do you know of any books/sites that explains the different components in better detail? –  ChocoMan Jan 8 '13 at 4:43
    
You can find many details on the OpenGL 2.1 man page here. A good source for OpenGL 2 tutorials you may already know is the NeHe tutorials. There are also many good books including the official OpenGL red book and perhaps the OpenGL Superbible. Btw, I edited my answer because it wasn't a very good explanation. –  Grieverheart Jan 8 '13 at 5:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.