def test_init(self): a = gl.Buffer() self.assertNotEqual(a.id, 0) self.assertEqual(a.target_hint, gl.Buffer.TargetHint.ARRAY) b = gl.Buffer(gl.Buffer.TargetHint.ELEMENT_ARRAY) self.assertNotEqual(b.id, 0) self.assertEqual(b.target_hint, gl.Buffer.TargetHint.ELEMENT_ARRAY)
def __init__(self): configuration = self.Configuration() configuration.title = "Magnum Python Textured Triangle Example" Application.__init__(self, configuration) buffer = gl.Buffer() buffer.set_data(array.array('f', [ -0.5, -0.5, 0.0, 0.0, 0.5, -0.5, 1.0, 0.0, 0.0, 0.5, 0.5, 1.0 ])) self._mesh = gl.Mesh() self._mesh.count = 3 self._mesh.add_vertex_buffer(buffer, 0, 4*4, TexturedTriangleShader.POSITION) self._mesh.add_vertex_buffer(buffer, 2*4, 4*4, TexturedTriangleShader.TEXTURE_COORDINATES) importer = trade.ImporterManager().load_and_instantiate('TgaImporter') importer.open_file(os.path.join(os.path.dirname(__file__), '../textured-triangle/stone.tga')) image = importer.image2d(0) self._texture = gl.Texture2D() self._texture.wrapping = gl.SamplerWrapping.CLAMP_TO_EDGE self._texture.minification_filter = gl.SamplerFilter.LINEAR self._texture.magnification_filter = gl.SamplerFilter.LINEAR self._texture.set_storage(1, gl.TextureFormat.RGB8, image.size) self._texture.set_sub_image(0, Vector2i(), image) # or self._shader = shaders.Flat2D(shaders.Flat2D.Flags.TEXTURED) self._shader = TexturedTriangleShader()
def test_add_buffer(self): buffer = gl.Buffer() buffer_refcount = sys.getrefcount(buffer) # Adding a buffer to the mesh should increase its ref count mesh = gl.Mesh() mesh.add_vertex_buffer(buffer, 0, 8, gl.Attribute(gl.Attribute.Kind.GENERIC, 2, gl.Attribute.Components.TWO, gl.Attribute.DataType.FLOAT)) self.assertEqual(len(mesh.buffers), 1) self.assertIs(mesh.buffers[0], buffer) self.assertEqual(sys.getrefcount(buffer), buffer_refcount + 1) # Deleting the mesh should decrease it again del mesh self.assertEqual(sys.getrefcount(buffer), buffer_refcount)
def test_set_index_buffer(self): buffer = gl.Buffer() buffer_refcount = sys.getrefcount(buffer) # Adding a buffer to the mesh should increase its ref count mesh = gl.Mesh() self.assertEqual(mesh.is_indexed(), False) mesh.set_index_buffer(buffer, 0, MeshIndexType.UNSIGNED_SHORT, 0, 2) self.assertEqual(mesh.is_indexed(), True) self.assertEqual(sys.getrefcount(buffer), buffer_refcount + 1) # Deleting the mesh should decrease it again del mesh self.assertEqual(sys.getrefcount(buffer), buffer_refcount)
def __init__(self): configuration = self.Configuration() configuration.title = "Magnum Python Triangle Example" Application.__init__(self, configuration) buffer = gl.Buffer() buffer.set_data( array.array('f', [ -0.5, -0.5, 1.0, 0.0, 0.0, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0, 0.5, 0.0, 0.0, 1.0 ])) self._mesh = gl.Mesh() self._mesh.count = 3 self._mesh.add_vertex_buffer(buffer, 0, 5 * 4, shaders.VertexColor2D.POSITION) self._mesh.add_vertex_buffer(buffer, 2 * 4, 5 * 4, shaders.VertexColor2D.COLOR3) self._shader = shaders.VertexColor2D()
def test_set_data_array(self): a = gl.Buffer() a.set_data(array.array('f', [0.5, 1.2]))
def test_set_data(self): a = gl.Buffer() a.set_data(b'hello', gl.BufferUsage.STATIC_DRAW)