Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Sphere and texture rotation

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    4

    Sphere and texture rotation

    Hi!
    I'm drawing a sphere and cover it with a texture.
    That's the problem: I want the texture to rotate with the sphere.
    How can I do this?

  2. #2
    Intern Contributor
    Join Date
    Apr 2011
    Location
    Miami, FL
    Posts
    54

    Re: Sphere and texture rotation

    Well, if you add the texture to the sphere, it would be attach to it.
    Bind the texture before drawing the sphere

  3. #3
    Junior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Sphere and texture rotation

    Quote Originally Posted by furetto3
    Hi!
    I'm drawing a sphere and cover it with a texture.
    That's the problem: I want the texture to rotate with the sphere.
    How can I do this?
    If you're drawing a texture, you must have texture coordinates for your sphere vertices. So, when rotating the sphere, the texture will rotate too, unless you are not setting the texture coordinates correctly.

  4. #4
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    4

    Re: Sphere and texture rotation

    Sorry, but I don't understand...I'm doing something like this:

    glPushMatrix();

    glEnable(GL_TEXTURE_2D);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glBindTexture(GL_TEXTURE_2D, texture_id[1]);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

    glTranslatef(posX, 1.0, posZ);
    glutSolidSphere(palla.r, 12, 12);

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);

    glPopMatrix();

    what kind of sphere vertex I'm suppose to consider?

  5. #5
    Junior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Sphere and texture rotation

    I'm not sure, but I read somewhere that glutSolidSphere didn't generate texture coordinates. Try glutSolidTeapot(), I'm sure that the teapot have texture coordinates.

  6. #6
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    4

    Re: Sphere and texture rotation

    Probably you are right.
    But I need to draw a sphere not a teapot.
    Anybody can help me, please?

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Sphere and texture rotation

    You can use glu (gluSphere)
    or you can use my library (glhCreateSpheref2 and example code is provided in the header).
    Or as a fun exercise, create a sphere yourself.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •