Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: VBOs and Normals

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    5

    VBOs and Normals

    Hi!

    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,
    roland

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: VBOs and Normals

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    5

    Re: VBOs and Normals

    Thanks BionicBytes

    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?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: VBOs and Normals

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    5

    Re: VBOs and Normals

    @BionicBytes

    It just made "click". Thx alot for ur answers

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    5

    Re: VBOs and Normals

    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)

  7. #7
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302

    Re: VBOs and Normals

    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.

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    5

    Re: VBOs and Normals

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •