python - Pyglet VBOs glVertexPointer -


i've used pyopengl long time, now, i've switched pyglet. pyglet more strict pyopengl, i'm learning it. i've written simple code using vbos render triangle(i've took base pyglet tutorial), doesn't works me.

it shoud render colored triangle, instead of, renders white triangle. wrong?

here's code:

from pyglet.gl import *  window = pyglet.window.window() glenableclientstate(gl_vertex_array) vertices = [     0,0,0,     window.width,0,0,     window.width,window.height,0]  colors=[1.0,0.0,0.0,         0.0,1.0,0.0,         0.0,0.0,1.0]  class vbo():     def __init__(self):         self.buffer=(gluint)(0)         glgenbuffers(1,self.buffer)     def data(self,data):         data_gl= (glfloat * len(data))(*data)         glbindbuffer(gl_array_buffer_arb, self.buffer)         glbufferdata(gl_array_buffer_arb, len(data)*4,                     data_gl, gl_static_draw)      def bind(self):         glbindbuffer(gl_array_buffer_arb, self.buffer)     def vertex(self):         self.bind()         glvertexpointer(3, gl_float, 0, 0)     def color(self):         self.bind()         glcolorpointer(3, gl_float, 0, 0)      vbo=vbo() vbo.data(vertices) color=vbo() color.data(colors)  @window.event def on_draw():     glclear(gl_color_buffer_bit)     glloadidentity()     vbo.vertex()     color.color()     gldrawarrays(gl_triangles, 0, len(vertices) // 2)  @window.event def on_resize(width, height):     glviewport(0, 0, width, height)     glmatrixmode(gl.gl_projection)     glloadidentity()     glortho(0, width, 0, height, -1, 1)     glmatrixmode(gl.gl_modelview)  pyglet.app.run() 

thanks in advance!

i able colors displayed adding following:

...  glclientstateenable(gl_color_array)   vbo=vbo() vbo.data(vertices) color=vbo() color.data(colors)  ... 

the embedded documentation pyglet singularly unhelpful, man page glcolorpointer quite clear in pointing out color arrays ignored gldrawarray until gl_color_array enabled via glclientstateenable.

triangle drawn colored vertices.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -