-1

此代码仅呈现十二面体并完全忽略该glBegin(GL_TRIANGLES)块:

glutSolidDodecahedron();
glBegin(GL_TRIANGLES);
glNormal3f(1, 0, 0);
glVertex3f(11, 0, 0);
glNormal3f(0, 1, 1);
glVertex3f(-11, 0, 0);
glNormal3f(0, 0, 1);
glVertex3f(0, 0, 11);
glEnd();

这两个着色器非常简单:

顶点着色器:

varying vec3 normal;
void main()
{   
gl_Position = ftransform();
gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
normal =  gl_Normal;
normal = gl_NormalMatrix  * normal;
}

和碎片:

uniform vec3 lightDir;
varying vec3 normal;
void main()
{
    float intensity = dot(lightDir, normal);
    gl_FragColor =  0.5 * (1.5 + intensity) * gl_Color;
}

虽然glutSolidX函数类型在此示例中运行良好(基于Lightouse3D教程),但如何快速绘制在帧与帧之间更改坐标的三角形(我尝试了数组和 GL_DYNAMIC_DRAW,但与旧的“固定管道”相比,这工作量太大了“ 方法)。我看到其他人仍然glBegin(..); glEnd();成功地使用带有 GLSL 着色器的块,所以这一定是可能的。可能缺少什么?

4

1 回答 1

5

The coordinates of the vertices of the triangle in the glBegin/glEnd block are

 11, 0,  0
-11, 0,  0
  0, 0, 11

which means it lies completely flat in the view. This is like viewing a sheet of paper from such a hard angle, it becomes a line. Because triangles have no thickness, not even this line is drawn and the triangle seems invisible.

于 2012-06-28T08:56:44.110 回答