0
votes

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")  
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, 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)
# enable vertex array
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, v_stride, v_pointer)

# enable normal array 
glEnableClientState(GL_NORMAL_ARRAY)
glNormalPointer(GL_FLOAT, n_stride, n_pointer)

# enable color array 
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)

The geometry (vertices and normals) are drawn correctly (see figure below). I want to paint each vertex with different color but is not painting any colors? Any suggestions how to draw color of vertex with GL_TRIANGLES and calls to gl_DrawArrays() and glColorPointer? Do I have to use shaders or can this be done without shaders? If I understand correctly it can be done without using shaders. enter image description here

1

1 Answers

0
votes

Problem solved. The solution was to disable lighting and lights. But there is a new one. If I disable lights and lighting a model is painted in uniform color it looks like that normals are not used when drawing.

  • Left cube: vertex colors and lighting (and lights) disabled
  • Center cube: vertex colors are not shown, because lighting (and) lights are enabled
  • Right cube: uniform color of vertices and lighting (and lights) disabled

enter image description here

I would like to draw the center cube but with (uniform) color as the right cube. I would like to ask you how can this be achieved? I use interleaved VBO. Thanks for suggestions, as right now I am without them :)