4 from OpenGL.GL import *
\r
14 class VertexArray(object):
\r
15 def __init__(self, vertices):
\r
16 self.vertices=vertices
\r
19 return "<VertexArray %d>" % len(self.vertices)
\r
23 glEnableClientState(GL_VERTEX_ARRAY)
\r
24 glVertexPointer(3, GL_FLOAT, 0, self.vertices)
\r
26 glDrawArrays(GL_TRIANGLES, 0, len(self.vertices))
\r
28 glDisableClientState(GL_VERTEX_ARRAY)
\r
41 class VertexArrayWithUV(object):
\r
42 def __init__(self, vertices, uvarray):
\r
43 self.vertices=vertices
\r
44 self.uvarray=uvarray
\r
47 return "<VertexArrayWithUV %d>" % len(self.vertices)
\r
51 glEnableClientState(GL_VERTEX_ARRAY)
\r
52 glVertexPointer(3, GL_FLOAT, 0, self.vertices)
\r
54 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
\r
55 glTexCoordPointer(2, GL_FLOAT, 0, self.uvarray)
\r
57 triangle_count=int(len(self.vertices)/3)
\r
58 glDrawArrays(GL_TRIANGLES, 0, triangle_count)
\r
60 glDisableClientState(GL_TEXTURE_COORD_ARRAY)
\r
61 glDisableClientState(GL_VERTEX_ARRAY)
\r
72 class IndexedVertexArray(object):
\r
73 def __init__(self, vertices, indices):
\r
74 self.vertices=vertices
\r
75 self.indices=indices
\r
79 glEnableClientState(GL_VERTEX_ARRAY)
\r
80 glVertexPointer(3, GL_FLOAT, 0, self.vertices)
\r
82 glDrawElements(GL_TRIANGLES, len(self.indices),
\r
83 GL_UNSIGNED_INT, self.indices)
\r
85 glDisableClientState(GL_VERTEX_ARRAY)
\r
97 class IndexedVertexArrayWithColor(object):
\r
98 def __init__(self, vertices, colors, indices):
\r
99 self.vertices=vertices
\r
101 self.indices=indices
\r
105 glEnableClientState(GL_VERTEX_ARRAY)
\r
106 glVertexPointer(3, GL_FLOAT, 0, self.vertices)
\r
108 glEnableClientState(GL_COLOR_ARRAY)
\r
109 glColorPointer(3, GL_FLOAT, 0, self.colors)
\r
111 glDrawElements(GL_TRIANGLES, len(self.indices),
\r
112 GL_UNSIGNED_INT, self.indices)
\r
114 glDisableClientState(GL_COLOR_ARRAY)
\r
115 glDisableClientState(GL_VERTEX_ARRAY)
\r