def test_create_quad_rgba_values(self): v, i = geometry.create_quad(rgba=((0.1,0.2,0.3,0.4),(0.5,0.6,0.7,0.8),(0.9,1.0,1.1,1.2),(1.3,1.4,1.5,1.6))) expected_v = np.array([ [ 0.5, 0.5, 0., .1, .2, .3, .4], [-0.5, 0.5, 0., .5, .6, .7, .8], [-0.5,-0.5, 0., .9, 1., 1.1, 1.2], [ 0.5,-0.5, 0., 1.3, 1.4, 1.5, 1.6], ]) expected_i = np.array([0,1,2,0,2,3]) self.assertTrue(np.allclose(v, expected_v), (v,)) self.assertTrue(np.array_equal(i, expected_i))
def test_create_quad_rgba(self): v, i = geometry.create_quad(rgba=True) expected_v = np.array([ [ 0.5, 0.5, 0., 1., 1., 1., 1.], [-0.5, 0.5, 0., 1., 1., 1., 1.], [-0.5,-0.5, 0., 1., 1., 1., 1.], [ 0.5,-0.5, 0., 1., 1., 1., 1.], ]) expected_i = np.array([0,1,2,0,2,3]) self.assertTrue(np.allclose(v, expected_v), (v,)) self.assertTrue(np.array_equal(i, expected_i))
def test_create_quad_scale(self): v, i = geometry.create_quad((2.0,0.5)) expected_v = np.array([ [ 1., 0.25, 0.], [-1., 0.25, 0.], [-1.,-0.25, 0.], [ 1.,-0.25, 0.], ]) expected_i = np.array([0,1,2,0,2,3]) self.assertTrue(np.allclose(v, expected_v), (v,)) self.assertTrue(np.array_equal(i, expected_i))
def test_create_quad_st_values(self): v, i = geometry.create_quad(st=((0.1,0.2),(0.3,0.4))) expected_v = np.array([ [ 0.5, 0.5, 0., 0.3, 0.4], [-0.5, 0.5, 0., 0.1, 0.4], [-0.5,-0.5, 0., 0.1, 0.2], [ 0.5,-0.5, 0., 0.3, 0.2], ]) expected_i = np.array([0,1,2,0,2,3]) self.assertTrue(np.allclose(v, expected_v), (v,)) self.assertTrue(np.array_equal(i, expected_i))
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, TextureCoordAttribute from pygly.vertex_array import VertexArray from pyrr import geometry vertices, indices = geometry.create_quad(scale=(5.0,5.0), st=True, dtype='float32') vertices = vertices[indices] vertices.dtype = [ ('position', 'float32', (3,)), ('texture_coord', 'float32', (2,)), ] def create( core_profile = True ): if core_profile: return CoreQuad() else: return LegacyQuad() class CoreQuad( object ): vertex_shader = textwrap.dedent( """ #version 150