Search code examples
c++openglshadervertex-shader

OpenGL glVertexAttribPointer normal


Let's say I am rendering a 3d GL_TRIANGLE. The object requires 3 vertices for it to be defined: A,B,C. I place such data into a buffer and bind it to the shader through glVertexAttribPointer.

Now I want to pass in the normal to the shader. For every triangle there should be 1 normal vector but if I try to pass it in through a glVertexAttribPointer, I would need to define the same normal 3 times for points A,B,C. Is it possible to pass in 1 vertex every 3 other vertices in a glVertexAttribPointer to avoid this?

Or is it a good idea to pass it in for all vertices?


Solution

  • Now I want to pass in the normal to the shader. For every triangle there should be 1 normal vector

    No, there are 3 normals. One for each vertex.

    Is it possible to pass in 1 vertex every 3 other vertices in a glVertexAttribPointer to avoid this?

    No, because vertex attributes belong together and can not be separated.

    Or is it a good idea to pass it in for all vertices?

    Definitely. Makes life much easier for everybody.