License New BSD license
Lines 32
Keywords
OpenGL (15) PyOpenGL (9) VBO (1) Vertex Buffer Object (1)
Included in these Libraries
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Need a quick chart or graph for your blog? Try our reStructured Text renderer. Join Siafoo Now or Learn More

PyOpenGL Vertex Buffer Object (VBO) utility class Atom Feed 0

In Brief A python object for using OpenGL Vertex Buffer Objects with PyOpenGL. It supports NumPy arrays and takes care of all the craziness related to coercing the data into OpenGL buffers.
# 's
 1from OpenGL.GL import *
2from OpenGL.raw import GL
3from OpenGL.arrays import ArrayDatatype as ADT
4
5
6class VertexBuffer(object):
7
8 def __init__(self, data, usage):
9 self.buffer = GL.GLuint(0)
10 glGenBuffers(1, self.buffer)
11 self.buffer = self.buffer.value
12 glBindBuffer(GL_ARRAY_BUFFER_ARB, self.buffer)
13 glBufferData(GL_ARRAY_BUFFER_ARB, ADT.arrayByteCount(data), ADT.voidDataPointer(data), usage)
14
15 def __del__(self):
16 glDeleteBuffers(1, GL.GLuint(self.buffer))
17
18 def bind(self):
19 glBindBuffer(GL_ARRAY_BUFFER_ARB, self.buffer)
20
21 def bind_colors(self, size, type, stride=0):
22 self.bind()
23 glColorPointer(size, type, stride, None)
24
25 def bind_edgeflags(self, stride=0):
26 self.bind()
27 glEdgeFlagPointer(stride, None)
28
29 def bind_indexes(self, type, stride=0):
30 self.bind()
31 glIndexPointer(type, stride, None)
32
33 def bind_normals(self, type, stride=0):
34 self.bind()
35 glNormalPointer(type, stride, None)
36
37 def bind_texcoords(self, size, type, stride=0):
38 self.bind()
39 glTexCoordPointer(size, type, stride, None)
40
41 def bind_vertexes(self, size, type, stride=0):
42 self.bind()
43 glVertexPointer(size, type, stride, None)

A python object for using OpenGL Vertex Buffer Objects with PyOpenGL. It supports NumPy arrays and takes care of all the craziness related to coercing the data into OpenGL buffers.