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 5 of 5

Thread: VBO vertices colors using shaders

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    20

    VBO vertices colors using shaders

    I am displaying a geometry (file format: .stl) with OpenGL (PyOpenGL and Python). Geometry data has the form and is assembled from triangles. I save to VBO data of; vertices, normals and colors. As the normal is only defined per 3 vertices (triangle) and I define color vector for every vertex, the data in VBO has the form:
    Code :
    VBO = [v1x, v1y, v1z,...vNx, vNy, vNz,
              n1x, n1y, n1z,...nNx, nNy, nNz,
              R1, G1, B1,...RN, GN, BN]
    In words; first I save all vertices, then I "append" (use of glBufferSubData) all normals (number of normals is 3-times less then number of vertices and vertice's colors) and then I append color vectors of each vertex. I would like to know if this is good idea, as I have problems painting each vertex in different color. The code for drawing is:
    Code :
    glPushMatrix()
    glEnableClientState(GL_VERTEX_ARRAY)
    glVertexPointer(3, 
                    GL_FLOAT, 
                    0, 
                    None)
    glEnableClientState(GL_COLOR_ARRAY)
    glColorPointer(3,
                   GL_UNSIGNED_BYTE,
                   0,
                   self.data_size_vertices+self.data_size_normals)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vbo_id)     
    glDrawArrays(GL_TRIANGLES,
                 0,
                 self.N_vertices)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) # reset
    glDisableClientState(GL_COLOR_ARRAY)
    glDisableClientState(GL_VERTEX_ARRAY)
    glPopMatrix()
    I think I am having problems with glColorPointer(). Can someone point out the problem? I have also seen two more ways to save the data to VBO:
    1. create separate VBO for vertices, VBO for normals and VBO for colors
    2. one VBO but has the form: [v1, c1, v2, c2, v3, c3, n1, ....]

    Is any of this two a better solution (more common in practice)? And do I have to assign a normal of triangle to each vertex although it is the same (for 3 vertices that define a triangle)? As I would like to get the display as shown below (left: current state, middle: plan, right: ideal - the point is the shading of surfaces), I would like to ask you to give me some directions about how to achieve this (using shaders).
    Click image for larger version. 

Name:	combined.jpg 
Views:	49 
Size:	15.4 KB 
ID:	1191
    Last edited by avstenit; 12-03-2013 at 09:37 AM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    As far as I know you will get better caching if the 3 components (vertex,colour,normal) are kept together in the buffer. The main reason for splitting the normal away would be if your default render only uses the vertex and colour and occasionally you need all three.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    20
    Quote Originally Posted by tonyo_au View Post
    As far as I know you will get better caching if the 3 components (vertex,colour,normal) are kept together in the buffer. The main reason for splitting the normal away would be if your default render only uses the vertex and colour and occasionally you need all three.
    Thanks for reply. I am planing to use interleaved VBOs (vertex, normal, color) and hope this will work for me. Just one thing; if I use interleaved VBOs (vertex, normal, color) I can achive painting each vertex with different color and avoiding using shaders if I understand correctly?
    Thanks again!

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    I have not used VBOs without shaders but I think it should work.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    20
    Quote Originally Posted by tonyo_au View Post
    I have not used VBOs without shaders but I think it should work.
    Thanks for the answer.

Posting Permissions

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