def initializeGL(self): try: GL.Init() GL.Viewport(0, 0, context['width'], context['height']) vert = GL.NewVertexShader(''' #version 330 in vec2 vert; out vec2 tex_coord; uniform vec2 scale; uniform float rotation; void main() { mat2 rot = mat2(cos(rotation), sin(rotation), -sin(rotation), cos(rotation)); gl_Position = vec4((rot * vert) * scale, 0.0, 1.0); tex_coord = vert; } ''') frag = GL.NewFragmentShader(''' #version 330 uniform sampler2D texture; in vec2 tex_coord; out vec4 color; void main() { color = vec4(texture2D(texture, tex_coord).rgb, 1.0); } ''') prog = GL.NewProgram([vert, frag]) context['rotation'] = prog['rotation'] vbo = GL.NewVertexBuffer( struct.pack('6f', 1.0, 0.0, -0.5, 0.86, -0.5, -0.86)) context['vao'] = GL.NewVertexArray(prog, vbo, '2f', ['vert']) GL.SetUniform(prog['scale'], context['height'] / context['width'] * 0.75, 0.75) tex = GL.NewTexture(256, 256, Image.open('../DataFiles/Noise.jpg').tobytes()) GL.UseTexture(tex) except GL.Error as error: print(error) exit(1)
in vec2 tex_coord; out vec4 color; void main() { color = vec4(texture2D(texture, tex_coord).rgb, 1.0); } ''') prog = GL.NewProgram([vert, frag]) vbo = GL.NewVertexBuffer(struct.pack('6f', 1.0, 0.0, -0.5, 0.86, -0.5, -0.86)) vao = GL.NewVertexArray(prog, vbo, '2f', ['vert']) GL.SetUniform(prog['scale'], height / width * 0.75, 0.75) tex = GL.NewTexture(256, 256, Image.open('../DataFiles/Noise.jpg').tobytes()) GL.UseTexture(tex) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False GL.Clear(240, 240, 240) GL.SetUniform(prog['rotation'], time.time() - start) GL.RenderTriangles(vao, 3) pygame.display.flip() pygame.time.wait(10)
GL.DisableMultisample() GL.EnableBlend() GL.EnableCullFace() GL.EnableDepthTest() GL.EnableMultisample() GL.NewAdvancedVertexArray() GL.NewFragmentShader() GL.NewFramebuffer() GL.NewGeometryShader() GL.NewIndexBuffer() GL.NewProgram() GL.NewTessControlShader() GL.NewTessEvaluationShader() GL.NewTexture() GL.NewUniformBuffer() GL.NewVertexArray() GL.NewVertexBuffer() GL.NewVertexShader() GL.ReadPixel() GL.ReadPixels() GL.ReadDepthPixel() GL.ReadDepthPixels() GL.ReadStorageBuffer() GL.RenderLineLoop() GL.RenderLineStrip()