Results 1 to 4 of 4

Thread: 2D-texture mapping a sphere. glTexGen*()

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    rus
    Posts
    21

    2D-texture mapping a sphere. glTexGen*()

    In Red Book 1.1 there is a sample 'texgen.c' for mapping a 1D texture 'Automatic Texture-Coordinate Generation' and it works fine. I want to wrap a 2D texture around a sphere with glTexGen*() functions. I have 32x32 blue texture with red square in the center. The init() code looks like:
    Init()
    ....
    glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP)
    glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP)
    glEnable(GL_TEXTURE_GEN_S)
    glEnable(GL_TEXTURE_GEN_T)
    ....
    But when a shpere is renered and I begin to rotate it, assigned texture doesnt rotate with the sphere but behaves like with GL_EYE_LINEAR and GL_EYE_PLANE enabled with 1D Red Book sample.
    How make it to stick to sphere surface?

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2000
    Location
    Oxford, England
    Posts
    472

    Re: 2D-texture mapping a sphere. glTexGen*()

    GL_OBJECT_LINEAR ?

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: 2D-texture mapping a sphere. glTexGen*()

    Sounds to me that you misunderstood the purpose of sphere mapping. Sphere mapping is a kind of reflection mapping. The texture is an image of the surrounding envoronment (as seen from the object), and GL_SPHERE_MAP generates texture coordinates for that image so you can use it to get a reflection of the environment in the object being textured.

    If you want to wrap a texture around a sphere, like a texture of the earth to get a nice picture of our planet, you have to generate the texture coordinates yourself. The automatic texture coordinate generation won't help you in that case.

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    rus
    Posts
    21

    Re: 2D-texture mapping a sphere. glTexGen*()

    Ive done with it. Yes with GL_TEXTURE_GEN_S and GL_TEXTURE_GEN_T texture will always facing you in GL_SPHERE_MAP mode. There are a good samples on how to calculate texture coordinates to get texture wrap a sphere and yet another way to do it is Quadrics. Just a simple one with few lines of code:
    q = gluNewQuadric[];
    gluQuadricNormals[q, GL_SMOOTH];
    gluQuadricTexture[q, GL_TRUE]; <-- Thats it!
    glTexGeni[GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP]
    glTexGeni[GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP]
    .......
    glBindTexture[...];
    gluSphere[q, ....];

Similar Threads

  1. Sphere texture mapping
    By pedr0 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-22-2010, 05:04 AM
  2. Sphere Texture Mapping
    By girish3110 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-07-2008, 11:21 AM
  3. Texture Mapping a Sphere
    By OGL_PGR in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-10-2006, 08:16 AM
  4. Texture a sphere with glTexGen
    By michcaptk in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-13-2006, 07:23 PM
  5. Mapping texture to an sphere
    By thorsan in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-23-2004, 12:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean