Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
	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)
Exemplo n.º 3
0
vao = GL.NewVertexArray(grass_prog, vbo, '3f3f3f1f1f',
                        ['vert', 'direction', 'color', 'thickness', 'power'],
                        ibo)

ssao_vbo = GL.NewVertexBuffer(
    struct.pack('8f', 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0))
ssao_vao = GL.NewVertexArray(ssao_prog, ssao_vbo, '2f', ['vert'])

ubo = GL.NewUniformBuffer(b''.join(struct.pack('2f', x, y) for x, y in kernel))

fbo, color, depth = GL.NewFramebuffer()

GL.SetUniform(grass_prog['mat'], struct.pack('16f', *camera))
GL.SetUniform(ssao_prog['texture'], 0)
GL.SetUniform(ssao_prog['depth'], 1)

GL.UseUniformBuffer(ubo, ssao_prog['Kernel'])

while WND.Update():
    GL.UseFramebuffer(fbo)
    GL.EnableDepthTest()
    GL.Clear(0, 0, 0)

    GL.RenderTriangleStrip(vao, 1000 * 8)

    GL.UseFramebuffer(GL.SCREEN)
    GL.DisableDepthTest()
    GL.UseTexture(color, 0)
    GL.UseTexture(depth, 1)
    GL.RenderTriangleStrip(ssao_vao, 4)
Exemplo n.º 4
0
GL.RenderLineStrip()
GL.RenderLines()
GL.RenderPoints()
GL.RenderTriangleFan()
GL.RenderTriangleStrip()
GL.RenderTriangles()

GL.RenderLinesAdjacency()
GL.RenderLineStripAdjacency()
GL.RenderTrianglesAdjacency()
GL.RenderTriangleStripAdjacency()

GL.SetTextureFiltered()
GL.SetTextureMipmapped()
GL.SetTexturePixelated()
GL.SetUniform()
GL.SetUniformMatrix()

# GL.UpdateIndexBuffer()
# GL.UpdateTexture()
# GL.UpdateUniformBuffer()
# GL.UpdateVertexBuffer()

GL.UseDefaultFramebuffer()
GL.UseFramebuffer()
GL.UseTexture()
GL.UseTextureAsImage()
GL.UseUniformBuffer()

GL.Viewport()