Пример #1
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)
Пример #2
0
vao = GL.NewVertexArray(prog, vbo, '3f1f', ['vert', 'diffuse'])

nodes = [GL.NewFramebuffer(256, 256) for i in range(6)]

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()