In advance, I am a really newbie concerning OpenGL but I’ve not found any documentation on my question. That’s why I registered here. Hope you can help me out
I am coding my first OpenGL programm and want to visualize some bending beams. I am using VBOs to construct my beams.
Currently I use
1 VBO for Vertex Positions
1 VBO for Colours
1 VBO for Indices
I use the VBO for Indices to minimize the amount of vertices. For example, I would draw a cube with only 8 vertices and use the index vbo for generating the triangle strip by using correct indices.
This works fine for me, in wireframe. Now i want to add lighnting and setup a new VBO with the normals. I filled it with the normal vectors for each face, however lightning is not correctly rendered.
For drawing I use
glDrawElements(GL_TRIANGLE_STRIP, 34*10+8, GL_UNSIGNED_INT, 0);
I have the feeling, that my normals are applied to the vertices, not the triangles.
- What can I do to use VBOs to apply the normals onto my triangles?
- I want to keep the amount of vertices minimal and still use my index VBO. Is this possible?
Thanks and kind regards,
You have to specify a normal for each vertex in your VBO, that’s how vertex arrays work when using an index.
The value of each normal for the 3 verticies which make up a triange will probably be the same value as they are all on the same face/plane.
Considering a simple cube currently I use 8 vertices (Wireframe) which I connect with indices.
When adding normals (=lighning), would I now need
12 Triangle-Strips -> 3*12 = 36 Vertices ?
Did I understand correctly?
I make it that you need 24.
Each surface of the cube is 4 verticies & normals. There are 6 faces of a cube, so that’s 6*4=24 uniquie vertex/Normals in total.
You then need to split this up into trangles, which is where your indices come into play. For each face of the cube you would render two triangles and you can re-use the same vertex/normal pairs by re-specifiying them in your indices list.
It just made “click”. Thx alot for ur answers
One final question: Could i also use a cg fragment program to compute the normals of my triangle strip without using a normals vbo?
(also doing the lightning stuff with a cg fragment program)
To calculate the normal for flat shading (which is what you want for a box with sharp edges) you need to know the whole triangle, that information is available in the geometry shader but not in the fragment shader. So you could leave out the normal buffer but you would need a GS.
Thanks again to all of you!
I now chose to use GL_quads because of it’s easyness. 4 vertex/normals pairs per face.
As a result, my VBOs now drastically increased in size but it does not really seem too matter, even if I draw many thousands of them.
With the normals available, I could also realize the lightning stuff in my cg vertex programs which I already used for animation.
Thanks again, ur help is really appreciated.