-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to break up opengl/CyOpenGL.pyx into smaller pieces.
- Loading branch information
1 parent
cb85f9e
commit 01383f4
Showing
2 changed files
with
48 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
cdef class Triangle: | ||
""" | ||
A triangle with given vertices. | ||
""" | ||
|
||
cdef _gl_widget | ||
cdef _program | ||
cdef _vertex_buffer | ||
|
||
def __init__(self, gl_widget, program, vertices): | ||
""" | ||
Constructed from GL widget, GLSLProgram and vertices | ||
such as [[0,0,0],[1,1,0],[0,1,1]]. | ||
""" | ||
|
||
self._gl_widget = gl_widget | ||
self._program = program | ||
self._vertex_buffer = VertexBuffer() | ||
self._vertex_buffer.load(vertices) | ||
|
||
def draw(self, view_width, view_height): | ||
""" | ||
Draw the object (given size of viewport) by binding | ||
the program and the uniforms and calling draw_impl() which | ||
is implemented by some subclass. | ||
""" | ||
|
||
self._program.use_program() | ||
self._program.bind_uniforms( | ||
self.get_uniform_bindings(view_width, view_height)) | ||
|
||
self._vertex_buffer.bind() | ||
|
||
# Draw the triangle | ||
glDrawArrays(GL_TRIANGLES, 0, 3) | ||
|
||
def delete_resource(self): | ||
self._vertex_buffer.delete_resource() | ||
self._program.delete_resource() | ||
|
||
def get_uniform_bindings(self, view_width, view_height): | ||
""" | ||
Override to bind the uniforms you want. | ||
Arguments are size of viewport. | ||
""" | ||
|
||
return self._gl_widget.get_uniform_bindings(view_width, view_height) |