예제 #1
0
def on_draw(dt):
    # Clear depth and color buffers
    gl.glClearColor(*C0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            
    # Opaque objects rendering
    gl.glDepthMask(gl.GL_TRUE)
    gl.glDisable(gl.GL_BLEND)
    
    # Transparent objects rendering
    gl.glDepthMask(gl.GL_FALSE)
    gl.glEnable(gl.GL_BLEND)
    framebuffer.activate()
    gl.glClearColor(0,0,0,1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    
    window.clear(color=(0,0,0,1))
    gl.glBlendFuncSeparate(gl.GL_ONE,  gl.GL_ONE,
                           gl.GL_ZERO, gl.GL_ONE_MINUS_SRC_ALPHA)
    scene.draw(gl.GL_TRIANGLES, indices)
    framebuffer.deactivate()
    
    # Compositing
    gl.glBlendFunc(gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_SRC_ALPHA)
    compose.draw(gl.GL_TRIANGLE_STRIP)
예제 #2
0
파일: renderer.py 프로젝트: CNchence/cp-net
def draw_depth(shape, vertex_buffer, index_buffer, mat_model, mat_view, mat_proj):

    program = gloo.Program(_depth_vertex_code, _depth_fragment_code)
    program.bind(vertex_buffer)
    program['u_mv'] = _compute_model_view(mat_model, mat_view)
    program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view, mat_proj)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4), np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]), np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_CULL_FACE)
    gl.glCullFace(gl.GL_BACK) # Back-facing polygons will be culled
    gl.glClearColor(0.0, 0.0, 0.0, 0.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    # Rendering
    program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    depth = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, depth)
    depth.shape = shape[0], shape[1], 4
    depth = depth[::-1, :]
    depth = depth[:, :, 0] # Depth is saved in the first channel

    fbo.deactivate()

    return depth
예제 #3
0
    def on_draw(dt):
        # window.clear()
        global rgb
        extent_shape = (int(shape[0] * ssaa), int(shape[1] * ssaa))
        # Frame buffer object
        color_buf = np.zeros((extent_shape[0], extent_shape[1], 4),
                             np.float32).view(gloo.TextureFloat2D)
        depth_buf = np.zeros((extent_shape[0], extent_shape[1]),
                             np.float32).view(gloo.DepthTexture)
        fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
        fbo.activate()

        # OpenGL setup
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glViewport(0, 0, extent_shape[1], extent_shape[0])

        gl.glDisable(gl.GL_CULL_FACE)
        program.draw(gl.GL_TRIANGLES, I)

        rgb = np.zeros((extent_shape[0], extent_shape[1], 4), dtype=np.float32)
        gl.glReadPixels(0, 0, extent_shape[1], extent_shape[0], gl.GL_RGBA,
                        gl.GL_FLOAT, rgb)
        rgb.shape = extent_shape[0], extent_shape[1], 4
        rgb = rgb[::-1, :]
        rgb = np.round(rgb[:, :, :3] * 255).astype(
            np.uint8)  # Convert to [0, 255]

        import cv2
        rgb = cv2.resize(rgb, shape, interpolation=cv2.INTER_AREA)

        fbo.deactivate()
예제 #4
0
    def run(self):

        glfw.set_key_callback(self.window, self.key_callback)
        glfw.set_cursor_pos_callback(self.window,
                                     self.mouse_cursor_pos_callback)
        glfw.set_mouse_button_callback(self.window, self.mouse_button_callback)
        glfw.set_scroll_callback(self.window, self.mouse_scroll_callback)
        glfw.set_window_size_callback(self.window, self.window_size_callback)

        while not glfw.window_should_close(
                self.window) and not self.quit_requested:
            self.app.on_draw()

            glfw.poll_events()
            self.impl.process_inputs()

            self.app.menu()

            gl.glClearColor(0., 0., 0.2, 1)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT)

            self.app.on_draw()

            imgui.render()
            self.impl.render(imgui.get_draw_data())
            glfw.swap_buffers(self.window)

        self.impl.shutdown()
        glfw.terminate()
예제 #5
0
    def __exit__(self, type, value, traceback):
        # Done with "original" rendering
        self._framebuffers[0].deactivate()

        # Actual filtering starts here
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glDisable(gl.GL_DEPTH_TEST)

        # Apply all filters using ping-pong framebuffers
        index = 0
        for i in range(len(self._programs)-1):
            program = self._programs[i]
            if i == 0: # special case for first rendering
                program['filtered'] = self._framebuffers[0].color[0]
            else:
                program['filtered'] = self._framebuffers[1+index].color[0]
            index = (index + 1) % 2 # ping-pong
            self._framebuffers[index+1].activate()
            self._programs[i].draw(gl.GL_TRIANGLE_STRIP)
            self._framebuffers[index+1].deactivate()

        # Final rendering (no transformation) at original viewport size
        program = self._programs[-1]
        program['filtered'] = self._framebuffers[index+1].color[0]
        gl.glViewport( *self._viewport )
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glDisable(gl.GL_DEPTH_TEST)
        program.draw(gl.GL_TRIANGLE_STRIP)
예제 #6
0
def on_draw(dt):
    # Clear depth and color buffers
    gl.glClearColor(*C0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    # Opaque objects rendering
    gl.glDepthMask(gl.GL_TRUE)
    gl.glDisable(gl.GL_BLEND)

    # Transparent objects rendering
    gl.glDepthMask(gl.GL_FALSE)
    gl.glEnable(gl.GL_BLEND)
    framebuffer.activate()
    gl.glClearColor(0, 0, 0, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    window.clear(color=(0, 0, 0, 1))
    gl.glBlendFuncSeparate(gl.GL_ONE, gl.GL_ONE, gl.GL_ZERO,
                           gl.GL_ONE_MINUS_SRC_ALPHA)
    scene.draw(gl.GL_TRIANGLES, indices)
    framebuffer.deactivate()

    # Compositing
    gl.glBlendFunc(gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_SRC_ALPHA)
    compose.draw(gl.GL_TRIANGLE_STRIP)
예제 #7
0
파일: stage.py 프로젝트: m0r13/pyvisual
    def render_texture(self, texture):
        self.before_render(texture)

        #print("Rendering %s to texture" % repr(self))
        fbo_size = None
        if self._force_size is not None:
            fbo_size = self._force_size
        elif texture is not None:
            h, w, _ = texture.shape
            fbo_size = w, h
        elif self.preferred_size is not None:
            fbo_size = self.preferred_size
        else:
            assert False, "A preferred size must be set if there is no input texture / no size forced"

        fbo = self.fbo(fbo_size)
        fbo.activate()

        gl.glViewport(0, 0, fbo_size[0], fbo_size[1])
        gl.glClearColor(0.0, 0.0, 0.0, 0.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        self._transform_flipy = True
        self.render(texture, fbo_size)
        fbo.deactivate()
        self.after_render()

        return fbo.color[0]
예제 #8
0
def draw_depth(shape, vertex_buffer, index_buffer, mat_model, mat_view, mat_proj):

    program = gloo.Program(_depth_vertex_code, _depth_fragment_code)
    program.bind(vertex_buffer)
    program['u_mv'] = _compute_model_view(mat_model, mat_view)
    program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view, mat_proj)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4), np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]), np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_CULL_FACE)
    gl.glCullFace(gl.GL_BACK) # Back-facing polygons will be culled
    gl.glClearColor(0.0, 0.0, 0.0, 0.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    # Rendering
    program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    depth = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, depth)
    depth.shape = shape[0], shape[1], 4
    depth = depth[::-1, :]
    depth = depth[:, :, 0] # Depth is saved in the first channel

    fbo.deactivate()

    return depth
예제 #9
0
 def activate(self, clear=False):
     gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)
     gl.glViewport(0, 0, self.width, self.height)
     if clear:
         # self._win.clear()
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glEnable(gl.GL_DEPTH_TEST)
     yield self
예제 #10
0
파일: show-label.py 프로젝트: mabl/glumpy
def on_draw(dt):
    global theta, dtheta
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    program.draw(gl.GL_TRIANGLES, I)
    theta += dtheta
    model = np.eye(4, dtype=np.float32)
    glm.rotate(model, theta, 0, 0, 1)
    program['model'] = model
예제 #11
0
def on_draw(dt):
    global theta, dtheta
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    C.draw()
    theta += dtheta
    model = np.eye(4, dtype=np.float32)
    glm.rotate(model, theta, 0, 0, 1)
    C['model'] = model
예제 #12
0
    def clear(self, color=None):
        """ Clear the whole window """

        if color is not None:
            gl.glClearColor(*color)
            gl.glClear(self._clearflags)
            gl.glClearColor(*self.color)
        else:
            gl.glClear(self._clearflags)
예제 #13
0
파일: window.py 프로젝트: jk34/glumpy
    def clear(self,color=None):
        """ Clear the whole window """

        if color is not None:
            gl.glClearColor(*color)
            gl.glClear(self._clearflags)
            gl.glClearColor(*self.color)
        else:
            gl.glClear(self._clearflags)
예제 #14
0
def draw_color(shape, vertex_buffers, index_buffers, mat_models, mat_views,
               mat_projs, ambient_weight, light_color, bg_color):
    assert (len(vertex_buffers) == len(index_buffers))
    assert (len(vertex_buffers) == len(mat_models))
    assert (len(vertex_buffers) == len(mat_views))
    assert (len(vertex_buffers) == len(mat_projs))

    program = gloo.Program(_color_vertex_code, _color_fragment_code)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4),
                         np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]),
                         np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_CULL_FACE)
    gl.glCullFace(gl.GL_BACK)  # Back-facing polygons will be culled
    gl.glClearColor(bg_color[0], bg_color[1], bg_color[2], bg_color[3])
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    for i in xrange(len(vertex_buffers)):
        vertex_buffer = vertex_buffers[i]
        index_buffer = index_buffers[i]
        mat_model = mat_models[i]
        mat_view = mat_views[i]
        mat_proj = mat_projs[i]

        program.bind(vertex_buffer)
        program['u_light_eye_pos'] = [0, 0, 0]
        program['light_color'] = [
            light_color[0], light_color[1], light_color[2]
        ]
        program['u_light_ambient_w'] = ambient_weight
        program['u_mv'] = _compute_model_view(mat_model, mat_view)
        program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view,
                                                    mat_proj)
        # Rendering
        program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    rgb = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, rgb)
    rgb.shape = shape[0], shape[1], 4
    rgb = rgb[::-1, :]
    rgb = np.round(rgb[:, :, :3] * 255).astype(np.uint8)  # Convert to [0, 255]

    fbo.deactivate()

    return rgb
예제 #15
0
    def paintGL(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        if self._program is not None:
            # Send the updated transformation matrices to the shader
            self._program[OBJECT_MATRIX_NAME] = self._object_to_world
            self._program[VIEW_MATRIX_NAME] = self._world_to_view
            self._program[PROJECTION_MATRIX_NAME] = self._view_to_projection
            self._program[UNIFORM_VERTEX_MAXES] = self._maxes
            self._program[UNIFORM_VERTEX_MINS] = self._mins

            self._program.draw(gl.GL_TRIANGLES, self._I)
예제 #16
0
파일: base.py 프로젝트: m0r13/pyvisual
    def render(self, size, render_func):
        fbo = self.get_fbo(size)
        fbo.activate()

        gl.glViewport(0, 0, size[0], size[1])
        gl.glClearColor(0.0, 0.0, 0.0, 0.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        render_func()

        fbo.deactivate()
        return fbo.color[0]
예제 #17
0
def draw_label(shape, vertex_buffers, index_buffers, mat_models, mat_views,
               mat_projs, labels):
    assert (len(vertex_buffers) == len(index_buffers))
    assert (len(vertex_buffers) == len(mat_models))
    assert (len(vertex_buffers) == len(mat_views))
    assert (len(vertex_buffers) == len(mat_projs))
    assert (labels is not None)
    assert (len(vertex_buffers) == len(labels))

    program = gloo.Program(_label_vertex_code, _label_fragment_code)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4),
                         np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]),
                         np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_CULL_FACE)
    gl.glCullFace(gl.GL_BACK)  # Back-facing polygons will be culled
    gl.glClearColor(0.0, 0.0, 0.0, 0.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    for i in range(len(vertex_buffers)):
        vertex_buffer = vertex_buffers[i]
        index_buffer = index_buffers[i]
        mat_model = mat_models[i]
        mat_view = mat_views[i]
        mat_proj = mat_projs[i]
        label = labels[i]
        program.bind(vertex_buffer)
        program['u_mv'] = _compute_model_view(mat_model, mat_view)
        # program['u_nm'] = compute_normal_matrix(model, view)
        program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view,
                                                    mat_proj)
        program['label'] = label
        # Rendering
        program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    label_map = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT,
                    label_map)
    label_map.shape = shape[0], shape[1], 4
    label_map = label_map[::-1, :]
    label_map = label_map[:, :, 0]
    fbo.deactivate()

    return label_map
예제 #18
0
 def activate(self, clear=False):
     self._framebuffer.activate()
     gl.glViewport(0, 0, self.width, self.height)
     if clear:
         # color_attachment_flags = []
         # for i in range(len(self._color_attachments)):
         #     color_attachment_flags.append(gl.GL_COLOR_ATTACHMENT0 + i)
         # gl.glDrawBuffers(np.array(color_attachment_flags, dtype=np.uint32))
         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glEnable(gl.GL_DEPTH_TEST)
     yield self
     self._framebuffer.deactivate()
예제 #19
0
    def paintGL(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        self.program.draw(gl.GL_TRIANGLES, self.I)
        self._current_frame += 1

        if self.callback and (self._current_frame %
                              self.cb_freg) == 0 and self._current_frame > 0:
            self.callback(self.get_image())

        if self._current_frame >= self._frame_count:
            self.rendered_image = self.get_image()
            self.close()
예제 #20
0
 def draw(self):
     # consume all segments present at start of drawing
     with self.target:
         gl.glViewport(0, 0, *self.target.size)
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         n = self.segments.qsize()
         for _ in range(n):
             p, c, s = self.segments.get()
             self.data['a_position'][:] = p
             self.data['a_color'][:] = c
             self.data['a_size'][:] = s
             # gl.glClearColor(0,0,0,0.001)
             # gl.glEnable(gl.GL_BLEND)
             # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
             self.program.draw(gl.GL_POINTS)
예제 #21
0
def draw_depth(shape, vertex_buffer, index_buffer, mat_model, mat_view,
               mat_proj):

    assert type(mat_view) is list, 'Requires list of arrays.'

    program = gloo.Program(_depth_vertex_code, _depth_fragment_code)
    program.bind(vertex_buffer)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4),
                         np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]),
                         np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)

    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glClearColor(0.0, 0.0, 0.0, 0.0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    for i in range(len(mat_view)):

        program['u_mv'] = _compute_model_view(mat_model, mat_view[i])
        program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view[i],
                                                    mat_proj)

        # Keep the back-face culling disabled because of objects which do not have
        # well-defined surface (e.g. the lamp from the dataset of Hinterstoisser)
        gl.glDisable(gl.GL_CULL_FACE)
        # gl.glEnable(gl.GL_CULL_FACE)
        # gl.glCullFace(gl.GL_BACK) # Back-facing polygons will be culled

        # Rendering
        program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    depth = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, depth)
    depth.shape = shape[0], shape[1], 4
    depth = depth[::-1, :]
    depth = depth[:, :, 0]  # Depth is saved in the first channel

    fbo.deactivate()

    return depth
예제 #22
0
def on_draw(dt):

    gl.glViewport(0, 0, GridWidth, GridHeight)
    gl.glDisable(gl.GL_BLEND)

    Advect(Velocity.Ping, Velocity.Ping, Obstacles, Velocity.Pong,
           VelocityDissipation)
    Velocity.swap()

    Advect(Velocity.Ping, Temperature.Ping, Obstacles, Temperature.Pong,
           TemperatureDissipation)
    Temperature.swap()

    Advect(Velocity.Ping, Density.Ping, Obstacles, Density.Pong,
           DensityDissipation)
    Density.swap()

    ApplyBuoyancy(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong)
    Velocity.swap()

    ApplyImpulse(Temperature.Ping, ImpulsePosition, ImpulseTemperature)
    ApplyImpulse(Density.Ping, ImpulsePosition, ImpulseDensity)
    ComputeDivergence(Velocity.Ping, Obstacles, Divergence)
    ClearSurface(Pressure.Ping, 0.0)

    for i in range(NumJacobiIterations):
        Jacobi(Pressure.Ping, Divergence, Obstacles, Pressure.Pong)
        Pressure.swap()

    SubtractGradient(Velocity.Ping, Pressure.Ping, Obstacles, Velocity.Pong)
    Velocity.swap()

    gl.glViewport(0, 0, window.width, window.height)
    gl.glClearColor(0, 0, 0, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

    prog_visualize['u_data'] = Density.Ping.texture
    prog_visualize['u_shape'] = Density.Ping.texture.shape[
        1], Density.Ping.texture.shape[0]
    prog_visualize['u_kernel'] = data.get("spatial-filters.npy")
    prog_visualize["Sampler"] = Density.Ping.texture
    prog_visualize["FillColor"] = 0.95, 0.925, 1.00
    prog_visualize["Scale"] = 1.0 / window.width, 1.0 / window.height
    prog_visualize.draw(gl.GL_TRIANGLE_STRIP)
예제 #23
0
def on_draw(dt):
    global pingpong

    pingpong = 1 - pingpong
    compute["pingpong"] = pingpong
    render["pingpong"] = pingpong

    gl.glDisable(gl.GL_BLEND)

    framebuffer.activate()
    gl.glViewport(0, 0, cwidth, cheight)
    compute.draw(gl.GL_TRIANGLE_STRIP)
    framebuffer.deactivate()

    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glViewport(0, 0, window.width, window.height)
    render.draw(gl.GL_TRIANGLE_STRIP)
예제 #24
0
def on_draw(dt):
    global pingpong

    pingpong = 1 - pingpong
    compute["pingpong"] = pingpong
    render["pingpong"] = pingpong

    gl.glDisable(gl.GL_BLEND)

    framebuffer.activate()
    gl.glViewport(0, 0, cwidth, cheight)
    compute.draw(gl.GL_TRIANGLE_STRIP)
    framebuffer.deactivate()

    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glViewport(0, 0, window.width, window.height)
    render.draw(gl.GL_TRIANGLE_STRIP)
예제 #25
0
def draw_label(shape, vertex_buffer, index_buffer, texture, mat_model,
               mat_view, mat_proj, ambient_weight, bg_color, shading,
               inst_ids):

    assert type(mat_view) is list, 'Requires list of arrays.'

    program = gloo.Program(_label_vertex_code, _label_fragment_code)
    program.bind(vertex_buffer)

    # FBO
    color_buf = np.zeros((shape[0], shape[1], 4),
                         np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]),
                         np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)

    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glClearColor(bg_color[0], bg_color[1], bg_color[2], bg_color[3])
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    print('inst ids = ' + str(inst_ids))
    for i in range(len(mat_view)):
        program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view[i],
                                                    mat_proj)
        program['inst_id'] = inst_ids[
            i] / 255.  # input instance-id is mapped to range [0,1]

        gl.glDisable(gl.GL_CULL_FACE)

        program.draw(gl.GL_TRIANGLES, index_buffer)

    label = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, label)
    label.shape = shape[0], shape[1], 4
    label = label[::-1, :]
    label = np.round(label[:, :, 0] * 255).astype(
        np.uint8)  # Label is saved in the first channel

    fbo.deactivate()

    return label
예제 #26
0
파일: smoke.py 프로젝트: untereiner/glumpy
def CreateObstacles(dest, width, height):
    dest.activate()
    gl.glViewport(0, 0, width, height)
    gl.glClearColor(0, 0, 0, 0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    T = np.ones((height,width,3), np.float32).view(gloo.Texture2D)

    T[+1:-1,+1:-1] = 0.0
    T[...,0] += disc(shape = (GridHeight,GridWidth),
                     center = (GridHeight/2,GridWidth/2),
                     radius = 32)
    T[...,2] += -2*disc(shape = (GridHeight,GridWidth),
                        center = (GridHeight/2,GridWidth/2),
                        radius = 32)
    prog_fill["Sampler"] = T
    prog_fill.draw(gl.GL_TRIANGLE_STRIP)
    dest.deactivate()
예제 #27
0
def CreateObstacles(dest, width, height):
    dest.activate()
    gl.glViewport(0, 0, width, height)
    gl.glClearColor(0, 0, 0, 0)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    T = np.ones((height, width, 3), np.float32).view(gloo.Texture2D)

    T[+1:-1, +1:-1] = 0.0
    T[..., 0] += disc(shape=(GridHeight, GridWidth),
                      center=(GridHeight / 2, GridWidth / 2),
                      radius=32)
    T[..., 2] += -2 * disc(shape=(GridHeight, GridWidth),
                           center=(GridHeight / 2, GridWidth / 2),
                           radius=32)
    prog_fill["Sampler"] = T
    prog_fill.draw(gl.GL_TRIANGLE_STRIP)
    dest.deactivate()
예제 #28
0
    def __init__(self,
                 model,
                 im_size,
                 texture=None,
                 bg_color=(0.0, 0.0, 0.0, 0.0),
                 ambient_weight=0.5,
                 shading='flat',
                 mode='rgb+depth'):

        # Set texture / color of vertices
        texture_uv = np.zeros((model['pts'].shape[0], 2), np.float32)
        colors = np.ones((model['pts'].shape[0], 3), np.float32) * 0.5

        # Set the vertex data
        vertices_type = [('a_position', np.float32, 3),
                         ('a_normal', np.float32, 3),
                         ('a_color', np.float32, colors.shape[1]),
                         ('a_texcoord', np.float32, 2)]
        vertices = np.array(
            list(zip(model['pts'], model['normals'], colors, texture_uv)),
            vertices_type)

        # Create buffers
        self.vertex_buffer = vertices.view(gloo.VertexBuffer)
        self.index_buffer = model['faces'].flatten().astype(np.uint32).view(
            gloo.IndexBuffer)
        self.window = app.Window(visible=False)

        self.program = gloo.Program(_normal_vertex_code, _normal_fragment_code)
        self.program.bind(self.vertex_buffer)

        scale = max(im_size)
        shape = (scale, scale)
        color_buf = np.zeros((shape[0], shape[1], 4),
                             np.float32).view(gloo.TextureFloat2D)
        depth_buf = np.zeros((shape[0], shape[1]),
                             np.float32).view(gloo.DepthTexture)
        fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
        fbo.activate()
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClearColor(bg_color[0], bg_color[1], bg_color[2], bg_color[3])
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glViewport(0, 0, shape[1], shape[0])
        gl.glDisable(gl.GL_CULL_FACE)
예제 #29
0
파일: smoke.py 프로젝트: untereiner/glumpy
def on_draw(dt):

    gl.glViewport(0, 0, GridWidth, GridHeight)
    gl.glDisable(gl.GL_BLEND)

    Advect(Velocity.Ping, Velocity.Ping, Obstacles, Velocity.Pong, VelocityDissipation)
    Velocity.swap()

    Advect(Velocity.Ping, Temperature.Ping, Obstacles, Temperature.Pong, TemperatureDissipation)
    Temperature.swap()

    Advect(Velocity.Ping, Density.Ping, Obstacles, Density.Pong, DensityDissipation)
    Density.swap()

    ApplyBuoyancy(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong)
    Velocity.swap()

    ApplyImpulse(Temperature.Ping, ImpulsePosition, ImpulseTemperature)
    ApplyImpulse(Density.Ping, ImpulsePosition, ImpulseDensity)
    ComputeDivergence(Velocity.Ping, Obstacles, Divergence)
    ClearSurface(Pressure.Ping, 0.0)

    for i in range(NumJacobiIterations):
        Jacobi(Pressure.Ping, Divergence, Obstacles, Pressure.Pong)
        Pressure.swap()

    SubtractGradient(Velocity.Ping, Pressure.Ping, Obstacles, Velocity.Pong)
    Velocity.swap()

    gl.glViewport(0,0,window.width,window.height)
    gl.glClearColor(0, 0, 0, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

    prog_visualize['u_data']   = Density.Ping.texture
    prog_visualize['u_shape']  = Density.Ping.texture.shape[1], Density.Ping.texture.shape[0]
    prog_visualize['u_kernel'] = data.get("spatial-filters.npy")
    prog_visualize["Sampler"] = Density.Ping.texture
    prog_visualize["FillColor"] = 0.95, 0.925, 1.00
    prog_visualize["Scale"] =  1.0/window.width, 1.0/window.height
    prog_visualize.draw(gl.GL_TRIANGLE_STRIP)
예제 #30
0
    def _draw_rgb(self, obj_id, mat_model, mat_view, mat_proj):
        """Renders an RGB image.

    :param obj_id: ID of the object model to render.
    :param mat_model: 4x4 ndarray with the model matrix.
    :param mat_view: 4x4 ndarray with the view matrix.
    :param mat_proj: 4x4 ndarray with the projection matrix.
    :return: HxWx3 ndarray with the rendered RGB image.
    """
        # Update the OpenGL program.
        program = self.rgb_programs[obj_id]
        program['u_light_eye_pos'] = [0, 0, 0]  # Camera origin.
        program['u_light_ambient_w'] = self.light_ambient_weight
        program['u_mv'] = _calc_model_view(mat_model, mat_view)
        program['u_nm'] = _calc_normal_matrix(mat_model, mat_view)
        program['u_mvp'] = _calc_model_view_proj(mat_model, mat_view, mat_proj)

        # OpenGL setup.
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClearColor(self.bg_color[0], self.bg_color[1], self.bg_color[2],
                        self.bg_color[3])
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glViewport(0, 0, self.width, self.height)

        # Keep the back-face culling disabled because of objects which do not have
        # well-defined surface (e.g. the lamp from the lm dataset).
        gl.glDisable(gl.GL_CULL_FACE)

        # Rendering.
        program.draw(gl.GL_TRIANGLES, self.index_buffers[obj_id])

        # Get the content of the FBO texture.
        rgb = np.zeros((self.height, self.width, 4), dtype=np.float32)
        gl.glReadPixels(0, 0, self.width, self.height, gl.GL_RGBA, gl.GL_FLOAT,
                        rgb)
        rgb.shape = (self.height, self.width, 4)
        rgb = rgb[::-1, :]
        rgb = np.round(rgb[:, :, :3] * 255).astype(
            np.uint8)  # Convert to [0, 255].

        return rgb
예제 #31
0
def on_draw(dt):

    surface_ref.set_array(Density.ping_array)
    kernel_function(np.int32(400), np.int32(400), block=(16,16,1), grid=((400+1)//16+1,(400+1)//16+1))

    gl.glViewport(0,0,window.width,window.height)
    gl.glClearColor(0, 0, 0, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

    global t
    t += dt
    prog_visualize['u_data']   = Density.Ping.texture
    prog_visualize['t'] = t
    prog_visualize['u_shape']  = Density.Ping.texture.shape[1], Density.Ping.texture.shape[0]
    prog_visualize['u_kernel'] = data.get("spatial-filters.npy")
    prog_visualize["Sampler"] = Density.Ping.texture
    prog_visualize["FillColor"] = 0.95, 0.925, 1.00
    prog_visualize["Scale"] =  1.0/window.width, 1.0/window.height
    prog_visualize.draw(gl.GL_TRIANGLE_STRIP)
    Density.swap()
예제 #32
0
def draw_color(shape, vertex_buffer, index_buffer, mat_model, mat_view, mat_proj,
               ambient_weight, bg_color):

    program = gloo.Program(_color_vertex_code, _color_fragment_code)
    program.bind(vertex_buffer)
    program['u_light_eye_pos'] = [0, 0, 0]
    program['u_light_ambient_w'] = ambient_weight
    program['u_mv'] = _compute_model_view(mat_model, mat_view)
    # program['u_nm'] = compute_normal_matrix(model, view)
    program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view, mat_proj)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4), np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]), np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_CULL_FACE)
    gl.glCullFace(gl.GL_BACK) # Back-facing polygons will be culled
    gl.glClearColor(bg_color[0], bg_color[1], bg_color[2], bg_color[3])
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    # Rendering
    program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    rgb = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, rgb)
    rgb.shape = shape[0], shape[1], 4
    rgb = rgb[::-1, :]
    rgb = np.round(rgb[:, :, :3] * 255).astype(np.uint8) # Convert to [0, 255]

    fbo.deactivate()

    return rgb
예제 #33
0
def process(dt):

    # Poll for and process events
    # -> Add toolkit specific code here to process events
    # -> Must always exit

    for window in __windows__:
        # Make window active
        window.activate()

        # Clear window using window clear flags
        gl.glClear(window._clearflags)

        # Dispatch the main draw event
        window.dispatch_event('on_draw', dt)

        # Dispatch the idle event
        window.dispatch_event('on_idle', dt)

        # Swap buffers
        window.swap()

    return len(__windows__)
예제 #34
0
def process(dt):

    # Poll for and process events
    # -> Add toolkit specific code here to process events
    # -> Must always exit

    for window in __windows__:
        # Make window active
        window.activate()

        # Clear window using window clear flags
        gl.glClear(window._clearflags)

        # Dispatch the main draw event
        window.dispatch_event('on_draw', dt)

        # Dispatch the idle event
        window.dispatch_event('on_idle', dt)

        # Swap buffers
        window.swap()

    return len(__windows__)
예제 #35
0
def process(dt):
    """ Process events for all windows. Non blocking. """

    # Poll for and process events
    # -> Add toolkit specific code here to process events
    # -> Must return (non bloking)

    for window in __windows__:
        # Make window active
        window.activate()

        # Clear window using window clear flags
        gl.glClear(window._clearflags)

        # Dispatch the main draw event
        window.dispatch_event("on_draw", dt)

        # Dispatch the idle event
        window.dispatch_event("on_idle", dt)

        # Swap buffers
        window.swap()

    return len(__windows__)
예제 #36
0
    def render(self, scene, cull_face=True):
        self.fbo.activate()

        gl.glEnable(gl.GL_PROGRAM_POINT_SIZE)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glShadeModel(gl.GL_FLAT)

        if cull_face:
            gl.glEnable(gl.GL_CULL_FACE)
            gl.glCullFace(gl.GL_BACK)
        else:
            gl.glDisable(gl.GL_CULL_FACE)

        gl.glClearColor(*self.clear_color)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glViewport(0, 0, self.viewport_size[0], self.viewport_size[1])

        if scene.draw_points:
            scene.program.draw(gl.GL_POINTS)
        else:
            assert scene.index_buffer is not None
            scene.program.draw(gl.GL_TRIANGLES, scene.index_buffer)

        if self.out_buffer_location == 'torch':
            frame = cpy_texture_to_tensor(self.color_buf_cuda,
                                          self.out_buf).clone()
        elif self.out_buffer_location == 'opengl':
            frame = self.out_buf
        else:
            gl.glReadPixels(0, 0, self.viewport_size[0], self.viewport_size[1],
                            gl.GL_RGB, gl.GL_FLOAT, self.out_buf)
            frame = self.out_buf.copy()

        self.fbo.deactivate()

        return frame
예제 #37
0
    def _draw_depth(self, obj_id, mat_model, mat_view, mat_proj):
        """Renders a depth image.

    :param obj_id: ID of the object model to render.
    :param mat_model: 4x4 ndarray with the model matrix.
    :param mat_view: 4x4 ndarray with the view matrix.
    :param mat_proj: 4x4 ndarray with the projection matrix.
    :return: HxW ndarray with the rendered depth image.
    """
        # Update the OpenGL program.
        program = self.depth_programs[obj_id]
        program['u_mv'] = _calc_model_view(mat_model, mat_view)
        program['u_mvp'] = _calc_model_view_proj(mat_model, mat_view, mat_proj)

        # OpenGL setup.
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClearColor(0.0, 0.0, 0.0, 0.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glViewport(0, 0, self.width, self.height)

        # Keep the back-face culling disabled because of objects which do not have
        # well-defined surface (e.g. the lamp from the lm dataset).
        gl.glDisable(gl.GL_CULL_FACE)

        # Rendering.
        program.draw(gl.GL_TRIANGLES, self.index_buffers[obj_id])

        # Get the content of the FBO texture.
        depth = np.zeros((self.height, self.width, 4), dtype=np.float32)
        gl.glReadPixels(0, 0, self.width, self.height, gl.GL_RGBA, gl.GL_FLOAT,
                        depth)
        depth.shape = (self.height, self.width, 4)
        depth = depth[::-1, :]
        depth = depth[:, :, 0]  # Depth is saved in the first channel

        return depth
예제 #38
0
 def clear(self):
     self.activate()
     gl.glClearColor(0, 0, 0, 0)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.deactivate()
예제 #39
0
def ClearSurface(surface, v):
    surface.activate()
    gl.glClearColor(v, v, v, v)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    surface.deactivate()
예제 #40
0
파일: renderer.py 프로젝트: eirikwha/6DPose
def draw_color(shape, vertex_buffer, index_buffer, texture, mat_model, mat_view,
               mat_proj, ambient_weight, bg_color, shading):

    # Set shader for the selected shading
    if shading == 'flat':
        color_fragment_code = _color_fragment_flat_code
    else: # 'phong'
        color_fragment_code = _color_fragment_phong_code

    program = gloo.Program(_color_vertex_code, color_fragment_code)
    program.bind(vertex_buffer)
    program['u_light_eye_pos'] = [0, 0, 0] # Camera origin
    program['u_light_ambient_w'] = ambient_weight
    program['u_mv'] = _compute_model_view(mat_model, mat_view)
    program['u_nm'] = _compute_normal_matrix(mat_model, mat_view)
    program['u_mvp'] = _compute_model_view_proj(mat_model, mat_view, mat_proj)
    if texture is not None:
        program['u_use_texture'] = int(True)
        program['u_texture'] = texture
    else:
        program['u_use_texture'] = int(False)
        program['u_texture'] = np.zeros((1, 1, 4), np.float32)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4), np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]), np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glClearColor(bg_color[0], bg_color[1], bg_color[2], bg_color[3])
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    # gl.glEnable(gl.GL_BLEND)
    # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    # gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    # gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    # gl.glDisable(gl.GL_LINE_SMOOTH)
    # gl.glDisable(gl.GL_POLYGON_SMOOTH)
    # gl.glEnable(gl.GL_MULTISAMPLE)

    # Keep the back-face culling disabled because of objects which do not have
    # well-defined surface (e.g. the lamp from the dataset of Hinterstoisser)
    gl.glDisable(gl.GL_CULL_FACE)
    # gl.glEnable(gl.GL_CULL_FACE)
    # gl.glCullFace(gl.GL_BACK) # Back-facing polygons will be culled

    # Rendering
    program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    rgb = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, rgb)
    rgb.shape = shape[0], shape[1], 4
    rgb = rgb[::-1, :]
    rgb = np.round(rgb[:, :, :3] * 255).astype(np.uint8) # Convert to [0, 255]

    fbo.deactivate()

    return rgb
예제 #41
0
파일: window.py 프로젝트: mabl/glumpy
    def clear(self):
        """ Clear the whole window """

        gl.glClearColor(*self.color)
        gl.glClear(self._clearflags)
예제 #42
0
파일: labels.py 프로젝트: mabl/glumpy
def on_draw(dt):
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    C.draw()
예제 #43
0
    def clear(self):
        """ Clear the whole window """

        gl.glClear(self._clearflags)
예제 #44
0
def draw_color(
    shape,
    vertex_buffer,
    index_buffer,
    texture,
    mat_model,
    mat_view,
    mat_proj,
    ambient_weight,
    bg_color,
    shading,
):

    # Set shader for the selected shading
    if shading == "flat":
        color_fragment_code = _color_fragment_flat_code
    else:  # 'phong'
        color_fragment_code = _color_fragment_phong_code

    program = gloo.Program(_color_vertex_code, color_fragment_code)
    program.bind(vertex_buffer)
    program["u_light_eye_pos"] = [0, 0, 0]  # Camera origin
    program["u_light_ambient_w"] = ambient_weight
    program["u_mv"] = _compute_model_view(mat_model, mat_view)
    program["u_nm"] = _compute_normal_matrix(mat_model, mat_view)
    program["u_mvp"] = _compute_model_view_proj(mat_model, mat_view, mat_proj)
    if texture is not None:
        program["u_use_texture"] = int(True)
        program["u_texture"] = texture
    else:
        program["u_use_texture"] = int(False)
        program["u_texture"] = np.zeros((1, 1, 4), np.float32)

    # Frame buffer object
    color_buf = np.zeros((shape[0], shape[1], 4), np.float32).view(gloo.TextureFloat2D)
    depth_buf = np.zeros((shape[0], shape[1]), np.float32).view(gloo.DepthTexture)
    fbo = gloo.FrameBuffer(color=color_buf, depth=depth_buf)
    fbo.activate()

    # OpenGL setup
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glClearColor(bg_color[0], bg_color[1], bg_color[2], bg_color[3])
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glViewport(0, 0, shape[1], shape[0])

    # gl.glEnable(gl.GL_BLEND)
    # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    # gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    # gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    # gl.glDisable(gl.GL_LINE_SMOOTH)
    # gl.glDisable(gl.GL_POLYGON_SMOOTH)
    # gl.glEnable(gl.GL_MULTISAMPLE)

    # Keep the back-face culling disabled because of objects which do not have
    # well-defined surface (e.g. the lamp from the dataset of Hinterstoisser)
    gl.glDisable(gl.GL_CULL_FACE)
    # gl.glEnable(gl.GL_CULL_FACE)
    # gl.glCullFace(gl.GL_BACK) # Back-facing polygons will be culled

    # Rendering
    program.draw(gl.GL_TRIANGLES, index_buffer)

    # Retrieve the contents of the FBO texture
    rgb = np.zeros((shape[0], shape[1], 4), dtype=np.float32)
    gl.glReadPixels(0, 0, shape[1], shape[0], gl.GL_RGBA, gl.GL_FLOAT, rgb)
    rgb.shape = shape[0], shape[1], 4
    rgb = rgb[::-1, :]
    rgb = np.round(rgb[:, :, :3] * 255).astype(np.uint8)  # Convert to [0, 255]

    fbo.deactivate()

    return rgb
예제 #45
0
파일: show-atlas.py 프로젝트: mabl/glumpy
def on_draw(dt):
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    program.draw(gl.GL_TRIANGLE_STRIP)
예제 #46
0
파일: smoke.py 프로젝트: untereiner/glumpy
def ClearSurface(surface, v):
    surface.activate()
    gl.glClearColor(v, v, v, v)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    surface.deactivate()
예제 #47
0
def on_draw(dt):
    data["time"] += dt
    quad["time"] = data["time"]
    # window.clear()
    gl.glViewport(0, 0, window.width, window.height)

    # framebuffer.activate()
    # gl.glViewport(0, 0, width, height)
    # quad["time"] = 0.2
    # quad.draw(gl.GL_TRIANGLE_STRIP)
    # quad2["time"] = 0.1
    # quad2["color"] = 0,0,1,1
    # quad2.draw(gl.GL_TRIANGLE_STRIP)
    # gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0, gl.GL_FRONT)
    # values = gl.glReadPixels(0, 0, width, height, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE)
    # values = np.fromstring(values, np.ubyte).reshape((height, width, 4))
    # red = gl.glReadPixels(0, 0, width, height, gl.GL_RED, gl.GL_UNSIGNED_BYTE)
    # #red = np.fromstring(red, np.ubyte).reshape((480, 640))
    # #red = np.transpose(red)
    # red = np.fromstring(red, np.ubyte).reshape((height, width))
    # #red = np.transpose(red)
    # print(values.shape)
    # print(np.sum(values[..., 0]))
    # print(np.sum(values[..., 3]))
    # print(np.sum(red))
    # print(np.min(red))
    # print(np.max(red))
    # print(red[320,240])
    # img = values[..., [2, 1, 0, 3]]
    # #img = red
    # cv2.imwrite("img.png", img)
    # cv2.imshow("img", img)
    # cv2.waitKey(50)
    # framebuffer.deactivate()

    # framebuffer.color[0][:] = 0
    # framebuffer.color[1][:] = 0

    framebuffer.activate()
    gl.glViewport(0, 0, width, height)
    # gl.glDrawBuffer(gl.GL_COLOR_ATTACHMENT0 | gl.GL_COLOR_ATTACHMENT1)
    gl.glDrawBuffers(
        np.array([gl.GL_COLOR_ATTACHMENT0, gl.GL_COLOR_ATTACHMENT1],
                 dtype=np.uint32))
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glClear(gl.GL_DEPTH_BUFFER_BIT)

    global phi, theta
    # Filled cube
    gl.glDisable(gl.GL_BLEND)
    # gl.glDisable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
    cube['u_color'] = np.array([1, 1, 1, 1])
    cube.draw(gl.GL_TRIANGLES, faces)

    # Outlined cube
    # gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
    # gl.glEnable(gl.GL_BLEND)
    # gl.glDepthMask(gl.GL_FALSE)
    # cube['u_color'] = np.array([0, 0, 0, 1])
    # cube.draw(gl.GL_LINES, outline)
    # gl.glDepthMask(gl.GL_TRUE)

    gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0)
    # gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT1)
    pixels = gl.glReadPixels(0, 0, width, height, gl.GL_RGBA,
                             gl.GL_UNSIGNED_BYTE)
    gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0)
    # pixels = gl.glReadPixels(0, 0, width, height, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE)

    framebuffer.deactivate()

    gl.glDisable(gl.GL_BLEND)
    gl.glDisable(gl.GL_DEPTH_TEST)

    # pixels = 100 * np.ones((height, width, 4), np.ubyte)
    # pixels[:, :, 3] = 1
    # pixels[:, :, 2] = 0

    gl.glDrawPixels(width, height, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, pixels)

    # gl.glDisable(gl.GL_DEPTH_TEST)
    # # quad["time"] = 0.2
    # quad.draw(gl.GL_TRIANGLE_STRIP)
    # quad2["time"] = 0.1
    # quad2["color"] = 0, 0, 1, 1
    # quad2.draw(gl.GL_TRIANGLE_STRIP)
    # gl.glEnable(gl.GL_DEPTH_TEST)

    # Make cube rotate
    theta += 0.5  # degrees
    phi += 0.5  # degrees
    model = np.eye(4, dtype=np.float32)
    glm.rotate(model, theta, 0, 0, 1)
    glm.rotate(model, phi, 0, 1, 0)
    cube['u_model'] = model
예제 #48
0
파일: smoke.py 프로젝트: untereiner/glumpy
 def clear(self):
     self.activate()
     gl.glClearColor(0, 0, 0, 0)
     gl.glClear(gl.GL_COLOR_BUFFER_BIT)
     self.deactivate()