About ads on Siafoo
Hide Siafoo is here to make coding less frustrating and to save you time. Learn More Join Siafoo

PyOpenGL Vertex Buffer Object (VBO) utility class

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.
Language Python
# '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.

Keywords OpenGL (12) PyOpenGL (6) VBO (1) Vertex Buffer Object (1)
Included in these Libraries
Average
n/a
Rated
0
Times
5
4
3
2
1
0
License New BSD license
Lines 32
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Sponsored Links
About ads on Siafoo