如何在 OpenGL 中对 glutSolidTorus 进行纹理处理?

How to texture of a glutSolidTorus in OpenGL?

我正在尝试对 glutSolidTorus() 进行纹理处理。

这是我的代码:

glColor3f(1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tiring);
glutSolidTorus(.55, 1.8, 25, 25);           
glDisable(GL_TEXTURE_2D);

但是不行。我如何纹理 glutSolidTorus()?

除了 glut*Teapot() none of the GLUT geometry primitives provide texture coordinates:

11 Geometric Object Rendering

GLUT includes a number of routines for generating easily recognizable 3D geometric objects. These routines reflect functionality available in the aux toolkit described in the OpenGL Programmer's Guide and are included in GLUT to allow the construction of simple GLUT programs that render recognizable objects. These routines can be implemented as pure OpenGL rendering routines. The routines do not generate display lists for the objects they create.

The routines generate normals appropriate for lighting but do not generate texture coordinates (except for the teapot).

您有多种选择:

  1. 固定功能texcoord generation
  2. 基于着色器的纹理坐标生成
  3. Reimplement glutSolidTorus() 添加纹理坐标