简体   繁体   中英

GLSL and glBegin(GL_TRIANGLES) not working

This code only renders a dodecahedron and completely ignores the glBegin(GL_TRIANGLES) block:

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

The two shaders are quite simplistic:

the vertex shader:

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

and the frag:

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

While glutSolidX type of functions work well with this example (based on the Lightouse3D tutorial), how can one quickly draw triangles that change coordinates from frame to frame (I tried arrays and GL_DYNAMIC_DRAW, but that's too much work as compared to the old "fixed pipeline" approach). I saw other people still managing to use glBegin(..); glEnd(); glBegin(..); glEnd(); blocks with GLSL shaders successfully, so it must be possible. What could be missing?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM