我如何自动纹理在OpenGL中映射球体?

时间:2022-02-07 20:05:42

Which parameters for especially s and t would I use to text map a sphere? I've tried various different options, but there's always a little portion that's distorted no matter what values I choose for float[] s and t. I can do planes and cylinders, but I'm not sure about spheres. Any help would be appreciated.

我将使用哪些参数特别是s和t来对球体进行文本映射?我尝试了各种不同的选项,但无论我为float [] s和t选择什么值,总会有一小部分被扭曲。我可以做飞机和气缸,但我不确定球体。任何帮助,将不胜感激。

    gl.glTexGeni(GL2.GL_T, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR);
    float[] s = {1f, 0f, 0f, 0};
    gl.glTexGenfv(GL2.GL_S, GL2.GL_OBJECT_PLANE, s, 0);
    float[] t = {0f, 1f, 0f, 0};
    gl.glTexGenfv(GL2.GL_T, GL2.GL_OBJECT_PLANE, s, 0);

1 个解决方案

#1


0  

You can not texture map a sphere using a single rectangular texture without creating some serious distortion at some place. It's mathematically impossible. That being said, you should not use the glTexGen functionality for this either, because a) it's been deprecated, and b) only creates linear planar mappings, whereas for texturing a sphere you need curvilinear coordinates. Use a vertex shader to generate the texture coordinates from vertex position.

您无法使用单个矩形纹理对球体进行纹理贴图,而不会在某些位置产生严重的扭曲。这在数学上是不可能的。话虽这么说,你也不应该使用glTexGen功能,因为a)它已被弃用,b)只创建线性平面映射,而对于纹理化球体,你需要曲线坐标。使用顶点着色器从顶点位置生成纹理坐标。

#1


0  

You can not texture map a sphere using a single rectangular texture without creating some serious distortion at some place. It's mathematically impossible. That being said, you should not use the glTexGen functionality for this either, because a) it's been deprecated, and b) only creates linear planar mappings, whereas for texturing a sphere you need curvilinear coordinates. Use a vertex shader to generate the texture coordinates from vertex position.

您无法使用单个矩形纹理对球体进行纹理贴图,而不会在某些位置产生严重的扭曲。这在数学上是不可能的。话虽这么说,你也不应该使用glTexGen功能,因为a)它已被弃用,b)只创建线性平面映射,而对于纹理化球体,你需要曲线坐标。使用顶点着色器从顶点位置生成纹理坐标。