纹理 glutSolidSphere [英] texturing a glutSolidSphere

查看:38
本文介绍了纹理 glutSolidSphere的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 glutSolidSphere 添加地球纹理.问题是我无法弄清楚如何使纹理在整个球体上拉伸并且仍然能够旋转.

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

我们正在启用纹理.

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...

在参数中使用 GL_SPHERE_MAP 而不是 GL_OBJECT_LINEAR 使纹理看起来正确,但它们不能旋转.

using GL_SPHERE_MAP in param instead of GL_OBJECT_LINEAR makes the textures look proper, but they cannot rotate.

我用于纹理的参数是

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

我知道 GL_REPEAT 会平铺纹理,而使用 GL_CLAMP 会在对象上给我一次纹理,但我无法让它在整个球体上伸展.

I understand that GL_REPEAT tiles the texture, while using GL_CLAMP instead gives me the texture once on the object, but I cannot get it to stretch over the whole sphere.

有谁知道如何正确地构造 glutSolidSphere 的纹理?

Does anyone know how to properly texture a glutSolidSphere?

推荐答案

glutSolidSphere 没有提供正确的纹理坐标,OpenGL 内置的纹理生成只允许从顶点位置到顶点纹理的线性映射坐标,这实质上意味着您不能使用它们来纹理具有 2 平面有界纹理的 3 球体(有关数学解释,请查找 流形拓扑map理论).

glutSolidSphere doesn't provide proper texture coordinates, and OpenGL built in texture generation allows only for linear mappings from vertex position to vertex texture coordinate, which essentially means that you can not use them to texture a 3-sphere with a 2-flat, bounded texture (for a mathematical explanation look up the topics of topology of manifolds and map theory).

那你能做什么?有多种可能的解决方案:

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

  • 不要使用 glutSolidSphere,而是使用其他一些确实提供适当纹理坐标的几何生成器(尽管仅使用单个有界 2D 纹理对球体进行纹理化是一个困难的话题,有几个映射,每个都有他们的问题)

  • Don't use glutSolidSphere, but some other geometry generator that does provide proper texture coordinates (though texturing a sphere with just a single bounded 2D texture is a difficult topic, there are several mappings, each with their problems)

使用与球体具有相同拓扑结构的纹理,一个立方体贴图,然后您可以使用GL_NORMAL_MAP作为纹理生成模式,即

Use a texture with the same topology as a sphere, a cube map, then you can use the GL_NORMAL_MAP for the texture gen 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);

查找有关立方体映射的教程.但本质上,立方体贴图由 6 个纹理面组成,围绕原点排列在立方体中,纹理坐标不是立方体本身上的点,而是来自原点的方向和寻址的纹素是方向射线相交的方向与立方体.

Look up tutorials about cube mapping. But in a essence a cube map consists of 6 texture faces, arranged in a cube about the origin and texture coordinates are not points on the cube itself, but a direction from the origin and the addressed texel is the one, where the direction ray intersects with the cube.

使用顶点着色器,从顶点位置生成纹理坐标.由于顶点着色器是可自由编程的,因此映射不需要是线性的.当然会再次遇到用有界 2-flat 映射 3-sphere 的特殊性.

Use a vertex shader, generating texture coordinates from vertex positions. Since a vertex shader is freely programmable, the mapping isn't required to be linear. Of course will run into the peculiarities of mapping a 3-sphere with a bounded 2-flat again.

这篇关于纹理 glutSolidSphere的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆