PDA

View Full Version : VBO vertices colors using shaders



avstenit
12-03-2013, 05:50 AM
I am displaying a geometry (file format: .stl) with OpenGL (PyOpenGL and Python). Geometry data has the form (http://en.wikipedia.org/wiki/STL_%28file_format%29)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:


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:


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:

create separate VBO for vertices, VBO for normals and VBO for colors
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).
1191

tonyo_au
12-03-2013, 03:13 PM
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.

avstenit
12-07-2013, 06:48 AM
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!

tonyo_au
12-08-2013, 03:44 PM
I have not used VBOs without shaders but I think it should work.

avstenit
12-09-2013, 11:56 PM
I have not used VBOs without shaders but I think it should work.
Thanks for the answer. :)