Texturing Jamming SolidSphere

I need to add ground texture to glutSolidSphere. The problem is that I cannot figure out how to make the texture stretch across the entire sphere and still be able to rotate.

We have included textures.

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); //drawcode... 

using GL_SPHERE_MAP in the parameter instead of GL_OBJECT_LINEAR makes the textures correct, but they cannot rotate.

The options I use for texture are

 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

I understand that GL_REPEAT breaks the texture, while GL_CLAMP instead gives me the texture once on the object, but I cannot make it stretch across the entire sphere.

Does anyone know how to properly texture glutSolidSphere?

+4
source share
1 answer

glutSolidSphere does not provide the correct texture coordinates, and the OpenGL built-in texture generation only allows for linear mappings from the vertex position to the vertex texture coordinates, which essentially means that you cannot use them to texture a three-dimensional sphere with a 2-flat, bounded texture (for mathematical explanations are considered topics of the topology of manifolds and map theory).

So what can you do? There are a number of possible solutions:

  • Do not use glutSolidSphere, but any other geometry generator that really provides the correct texture coordinates (although texturing a sphere with only one limited 2D texture is a complex topic, there are several mappings, each of which has its own problems)

  • Use a texture with the same topology as a sphere, a cubic map, then you can use GL_NORMAL_MAP for the texture generation mode, i.e.

     glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); 

    Check out the cube mapping tutorials. But in essence, a cubic map consists of 6 texture faces located in a cube around the origin and texture coordinates, not the points on the cube itself, but the direction from the origin and the address texel is the one where the direction ray intersects with the cube.

  • Use the vertex shader, creating texture coordinates from vertex positions. Since the vertex shader is freely programmable, the mapping does not have to be linear. Of course, I will encounter the features of mapping a 3-sphere with a limited 2-plane again.

+5
source

Source: https://habr.com/ru/post/1382814/


All Articles