Results 1 to 8 of 8

Thread: texturing a geodesic sphere

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    5

    texturing a geodesic sphere

    Hi,

    I'm trying to render a geodesic sphere and make it look like the Earth by applying a single piece of texture on it.

    I'm familiar with Java, C++, gmax and gimp. But I'm new to OpenGL. I went whrough www.videotutorialsrock.com so I can do some basic stuff. Also I have downloaded some codes from Bullet Physics to make my life easier and play with vectors.

    Here's what I have accomplished so far:
    1. Draw 20 triangles to form an icosahedron
    2. Apply the texture on each triangle by assigning texture coordinates to each vertex. I simply used the top-middle, bottom-left and botton-right positions on the 256-by-256 bitmap file.
    3. Subdivide each triangle into 4 little triangles and pull the new vertices out so they are separated from the center just as far as the old vertices. Draw triangles all over again, with texture.
    4. Perform such subdivision k times until it reaches the desired shape, where k = 0, 1, 2, 3...
    5. Make the "planet" rotate

    Goal:
    Instead of painting a picture on individual triangles, I want the picture to cover the entire planet. Also, it should work with any number of subdivisions.

    A Wikipedia article on Dymaxion map provides some clue, but it doesn't explain the math behind it.

    There are many ways to unfold the polygon for Dymaxion map, but I prefer the way discussed in
    http://freeciv.wikia.com/wiki/Talk:Sphere
    It will fit into a rectangular texture file. Also, the equator will look straight, which is a good thing.

    I'll probably have to subdivide the picture and assign coorninates to each vertex. I'm unable to devise an algorithm that does that. The vertices in my sphere are not indexed in any way.

    Any suggestion?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: texturing a geodesic sphere

    Quote Originally Posted by Snow Spider
    Instead of painting a picture on individual triangles, I want the picture to cover the entire planet. Also, it should work with any number of subdivisions.
    You can first do refinements on your polyhedron to a degree to make it appear like a sphere and then apply texture over it. The texture coordinates distribution should follow spherical parametric equations then.

    OR

    If you wish to apply texture along with every round of refinement (on each triangle) then you should keep track of mapping. i.e texel 0 maps to vertex 0 of triangle 0 , and texel 1.0 to vertex n of your last triangle.

    With every subdivision, (k = 0,1,2...N), the first vertex in your list would always map to texel 0.0 and last vertex to 1.0. In between, you can interpolate texel value using barycentric coordinate system or some kind of interpolation (linear etc. ) but I warn you that the finish won't be smooth till you subdivide your polyhedron to a level where C2 continuity is achieved.

    I prefer the first method as applying texture to already refined polyhedron would be fast and inexpensive as compared to second approach.

    Hope this helps you.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    5

    Re: texturing a geodesic sphere

    I have found a solution that looks a lot easier:

    Code :
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, _textureId);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glutSolidSphere(1,50,50);
    glDisable(GL_TEXTURE_2D);

    By adding these lines in the middle of my code, I can paint the planet with the actual map of the world. This will hopefully allow me to have any number of subdivision without ruining the texture.

    Still, everything is skewed about 60 degrees to the left. I think it has to do with the fact that my sphere is made out of triangles.
    Secondly, the texture only stretches to half the sphere, and then projects its mirror image on the other side.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: texturing a geodesic sphere

    glutSolidSphere() may not be generating texture coordinates accurately. Rely on the model you create and generate texels by yourself or use cubemapping.

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGenf instead of glTexGeni to generate texels in floats. (Suggestion) and try GL_SPHERE_MAP for GL_S.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    5

    Re: texturing a geodesic sphere

    Thank you all. The solutions provided in the library didn't work out for me, so I ended up using longitude & latitude for tex coord at every vertex, which caused zig-zag seam on the longitude zero. I have fixed that, but I'm now struggling with the two poles.

    As you can see in the picture uploaded, the texture swirls at the north pole as well as at the south pole because the particular vertex is linked to the tex coord (0,1) for all 6 triangles around it.

    If I can squeeze the line from (0,1) to (1,1) into a point as a tex coord, this will a cakewalk. In fact, that's how Mercator maps work. I just don't know what OpenGL needs to be told to do it. I'm pretty sure this is an elementary issue, but I find no alternative to asking.

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: texturing a geodesic sphere

    Simple solution : keep a pole vertex for each triangle around it, each with a different texcoord.

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    5

    Re: texturing a geodesic sphere

    Well... in fact I've tried that before posting the last question. It is better than the "fail" case above, but it still cuts 1/2 of the pole areas off the texture in triangular sections.

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: texturing a geodesic sphere

    Indeed. The method discussed in the freeciv article you linked *have to* be applied with a specially crafted texture like this one :
    http://freeciv.wikia.com/index.php?t...y-earth-20-gif
    Note how the triangles leading to the poles are disjoint.

Similar Threads

  1. Texturing Sphere
    By AhmedSabry in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-21-2012, 02:25 PM
  2. classical sphere texturing
    By ugluk in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-04-2011, 03:49 PM
  3. texturing a sphere
    By OGLuser in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-24-2009, 12:55 PM
  4. Texturing a sphere
    By pjyelton in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-06-2009, 11:01 PM
  5. geodesic sphere
    By greg2 in forum OpenGL: General
    Replies: 0
    Last Post: 02-15-2008, 06:02 AM

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