triangle = [ 0.0, 0.8, # A -0.6, -0.8, # B 0.6, -0.8 # C ] # We have to pack the floats packed_triangle = struct.pack('6f', *triangle) # Now lets create a vertex buffer "containing" our triangle vbo = GL.NewVertexBuffer(packed_triangle) # Now we will create a VertexArray and specify what vertex attributes will be used during the rendering # The first parameter is a program object used for rendering # The second parameter is a VertexBuffer holding information about the triangle # The third parameter is the format of a single vertex # Now we only define the position as 2 float x and y coordinate # Later we can define color normals or any other data used in the vertex shader. # The fourth parameter must be a list containing a vertex attribute name in the vertex shader vao = GL.NewVertexArray(prog, vbo, '2f', ['vert']) while WND.Update(): GL.Clear(240, 240, 240) # Render a triangle using 3 vertices (remember we have 6 floats 3 * 2f) # RenderTriangles will use the program assigned to vao # By default the specified attribues are enabled (for now we have a single "vert" attribute) GL.RenderTriangles(vao, 3)
0.0, 0.0, # B -0.5, 0.86, 0.0, 1.0, 0.0, # C -0.5, -0.86, 0.0, 0.0, 1.0, ] packed_triangle = struct.pack('15f', *triangle) vbo = GL.NewVertexBuffer(packed_triangle) vao = GL.NewVertexArray(prog, vbo, '2f3f', ['vert', 'vert_color']) width, height = WND.GetSize() while WND.Update(): GL.Clear(240, 240, 240) GL.SetUniform(prog['rotate'], WND.GetTime()) GL.SetUniform(prog['scale'], height / width * 0.75, 0.75) GL.RenderTriangles(vao, 3, instances=10)
def draw(self, *args): GL.Clear(240, 240, 240) GL.RenderTriangles(self.vao, 3)
def on_draw(): GL.Clear(240, 240, 240) GL.SetUniform(prog['rotation'], elapsed) GL.RenderTriangles(vao, 3)
def display(): GL.Clear(240, 240, 240) GL.RenderTriangles(vao, 3) glutSwapBuffers()
def paintGL(self): GL.Clear(240, 240, 240) GL.EnableOnly(GL.ENABLE_BLEND + GL.ENABLE_MULTISAMPLE) GL.SetUniform(context['rotation'], time.time() - context['start']) GL.RenderTriangles(context['vao'], 3, instances=10) self.update()
def display(): GL.Clear(240, 240, 240) GL.SetUniform(prog['rotation'], time.time() - start) GL.RenderTriangles(vao, 3) glutSwapBuffers()
def paintGL(self): GL.Clear(240, 240, 240) GL.SetUniform(context['rotation'], time.time() - context['start']) GL.RenderTriangles(context['vao'], 3) self.update()
def on_draw(): GL.Clear(240, 240, 240) GL.RenderTriangles(vao, 3)
enables = [ GL.ENABLE_BLEND, GL.ENABLE_CULL_FACE, GL.ENABLE_DEPTH_TEST, GL.ENABLE_BLEND + GL.ENABLE_DEPTH_TEST, GL.ENABLE_CULL_FACE + GL.ENABLE_BLEND, GL.ENABLE_BLEND + GL.ENABLE_DEPTH_TEST + GL.ENABLE_CULL_FACE, ] GL.Viewport(0, 0, 256, 256) for i, (fbo, color, depth) in enumerate(nodes): GL.UseFramebuffer(fbo) GL.Clear(*bg[i]) GL.EnableOnly(enables[i]) GL.RenderTriangles(vao, 18) for i, (fbo, color, depth) in enumerate(nodes): GL.UpdateTexture(color, i * 8 + 8, 8, 8, 8, b'\x00' * 256) GL.UpdateTexture(color, i * 8 + 8, 24, 8, 8, b'\xff' * 256) for i, (fbo, color, depth) in enumerate(nodes): GL.UseFramebuffer(fbo) Image.frombytes('RGB', (256, 256), GL.ReadPixels(0, 0, 256, 256, 3)).save('TestResults/c_%d.png' % i) pixels = b''.join(struct.pack('B', int(c * 255)) for c in struct.unpack('65536f', GL.ReadDepthPixels(0, 0, 256, 256))) Image.frombytes('L', (256, 256), pixels).save('TestResults/d_%d.png' % i) exit() GL.DisableBlend() GL.DisableCullFace()
def on_draw(): GL.Clear(240, 240, 240) GL.SetUniform(prog['rotation'], time.time() - start) GL.RenderTriangles(vao, 3)
def display(): GL.Clear(240, 240, 240) GL.EnableOnly(GL.ENABLE_BLEND + GL.ENABLE_MULTISAMPLE) GL.SetUniform(prog['rotation'], time.time() - start) GL.RenderTriangles(vao, 3, instances=10) glutSwapBuffers()
def paintGL(self): GL.Clear(240, 240, 240) if 'vao' in context: GL.RenderTriangles(context['vao'], 3)
def on_draw(): GL.Clear(240, 240, 240) GL.EnableOnly(GL.ENABLE_BLEND + GL.ENABLE_MULTISAMPLE) GL.SetUniform(prog['rotation'], elapsed) GL.RenderTriangles(vao, 3, instances=10)