Example #1
0
def setup():
    pyshaders.transpose_matrices(False)
    # One-time GL setup
    glClearColor(1, 1, 1, 1)
    glColor3f(1, 0, 0)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_CULL_FACE)

    # Uncomment this line for a wireframe view
    #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    # Simple light setup.  On Windows GL_LIGHT0 is enabled by default,
    # but this is not the case on Linux or Mac, so remember to always
    # include it.
    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glEnable(GL_LIGHT1)

    glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
    glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 1))
    glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
    glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0))
    glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1))
    glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1))

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1))
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
    return load_program()
Example #2
0
 def test_set_uniform_matrices_transpose(self):
     shader = from_files_names(vert_path('shader1'), frag_path('shader1'))
     uni = shader.uniforms
     shader.use()
     
     pyshaders.transpose_matrices(False)
     uni.test_mat2 = ((5.0, 8.0), (2.0, 4.0))
     self.assertEqual(((5.0, 2.0), (8.0, 4.0)), uni.test_mat2)
Example #3
0
def setup():
    # One-time GL setup
    pyshaders.transpose_matrices(False)

    glClearColor(1, 1, 1, 1)
    glColor3f(1, 0, 0)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_CULL_FACE)

    # Uncomment this line for a wireframe view
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    return load_program()
Example #4
0
def start():
    window = pyglet.window.Window(resizable=True)
    pyglet.gl.glEnable(pyglet.gl.GL_DEPTH_TEST)
    pyshaders.transpose_matrices(False)
    shader = pyshaders.from_string(vert, frag)
    shader.use()

    view = glm.lookAt(
        glm.vec3(1.2, 1.2, 1.2),
        glm.vec3(0, 0, 0),
        glm.vec3(0, 0, 1),
    )

    proj = glm.perspective(glm.radians(45), 800/600, 1, 10)

    pattern = pyglet.image.CheckerImagePattern()
    tex = pattern.create_image(64, 64).get_texture()
    textured = pyglet.graphics.TextureGroup(tex)

    batch = pyglet.graphics.Batch()

    batch.add(
        36, pyglet.gl.GL_TRIANGLES, textured,
        ("0g3f", cube(0, 0, 0)),
        ("1g2f", (0, 2, 0, 0, 2, 0, 0, 2, 2, 2, 2, 0) * 6)
    )

    t = 0

    def update(dt):
        nonlocal t
        m = glm.mat4(1)
        m = glm.rotate(m, t, (0, 0, 1))
        shader.uniforms.model = m
        shader.uniforms.view = view
        shader.uniforms.proj = proj

        t += dt

    pyglet.clock.schedule(update)

    @window.event()
    def on_draw():
        window.clear()
        batch.draw()
    def __init__(self):
        display = pyglet.canvas.get_display()
        config = display.get_default_screen().get_best_config(Config())
        config.major_version = 3
        config.minor_version = 3
        context = config.create_context(None)

        Window.__init__(self,
                        800,
                        600,
                        visible=False,
                        resizable=True,
                        caption='Tinyblend example',
                        context=context)

        self.vao = (GLuint * 1)()
        glGenVertexArrays(1, self.vao)
        glBindVertexArray(self.vao[0])

        # Load shaders
        shader = shaders.from_files_names('shaders/main.glsl.vert',
                                          'shaders/main.glsl.frag')
        shader.owned = False
        shader.use()
        shader.enable_all_attributes()
        self.shader = shader

        # Uniforms matrices setup
        self.rotation = [-90, 0, 0]
        self.position = [0, 0, -4.5]
        shaders.transpose_matrices(False)
        self.upload_uniforms()

        # Scene creation
        self.setup_scene()

        # Show the window
        self.set_visible()