I am using (Python and PyOpenGL) interleaved VBO (vertex, normal, color) in the form:
Vx1, Vy1, Vz1, Nx1, Ny1, Nz1, R1, G1, B1, A1, Vx2...
VBO is generated with:
self.vbo_id = glGenBuffers (1)
glBindBuffer(GL_ARRAY_BUFFER, self.vbo_id)
# upload data to VBO
data = model_loader.Model_loader(filename = "geometry.STL")
vertices = data.vertices
normals = data.normals
self.N_vertices = len(vertices)
alpha = 1
color = np.array([[0.1, 0.1, 0.1, alpha]], dtype='float32')
colors = np.repeat(color, self.N_vertices, axis=0)
VBO_data = VBO_reshape.create_VBO_array(data.vertices, data.normals, colors, GL_primitive_type = "triangle", interleaved_type = "true")
VBO_size_bytes = arrays.ArrayDatatype.arrayByteCount(VBO_data)
glBufferData(GL_ARRAY_BUFFER,
VBO_size_bytes,
VBO_data, #vertices
GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER, self.vbo_id)
Geometry from VBO is drawn with the code:
v_pointer = ctypes.c_void_p(0)
n_pointer = ctypes.c_void_p(12)
c_pointer = ctypes.c_void_p(24)
v_stride = 40
n_stride = 40
c_stride = 40
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vbo_id)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3,
GL_FLOAT,
v_stride,
v_pointer)
glEnableClientState(GL_NORMAL_ARRAY)
glNormalPointer(GL_FLOAT,
n_stride,
n_pointer)
glEnableClientState(GL_COLOR_ARRAY)
glColorPointer(4,
GL_FLOAT,
c_stride,
c_pointer)
glDrawArrays(GL_TRIANGLES,
0,
self.N_vertices)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) # reset
glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY)
Normals are taken from the VBO correctly as the surfaces have shadows as can be seen from figure below. But I have problems with painting the each vertex (of triangle) with it’s own color although each vertex is assigned the different color. Any ideas where is the problem? Are function calls glDrawArrays and glColorPointer compatible?
[ATTACH=CONFIG]555[/ATTACH]