def test_create_cube(self): v, i = geometry.create_cube() expected_v = np.array([ [ 0.5, 0.5, 0.5], [-0.5, 0.5, 0.5], [-0.5, -0.5, 0.5], [ 0.5, -0.5, 0.5], [ 0.5, 0.5, -0.5], [ 0.5, 0.5, 0.5], [ 0.5, -0.5, 0.5], [ 0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [ 0.5, 0.5, -0.5], [ 0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, 0.5, 0.5], [-0.5, 0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, 0.5], [ 0.5, 0.5, -0.5], [-0.5, 0.5, -0.5], [-0.5, 0.5, 0.5], [ 0.5, 0.5, 0.5], [ 0.5, -0.5, 0.5], [-0.5, -0.5, 0.5], [-0.5, -0.5, -0.5], [ 0.5, -0.5, -0.5] ]) expected_i = np.array([ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 ]) self.assertTrue(np.array_equal(v, expected_v), (v,)) self.assertTrue(np.array_equal(i, expected_i), (i,))
0.0, 1.0, ), ( 1.0, 1.0, 0.0, ), ( 1.0, 0.0, 0.0, ), ) vertices, indices = geometry.create_cube(scale=(2.0, 2.0, 2.0), rgba=rgba, dtype='float32') vertices = vertices[indices] vertices.dtype = [ ('position', 'float32', (3, )), ('colour', 'float32', (3, )), ] def create(core_profile=True): if core_profile: return CoreCube() else: return LegacyCube()
import textwrap import numpy from OpenGL import GL from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute, ColourAttribute from pygly.vertex_array import VertexArray from pyrr import geometry rgba = ((0.0, 1.0, 0.0), (1.0, 0.5, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 0.0), (1.0, 0.0, 0.0)) vertices, indices = geometry.create_cube(scale=(2.0, 2.0, 2.0), rgba=rgba, dtype="float32") vertices = vertices[indices] vertices.dtype = [("position", "float32", (3,)), ("colour", "float32", (3,))] def create(core_profile=True): if core_profile: return CoreCube() else: return LegacyCube() class CoreCube(object): vertex_shader = textwrap.dedent( """ #version 150 // input
import textwrap import numpy from OpenGL import GL from pygly.shader import Shader, VertexShader, FragmentShader, ShaderProgram from pygly.vertex_buffer import VertexBuffer, BufferAttributes, GenericAttribute, VertexAttribute from pygly.vertex_array import VertexArray from pyrr import geometry vertices, indices = geometry.create_cube(scale=(2.0,2.0,2.0), dtype='float32') vertices = vertices[indices] vertices.dtype = [('position', 'float32', (3,)),] def create( core_profile = True ): if core_profile: return CoreColourCube() else: return LegacyColourCube() class CoreColourCube( object ): vertex_shader = textwrap.dedent( """ #version 150 // input in vec3 in_position; uniform mat4 model_view;