着色器中glNormal3fv的等价物是什么?

时间:2017-02-09 12:28:16

标签: opengl glsl shader normals

感谢您花时间阅读本文。 我正在修改我的OpenGL应用程序以使用GLSL着色器,其目的是使用GL_TRIANGLES可视化3D原子模型,包括四面体(和其他多面体)。

注意:在下面的示例中,颜色和alpha通道是相同的。

我之前:

void triangle (GLFloat * va, GLFloat * vb, GLFloat * vc)
{
   glVertex3fv (va);
   glVertex3fv (vb);
   glVertex3fv (vc);
}
void tetra (GLFloat ** xyz)
{
  // xyz Contains the coordinates of the triangles
  // ie. the 4 peaks of the tetrahedra
  // bellow 'get_normal' compute the normals
  glBegin (GL_TRIANGLES);
  glNormal3fv (get_normal(xyz[0], xyz[1], xyz[2]));
  triangle (xyz[0], xyz[1], xyz[2]);
  glNormal3fv (get_normal(xyz[1], xyz[2], xyz[3]));
  triangle (xyz[1], xyz[2], xyz[3]);
  glNormal3fv (get_normal(xyz[2], xyz[3], xyz[0]));
  triangle (xyz[2], xyz[3], xyz[0]);
  glNormal3fv (get_normal(xyz[0], xyz[3], xyz[1]));
  triangle (xyz[0], xyz[3], xyz[1]);
  glEnd ();
}

显示(正确的结果):

First version of the code using glNormal3fv + glVertex3fv

然后我修改了代码以使用以下着色器:

#define GLSL(src) "#version 130\n" #src

const GLchar * vertex = GLSL(
  uniform mat4 viewMatrix;
  uniform mat4 projMatrix;
  in vec3 position;
  in float size;
  in vec4 color;
  out vec4 vert_color;
  void main()
  {
    vert_color = color;
    gl_Position = projMatrix * viewMatrix * vec4(position, 1.0);
  }
);

const GLchar * colors = GLSL(
  in vec4 vert_color;
  out vec4 vertex_color;
  void main()
  {
    vertex_color = vert_color;
  }
);

现在我得到了:

New version of the code using Vertex and Fragment shaders

所以很明显颜色/灯光有问题,我想我能理解如何纠正这个问题,我认为我必须使用几何着色器,但我不知道在哪里可以找到现在的信息如何/怎样做, 提前感谢您的帮助。

0 个答案:

没有答案