Python OpenGL.GL.glClear() Examples

The following are 30 code examples of OpenGL.GL.glClear(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module OpenGL.GL , or try the search function .
Example #1
Source File: test_opengl.py    From spimagine with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def paintGL(self):
        self.makeCurrent()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        self.program.bind()

        self.program.enableAttributeArray("position")
        self.vbo.bind()
        gl.glVertexAttribPointer(self.program.attributeLocation("position"), 2, gl.GL_FLOAT, gl.GL_FALSE, 0, self.vbo)


        self.program.enableAttributeArray("normal")
        self.vbo_cols.bind()
        gl.glVertexAttribPointer(self.program.attributeLocation("normal"), 3, gl.GL_FLOAT, gl.GL_FALSE, 0, self.vbo_cols)


        gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(self.data))



        print(self.context().format().majorVersion())
        print(self.context().format().minorVersion())


        print(gl.glGetString(gl.GL_VERSION)); 
Example #2
Source File: rendering.py    From renpy-shader with MIT License 6 votes vote down vote up
def render(self, context):
        self.shader.bind()

        flipY = -1
        projection = utils.createPerspectiveOrtho(-1.0, 1.0, 1.0 * flipY, -1.0 * flipY, -1.0, 1.0)
        self.shader.uniformMatrix4f(shader.PROJECTION, projection)
        self.shader.uniformf("imageSize", *self.getSize())

        self.setUniforms(self.shader, context.uniforms)

        self.textureMap.bindTextures(self.shader)

        gl.glClearColor(*self.clearColor)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        self.bindAttributeArray(self.shader, "inVertex", self.verts, 4)
        gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, len(self.verts) // 4);
        self.unbindAttributeArray(self.shader, "inVertex")

        self.textureMap.unbindTextures()

        self.shader.unbind() 
Example #3
Source File: integrations_all_in_one.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main_cocos2d():
    class HelloWorld(ImguiLayer):
        is_event_handler = True

        def __init__(self):
            super(HelloWorld, self).__init__()
            self._text = "Input text here"

        def draw(self, *args, **kwargs):
            imgui.new_frame()
            on_frame()
            gl.glClearColor(1., 1., 1., 1)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT)
            imgui.render()

    director.init(width=800, height=600, resizable=True)
    hello_layer = HelloWorld()
    main_scene = cocos.scene.Scene(hello_layer)
    director.run(main_scene)


# backend-independent frame rendering function: 
Example #4
Source File: gltest.py    From bluesky with GNU General Public License v3.0 6 votes vote down vote up
def paintGL(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        if not self.first:
            return
        f = open('opengl_test.txt', 'w')
        gl_version = float(gl.glGetString(gl.GL_VERSION)[:3])
        f.write('Supported OpenGL version: %.1f\n' % gl_version)
        if gl_version >= 2.0:
            f.write('Supported GLSL version: ' +
                    gl.glGetString(gl.GL_SHADING_LANGUAGE_VERSION).decode() + '\n')
            f.write('Context was valid in initializeGL? %d\n' % self.was_valid_in_init)
            numext = gl.glGetIntegerv(gl.GL_NUM_EXTENSIONS)
            f.write('Supported OpenGL extensions:' + '\n')
            extensions = ''
            for i in range(numext):
                extensions += ', ' + gl.glGetStringi(gl.GL_EXTENSIONS, i).decode()
            f.write(extensions)
        f.close()
        self.first = False 
Example #5
Source File: integrations_all_in_one.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main_glfw():
    def glfw_init():
        width, height = 1280, 720
        window_name = "minimal ImGui/GLFW3 example"
        if not glfw.init():
            print("Could not initialize OpenGL context")
            exit(1)
        # OS X supports only forward-compatible core profiles from 3.2
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)
        # Create a windowed mode window and its OpenGL context
        window = glfw.create_window(
            int(width), int(height), window_name, None, None
        )
        glfw.make_context_current(window)
        if not window:
            glfw.terminate()
            print("Could not initialize Window")
            exit(1)
        return window
    window = glfw_init()
    impl = GlfwRenderer(window)
    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()
        imgui.new_frame()
        on_frame()
        gl.glClearColor(1., 1., 1., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        impl.render(imgui.get_draw_data())
        glfw.swap_buffers(window)
    impl.shutdown()
    glfw.terminate() 
Example #6
Source File: integrations_all_in_one.py    From pyimgui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main_pygame():
    pygame.init()
    size = 800, 600
    pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL)
    io = imgui.get_io()
    io.fonts.add_font_default()
    io.display_size = size
    renderer = PygameRenderer()
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            renderer.process_event(event)
        imgui.new_frame()
        on_frame()
        # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
        #       does not support fill() on OpenGL sufraces
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        pygame.display.flip() 
Example #7
Source File: ndwindow.py    From spectral with MIT License 6 votes vote down vote up
def render_rgb_indexed_colors(self, **kwargs):
        '''Draws scene in the background buffer to extract mouse click info'''
        import OpenGL.GL as gl
        import OpenGL.GLU as glu
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # camera_pos_rtp is relative to the target position. To get the
        # absolute camera position, we need to add the target position.
        gl.glPushMatrix()
        camera_pos_xyz = np.array(rtp_to_xyz(*self.camera_pos_rtp)) \
            + self.target_pos
        glu.gluLookAt(
            *(list(camera_pos_xyz) + list(self.target_pos) + self.up))
        self.draw_data_set()
        gl.glPopMatrix()
        gl.glFlush() 
Example #8
Source File: simpleScene.py    From pyslam with GNU General Public License v3.0 5 votes vote down vote up
def main():
    pangolin.CreateWindowAndBind('Main', 640, 480)
    gl.glEnable(gl.GL_DEPTH_TEST)

    # Define Projection and initial ModelView matrix
    scam = pangolin.OpenGlRenderState(
        pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100),
        pangolin.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pangolin.AxisY))

    tree = pangolin.Renderable()
    tree.Add(pangolin.Axis())

    # Create Interactive View in window
    handler = pangolin.SceneHandler(tree, scam)
    dcam = pangolin.CreateDisplay()
    dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 /480.0)
    dcam.SetHandler(handler)

    def draw(view):
        view.Activate(scam)
        tree.Render()
    dcam.SetDrawFunction(draw)

    while not pangolin.ShouldQuit():
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # or
        # dcam.Activate(scam)
        # tree.Render()

        pangolin.FinishFrame() 
Example #9
Source File: thumbview.py    From GDMC with ISC License 5 votes vote down vote up
def clear(self):
        if self.drawBackground:
            GL.glClearColor(0.25, 0.27, 0.77, 1.0)
        else:
            GL.glClearColor(0.0, 0.0, 0.0, 0.0)
        GL.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT) 
Example #10
Source File: opengl_test.py    From PFramer with GNU General Public License v3.0 5 votes vote down vote up
def paintGL(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glLoadIdentity()
        GL.glTranslated(0.0, 0.0, -10.0)
        GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
        GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
        GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
        GL.glCallList(self.object) 
Example #11
Source File: test_opengl.py    From spimagine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def initializeGL(self):
        GL.glClearColor(1.0, 0.0, 0.0, 1.0)
        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)

        print("OpenGL.GL: " + str(GL.glGetString(GL.GL_VERSION)))
        print("GL.GLSL: " + str(GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION)))
        print("OpenGL ATTRIBUTES:\n",", ".join(d for d in dir(GL) if d.startswith("GL_")))

        self.program = QOpenGLShaderProgram()
        self.program.addShaderFromSourceCode(QOpenGLShader.Vertex, """#version 120
        attribute vec2 position;
        attribute vec2 texcoord;
        varying vec2 mytexcoord;
        void main() {
            gl_Position = vec4(position, 0., 1.0);
            mytexcoord = texcoord;
        }""")

        self.program.addShaderFromSourceCode(QOpenGLShader.Fragment, """#version 120
        uniform sampler2D texture;
        varying vec2 mytexcoord;
        void main() {
            
            gl_FragColor = texture2D(texture,mytexcoord);
        }""")
        print(self.program.log())
        self.program.link()

        self.texture = fillTexture2d(np.outer(np.linspace(0, 1, 128), np.ones(128))) 
Example #12
Source File: test_opengl.py    From spimagine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paintGL(self):
        #GL.glClear(GL.GL_COLOR_BUFFER_BIT)
        self.program.bind()

        self.program.enableAttributeArray("position")
        self.program.enableAttributeArray("texcoord")
        self.program.setAttributeArray("position", self.quadCoord)
        self.program.setAttributeArray("texcoord", self.quadCoordTex)

        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)
        self.program.setUniformValue("texture", 0)

        GL.glDrawArrays(GL.GL_TRIANGLES, 0, len(self.quadCoord)) 
Example #13
Source File: test_opengl2.py    From spimagine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paintGL(self):
        self.makeCurrent()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        self.program.bind()

        self.program.enableAttributeArray("position")
        self.vbo.bind()
        gl.glVertexAttribPointer(self.program.attributeLocation("position"), 2, gl.GL_FLOAT, gl.GL_FALSE, 0, self.vbo)


        self.program.enableAttributeArray("color")
        self.vbo_cols.bind()
        gl.glVertexAttribPointer(self.program.attributeLocation("color"), 3, gl.GL_FLOAT, gl.GL_FALSE, 0, self.vbo_cols)

        self.vbo_index.bind()

        #gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(self.data))

        gl.glDrawElements(gl.GL_TRIANGLES, len(self.index), gl.GL_UNSIGNED_INT, None)

        print(self.context().format().majorVersion())
        print(self.context().format().minorVersion())


        print(gl.glGetString(gl.GL_VERSION)); 
Example #14
Source File: simplePlot.py    From pyslam with GNU General Public License v3.0 5 votes vote down vote up
def main():
    # Create OpenGL window in single line
    pangolin.CreateWindowAndBind('Main', 640, 480)

    # Data logger object
    log = pangolin.DataLog()

    # Optionally add named labels
    labels = ['sin(t)', 'cos(t)', 'sin(t)+cos(t)']
    log.SetLabels(labels)

    # OpenGL 'view' of data. We might have many views of the same data.
    tinc = 0.03
    plotter = pangolin.Plotter(log, 0.0, 4.0*np.pi/tinc, -2.0, 2.0, np.pi/(4*tinc), 0.5)
    plotter.SetBounds(0.0, 1.0, 0.0, 1.0)
    plotter.Track('$i')

    # Add some sample annotations to the plot
    plotter.AddMarker(pangolin.Marker.Vertical, -1000, pangolin.Marker.LessThan, 
        pangolin.Colour.Blue().WithAlpha(0.2))
    plotter.AddMarker(pangolin.Marker.Horizontal, 100, pangolin.Marker.GreaterThan, 
        pangolin.Colour.Red().WithAlpha(0.2))
    plotter.AddMarker(pangolin.Marker.Horizontal,  10, pangolin.Marker.Equal, 
        pangolin.Colour.Green().WithAlpha(0.2))

    pangolin.DisplayBase().AddDisplay(plotter)


    t = 0
    while not pangolin.ShouldQuit():
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        log.Log(np.sin(t), np.cos(t), np.sin(t)+np.cos(t))
        t += tinc

        pangolin.FinishFrame() 
Example #15
Source File: root.py    From GDMC with ISC License 5 votes vote down vote up
def gl_clear(self):
        from OpenGL import GL
        
        bg = self.bg_color
        if bg:
            r = bg[0] / 255.0
            g = bg[1] / 255.0
            b = bg[2] / 255.0
            GL.glClearColor(r, g, b, 0.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) 
Example #16
Source File: helloPangolin.py    From pyslam with GNU General Public License v3.0 5 votes vote down vote up
def main():
    pangolin.CreateWindowAndBind('Main', 640, 480)
    gl.glEnable(gl.GL_DEPTH_TEST)

    # Define Projection and initial ModelView matrix
    scam = pangolin.OpenGlRenderState(
        pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100),
        pangolin.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pangolin.AxisDirection.AxisY))
    handler = pangolin.Handler3D(scam)

    # Create Interactive View in window
    dcam = pangolin.CreateDisplay()
    dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0/480.0)
    dcam.SetHandler(handler)

    while not pangolin.ShouldQuit():
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glClearColor(1.0, 1.0, 1.0, 1.0)
        dcam.Activate(scam)
        
        # Render OpenGL Cube
        pangolin.glDrawColouredCube()

        # Draw Point Cloud
        points = np.random.random((100000, 3)) * 10
        colors = np.zeros((len(points), 3))
        colors[:, 1] = 1 -points[:, 0] / 10.
        colors[:, 2] = 1 - points[:, 1] / 10.
        colors[:, 0] = 1 - points[:, 2] / 10.

        gl.glPointSize(2)
        gl.glColor3f(1.0, 0.0, 0.0)
        # access numpy array directly(without copying data), array should be contiguous.
        pangolin.DrawPoints(points, colors)    

        pangolin.FinishFrame() 
Example #17
Source File: with_pyopengl.py    From moderngl-window with MIT License 5 votes vote down vote up
def render(self, time, frametime):
        GL.glClearColor(
            (math.sin(time) + 1.0) / 2,
            (math.sin(time + 2) + 1.0) / 2,
            (math.sin(time + 3) + 1.0) / 2,
            1.0,
        )
        GL.glClear(GL.GL_COLOR_BUFFER_BIT) 
Example #18
Source File: gui-glut.py    From filmkodi with Apache License 2.0 5 votes vote down vote up
def display():
        gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        glut.glutSwapBuffers() 
Example #19
Source File: fullscreen_quad.py    From dm_control with Apache License 2.0 5 votes vote down vote up
def render(self, pixmap, viewport_shape):
    """Renders the pixmap on a fullscreen quad.

    Args:
      pixmap: A 3D numpy array of bytes (np.uint8), with dimensions
        (width, height, 3).
      viewport_shape: A tuple of two elements, (width, height).
    """
    GL.glClear(GL.GL_COLOR_BUFFER_BIT)
    GL.glViewport(0, 0, *viewport_shape)
    GL.glUseProgram(self._shader)
    GL.glActiveTexture(GL.GL_TEXTURE0)
    GL.glBindTexture(GL.GL_TEXTURE_2D, self._texture)
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, pixmap.shape[1],
                    pixmap.shape[0], 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE,
                    pixmap)
    GL.glUniform1i(self._var_texture_sampler, 0)
    GL.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4) 
Example #20
Source File: hellovr_glfw.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def render_scene(self, eye):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glEnable(GL.GL_DEPTH_TEST)
        if self.show_cubes:
            GL.glUseProgram(self.scene_program)
            GL.glUniformMatrix4fv(
                self.scene_matrix_location, 1, False,
                self.get_current_view_projection_matrix(eye))
            GL.glBindVertexArray(self.scene_vao)
            GL.glBindTexture(GL.GL_TEXTURE_2D, self.i_texture)
            GL.glDrawArrays(GL.GL_TRIANGLES, 0, int(self.vert_count))
            GL.glBindVertexArray(0)
        b_is_input_available = self.hmd.isInputAvailable()
        if b_is_input_available:
            # draw the controller axis lines
            GL.glUseProgram(self.controller_transform_program)
            GL.glUniformMatrix4fv(self.controller_matrix_location, 1, False, self.get_current_view_projection_matrix(eye))
            GL.glBindVertexArray(self.controller_vao)
            GL.glDrawArrays(GL.GL_LINES, 0, self.controller_vertex_count)
            GL.glBindVertexArray(0)
        # ----- Render Model rendering -----
        GL.glUseProgram(self.render_model_program)
        for hand in self.hand:
            if not hand.show_controller:
                continue
            if hand.render_model is None:
                continue
            mvp = hand.pose @ self.get_current_view_projection_matrix(eye)
            GL.glUniformMatrix4fv(self.render_model_matrix_location, 1, False, mvp)
            hand.render_model.draw()
        GL.glUseProgram(0) 
Example #21
Source File: hellovr_glfw.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run_main_loop(self):
        while not glfw.window_should_close(self.window):
            self.handle_input()
            self.render_frame()
            glfw.swap_buffers(self.window)
            GL.glClearColor(0, 0, 0, 1)
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
            glfw.poll_events() 
Example #22
Source File: root.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def gl_clear(self):
        #from OpenGL import GL
        
        bg = self.bg_color
        if bg:
            r = bg[0] / 255.0
            g = bg[1] / 255.0
            b = bg[2] / 255.0
            GL.glClearColor(r, g, b, 0.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) 
Example #23
Source File: thumbview.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def clear(self):
        if self.drawBackground:
            GL.glClearColor(0.25, 0.27, 0.77, 1.0)
        else:
            GL.glClearColor(0.0, 0.0, 0.0, 0.0)
        GL.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT) 
Example #24
Source File: mpvwidget.py    From vidcutter with GNU General Public License v3.0 5 votes vote down vote up
def paintGL(self):
        if self.opengl:
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
            self.opengl.draw(self.defaultFramebufferObject(), self.width(), -self.height()) 
Example #25
Source File: display.py    From twitchslam with MIT License 5 votes vote down vote up
def viewer_refresh(self, q):
    while not q.empty():
      self.state = q.get()

    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    gl.glClearColor(0.0, 0.0, 0.0, 1.0)
    self.dcam.Activate(self.scam)

    if self.state is not None:
      if self.state[0].shape[0] >= 2:
        # draw poses
        gl.glColor3f(0.0, 1.0, 0.0)
        pangolin.DrawCameras(self.state[0][:-1])

      if self.state[0].shape[0] >= 1:
        # draw current pose as yellow
        gl.glColor3f(1.0, 1.0, 0.0)
        pangolin.DrawCameras(self.state[0][-1:])

      if self.state[1].shape[0] != 0:
        # draw keypoints
        gl.glPointSize(5)
        gl.glColor3f(1.0, 0.0, 0.0)
        pangolin.DrawPoints(self.state[1], self.state[2])

    pangolin.FinishFrame() 
Example #26
Source File: HelloPangolin.py    From twitchslam with MIT License 5 votes vote down vote up
def main():
    pangolin.CreateWindowAndBind('Main', 640, 480)
    gl.glEnable(gl.GL_DEPTH_TEST)

    # Define Projection and initial ModelView matrix
    scam = pangolin.OpenGlRenderState(
        pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100),
        pangolin.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pangolin.AxisDirection.AxisY))
    handler = pangolin.Handler3D(scam)

    # Create Interactive View in window
    dcam = pangolin.CreateDisplay()
    dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0/480.0)
    dcam.SetHandler(handler)
    dcam.Resize(pangolin.Viewport(0,0,640*2,480*2))

    while not pangolin.ShouldQuit():
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glClearColor(1.0, 1.0, 1.0, 1.0)
        dcam.Activate(scam)
        
        # Render OpenGL Cube
        pangolin.glDrawColouredCube()

        # Draw Point Cloud
        points = np.random.random((100000, 3)) * 10
        colors = np.zeros((len(points), 3))
        colors[:, 1] = 1 -points[:, 0] / 10.
        colors[:, 2] = 1 - points[:, 1] / 10.
        colors[:, 0] = 1 - points[:, 2] / 10.

        gl.glPointSize(2)
        gl.glColor3f(1.0, 0.0, 0.0)
        # access numpy array directly(without copying data), array should be contiguous.
        pangolin.DrawPoints(points, colors)    

        pangolin.FinishFrame() 
Example #27
Source File: rendering.py    From renpy-shader with MIT License 5 votes vote down vote up
def render(self, context):
        self.shader.bind()

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

        gl.glClearDepth(1.0)
        gl.glClearColor(*self.clearColor)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        view, projection = createDefaultMatrices(self.width, self.height, context)
        self.shader.uniformMatrix4f(shader.VIEW_MATRIX, view)
        self.shader.uniformMatrix4f(shader.PROJ_MATRIX, projection)

        self.setUniforms(self.shader, context.uniforms)

        for tag, entry in self.models.items():
            mesh = entry.mesh

            entry.textureMap.bindTextures(self.shader)

            self.shader.uniformMatrix4f(shader.WORLD_MATRIX, entry.matrix)

            self.bindAttributeArray(self.shader, "inPosition", mesh.vertices, 3)
            self.bindAttributeArray(self.shader, "inNormal", mesh.normals, 3)
            self.bindAttributeArray(self.shader, "inUv", mesh.uvs, 2)
            gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(mesh.vertices) // 3)
            self.unbindAttributeArray(self.shader, "inPosition")
            self.unbindAttributeArray(self.shader, "inNormal")
            self.unbindAttributeArray(self.shader, "inUv")

            entry.textureMap.unbindTextures()

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

        self.shader.unbind() 
Example #28
Source File: rendering.py    From renpy-shader with MIT License 5 votes vote down vote up
def render(self, context):
        self.shader.bind()

        self.setUniforms(self.shader, context.uniforms)
        self.shader.uniformf("screenSize", *self.getSize())

        gl.glClearColor(*self.clearColor)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glDisable(gl.GL_DEPTH_TEST)

        transforms = self.computeBoneTransforms()

        boneMatrixArray = []
        for i, transform in enumerate(transforms):
            boneMatrix = transform.matrix
            boneMatrix.p = transform.transparency #Abuse unused matrix location

            overwrite = transform.damping > 0.0
            if overwrite and self.oldFrameData.get(transform.bone.name):
                overwrite = self.dampenBoneTransform(context, transform)

            if overwrite:
                self.oldFrameData[transform.bone.name] = SkinnedFrameData(context.shownTime, transform)

            boneMatrixArray.extend(utils.matrixToList(boneMatrix))
        self.shader.uniformMatrix4fArray("boneMatrices", boneMatrixArray)

        for transform in transforms:
            self.renderBoneTransform(transform, context)

        for i in range(2):
            gl.glActiveTexture(gl.GL_TEXTURE0 + i)
            gl.glBindTexture(gl.GL_TEXTURE_2D, 0)

        gl.glActiveTexture(gl.GL_TEXTURE0)

        self.shader.unbind() 
Example #29
Source File: gui-glut.py    From PyDev.Debugger with Eclipse Public License 1.0 5 votes vote down vote up
def display():
        gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        glut.glutSwapBuffers() 
Example #30
Source File: hypercube.py    From spectral with MIT License 5 votes vote down vote up
def on_paint(self, event):
        """Process the drawing event."""
        import OpenGL.GL as gl
        import OpenGL.GLU as glu
        self.canvas.SetCurrent(self.canvas.context)

        if not self.gl_initialized:
            self.initgl()
            self.gl_initialized = True
            self.print_help()

        if self.light:
            gl.glEnable(gl.GL_LIGHTING)
        else:
            gl.glDisable(gl.GL_LIGHTING)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()
        gl.glPushMatrix()
        glu.gluLookAt(*(list(rtp_to_xyz(
            *self.camera_pos_rtp)) + list(self.target_pos) + list(self.up)))

        self.draw_cube()

        gl.glPopMatrix()
        gl.glFlush()
        self.SwapBuffers()
        event.Skip()