コード例 #1
0
        # Using GLFW to check for input events
        glfw.poll_events()

        # Filling or not the shapes depending on the controller state
        if controller.fillPolygon:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Create projection
        # projection = tr2.ortho(-1, 1, -1, 1, 0.1, 100)
        projection = tr.perspective(45, float(width) / float(height), 0.1, 100)

        # Get camera view matrix
        view = camera.get_view()

        # Place light
        obj_light.place()

        # Draw objects
        obj_axis.draw(view, projection, mode=GL_LINES)
        obj_cylinder.draw(view, projection)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen
        glfw.swap_buffers(window)

    glfw.terminate()
コード例 #2
0
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT)

        theta = glfw.get_time()
        tx = 0.7 * np.sin(0.5 * theta)
        ty = 0.2 * np.sin(5 * theta)

        # Derivative of tx give us the direction
        dtx = 0.7 * 0.5 * np.cos(0.5 * theta)
        if dtx > 0:
            reflex = tr.scale(-1, 1, 1)
        else:
            reflex = tr.identity()

        # Create booObj transformation
        booT = tr.matmul(
            [tr.translate(tx, ty, 0),
             tr.scale(0.5, 0.5, 1.0), reflex])
        obj_boo.apply_temporal_transform(booT)

        # Draw shapes
        obj_boo.draw()
        obj_question.draw()

        # Once the render is done, buffers are swapped, showing only the complete scene.
        glfw.swap_buffers(window)

    glfw.terminate()
コード例 #3
0
                      np.array([0, 0, 1]))

    # Mainloop
    while not glfw.window_should_close(window):

        # Using GLFW to check for input events
        glfw.poll_events()

        # Filling or not the shapes depending on the controller state
        if controller.fillPolygon:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        clear_buffer()

        theta = glfw.get_time()
        axis = np.array([1, -1, 1])
        axis = axis / np.linalg.norm(axis)
        obj_cube.apply_temporal_transform(tr.rotation_a(theta, axis))

        # Draw objects
        obj_axis.draw(view, projection)
        obj_cube.draw(view, projection)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
        glfw.swap_buffers(window)

    glfw.terminate()
コード例 #4
0
ファイル: ex_3dplot.py プロジェクト: ppizarror/glfw-toolbox
    # Mainloop
    while not glfw.window_should_close(window):

        # Using GLFW to check for input events
        glfw.poll_events()

        # Filling or not the shapes depending on the controller state
        if controller.fillPolygon:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        clear_buffer()

        # Get camera view matrix
        view = camera.get_view()

        # Place light
        obj_light.place()

        # Draw objects
        obj_axis.draw(view, projection, mode=GL_LINES)
        obj_main.draw(view, projection)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen
        glfw.swap_buffers(window)

    glfw.terminate()
コード例 #5
0
ファイル: ex_cube.py プロジェクト: ppizarror/glfw-toolbox
    cube = AdvancedGPUShape(gpuCube, shader=colorShaderProgram)

    # Mainloop
    while not glfw.window_should_close(window):

        # Using GLFW to check for input events
        glfw.poll_events()

        # Filling or not the shapes depending on the controller state
        if controller.fillPolygon:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        theta = glfw.get_time()
        Rx = tr.rotation_x(np.pi / 3)
        Ry = tr.rotation_y(theta)
        transform = np.matmul(Rx, Ry)

        # Drawing the Cube
        cube.apply_temporal_transform(transform)
        cube.draw(transform)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
        glfw.swap_buffers(window)

    glfw.terminate()
コード例 #6
0
ファイル: ex_mouse.py プロジェクト: ppizarror/glfw-toolbox
        # Using GLFW to check for input events
        glfw.poll_events()

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT)

        # While left click is pressed, we have continous rotation movement
        if controller.leftClickOn:
            controller.theta += 4 * dt
            if controller.theta >= 2 * np.pi:
                controller.theta -= 2 * np.pi

        # Drawing the rotating red quad
        obj_quad_red.apply_temporal_transform(tr.rotation_z(controller.theta))
        obj_quad_red.draw()

        # Getting the mouse location in opengl coordinates
        mousePosX = 2 * (controller.mousePos[0] - width / 2) / width
        mousePosY = 2 * (height / 2 - controller.mousePos[1]) / height

        # Draw green quad
        obj_quad_green.apply_temporal_transform(
            np.matmul(tr.uniform_scale(0.5),
                      tr.translate(mousePosX, mousePosY, 0)))
        obj_quad_green.draw()

        # This is another way to work with keyboard inputs
        # Here we request the state of a given key
        if glfw.get_key(window, glfw.KEY_LEFT_CONTROL) == glfw.PRESS:
            obj_quad_blue.apply_temporal_transform(
コード例 #7
0
ファイル: ex_curves.py プロジェクト: ppizarror/glfw-toolbox
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Create projection
        # projection = tr2.ortho(-1, 1, -1, 1, 0.1, 100)
        projection = tr2.perspective(45,
                                     float(width) / float(height), 0.1, 100)

        # Get camera view matrix
        view = camera.get_view()

        # Update target cube object
        t = tr2.translate(camera.get_center_x(), camera.get_center_y(),
                          camera.get_center_z())
        obj_camTarget.apply_temporal_transform(t)

        # Draw objects
        obj_axis.draw(view, projection, mode=GL_LINES)
        obj_camTarget.draw(view, projection)
        obj_planeL.draw(view, projection)
        obj_planeR.draw(view, projection)
        obj_planeS.draw(view, projection)
        obj_planeB.draw(view, projection)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen
        glfw.swap_buffers(window)

    glfw.terminate()