Python OpenGL.GL.GL_DEPTH_BUFFER_BIT Examples
The following are 26
code examples of OpenGL.GL.GL_DEPTH_BUFFER_BIT().
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 |
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: ndwindow.py From spectral with MIT License | 6 votes |
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 #3
Source File: mpvwidget.py From vidcutter with GNU General Public License v3.0 | 5 votes |
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 #4
Source File: simpleScene.py From pyslam with GNU General Public License v3.0 | 5 votes |
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 #5
Source File: simplePlot.py From pyslam with GNU General Public License v3.0 | 5 votes |
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 #6
Source File: helloPangolin.py From pyslam with GNU General Public License v3.0 | 5 votes |
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 #7
Source File: gui-glut.py From filmkodi with Apache License 2.0 | 5 votes |
def display(): gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) glut.glutSwapBuffers()
Example #8
Source File: test_opengl2.py From spimagine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #9
Source File: opengl_test.py From PFramer with GNU General Public License v3.0 | 5 votes |
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 #10
Source File: hellovr_glfw.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #11
Source File: root.py From GDMC with ISC License | 5 votes |
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 #12
Source File: hellovr_glfw.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #13
Source File: root.py From MCEdit-Unified with ISC License | 5 votes |
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 #14
Source File: hypercube.py From spectral with MIT License | 5 votes |
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()
Example #15
Source File: gui-glut.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def display(): gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) glut.glutSwapBuffers()
Example #16
Source File: rendering.py From renpy-shader with MIT License | 5 votes |
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 #17
Source File: HelloPangolin.py From twitchslam with MIT License | 5 votes |
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 #18
Source File: display.py From twitchslam with MIT License | 5 votes |
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 #19
Source File: electrodeGUI.py From simnibs with GNU General Public License v3.0 | 5 votes |
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.glScalef(self.zoom,self.zoom,self.zoom) GL.glCallList(self.electrode_object) GL.glCallList(self.center_dir) if self.plug_object != 0: GL.glCallList(self.plug_object)
Example #20
Source File: glutils.py From MCEdit-Unified with ISC License | 4 votes |
def __init__(self, width, height, drawFunc): tex = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) self.enabled = False self._texID = tex if bool(FBO.glGenFramebuffers) and "Intel" not in GL.glGetString(GL.GL_VENDOR): buf = FBO.glGenFramebuffers(1) depthbuffer = FBO.glGenRenderbuffers(1) FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) FBO.glBindRenderbuffer(FBO.GL_RENDERBUFFER, depthbuffer) FBO.glRenderbufferStorage(FBO.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT, width, height) FBO.glFramebufferRenderbuffer(FBO.GL_FRAMEBUFFER, FBO.GL_DEPTH_ATTACHMENT, FBO.GL_RENDERBUFFER, depthbuffer) FBO.glFramebufferTexture2D(FBO.GL_FRAMEBUFFER, FBO.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, tex, 0) status = FBO.glCheckFramebufferStatus(FBO.GL_FRAMEBUFFER) if status != FBO.GL_FRAMEBUFFER_COMPLETE: print "glCheckFramebufferStatus", status self.enabled = False return FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) with gl.glPushAttrib(GL.GL_VIEWPORT_BIT): GL.glViewport(0, 0, width, height) drawFunc() FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, 0) FBO.glDeleteFramebuffers(1, [buf]) FBO.glDeleteRenderbuffers(1, [depthbuffer]) self.enabled = True else: GL.glReadBuffer(GL.GL_BACK) GL.glPushAttrib( GL.GL_VIEWPORT_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_TEST | GL.GL_STENCIL_BUFFER_BIT) GL.glDisable(GL.GL_STENCIL_TEST) GL.glViewport(0, 0, width, height) GL.glScissor(0, 0, width, height) with gl.glEnable(GL.GL_SCISSOR_TEST): drawFunc() GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glReadBuffer(GL.GL_BACK) GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height) GL.glPopAttrib()
Example #21
Source File: simplePlotDisplay.py From pyslam with GNU General Public License v3.0 | 4 votes |
def main(): # Create OpenGL window in single line 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) # 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, 6.0*np.pi/tinc, -2.0, 2.0, np.pi/(6*tinc), 0.5) plotter.SetBounds(0.05, 0.3, 0.0, 0.4) 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) # Plot line log.Log(np.sin(t), np.cos(t), np.sin(t)+np.cos(t)) t += tinc gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # Render OpenGL 3D Cube pangolin.glDrawColouredCube() pangolin.FinishFrame()
Example #22
Source File: simpleDisplayImage.py From pyslam with GNU General Public License v3.0 | 4 votes |
def main(): # Create OpenGL window in single line pangolin.CreateWindowAndBind('Main', 640, 480) # 3D Mouse handler requires depth testing to be enabled gl.glEnable(gl.GL_DEPTH_TEST) scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000), pangolin.ModelViewLookAt(-1, 1, -1, 0, 0, 0, pangolin.AxisDirection.AxisY)) # Aspect ratio allows us to constrain width and height whilst fitting within specified # bounds. A positive aspect ratio makes a view 'shrink to fit' (introducing empty bars), # whilst a negative ratio makes the view 'grow to fit' (cropping the view). dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0/480.0) dcam.SetHandler(pangolin.Handler3D(scam)) # This view will take up no more than a third of the windows width or height, and it # will have a fixed aspect ratio to match the image that it will display. When fitting # within the specified bounds, push to the top-left (as specified by SetLock). dimg = pangolin.Display('image') dimg.SetBounds(2./3, 1.0, 0.0, 1./3, 640./480) dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) w, h = 64, 48 texture = pangolin.GlTexture(w, h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) # Default hooks for exiting (Esc) and fullscreen (tab). while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.95, 0.95, 0.95, 1.0) dcam.Activate(scam) gl.glColor3f(1.0, 1.0, 1.0) pangolin.glDrawColouredCube() # Set some random image data and upload to GPU image = random_image(w, h) texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) # display the image dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() pangolin.FinishFrame()
Example #23
Source File: glutils.py From GDMC with ISC License | 4 votes |
def __init__(self, width, height, drawFunc): tex = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) GL.glTexParameter(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, None) self.enabled = False self._texID = tex if bool(FBO.glGenFramebuffers) and "Intel" not in GL.glGetString(GL.GL_VENDOR): buf = FBO.glGenFramebuffers(1) depthbuffer = FBO.glGenRenderbuffers(1) FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) FBO.glBindRenderbuffer(FBO.GL_RENDERBUFFER, depthbuffer) FBO.glRenderbufferStorage(FBO.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT, width, height) FBO.glFramebufferRenderbuffer(FBO.GL_FRAMEBUFFER, FBO.GL_DEPTH_ATTACHMENT, FBO.GL_RENDERBUFFER, depthbuffer) FBO.glFramebufferTexture2D(FBO.GL_FRAMEBUFFER, FBO.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, tex, 0) status = FBO.glCheckFramebufferStatus(FBO.GL_FRAMEBUFFER) if status != FBO.GL_FRAMEBUFFER_COMPLETE: print "glCheckFramebufferStatus", status self.enabled = False return FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, buf) with gl.glPushAttrib(GL.GL_VIEWPORT_BIT): GL.glViewport(0, 0, width, height) drawFunc() FBO.glBindFramebuffer(FBO.GL_FRAMEBUFFER, 0) FBO.glDeleteFramebuffers(1, [buf]) FBO.glDeleteRenderbuffers(1, [depthbuffer]) self.enabled = True else: GL.glReadBuffer(GL.GL_BACK) GL.glPushAttrib( GL.GL_VIEWPORT_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_TEST | GL.GL_STENCIL_BUFFER_BIT) GL.glDisable(GL.GL_STENCIL_TEST) GL.glViewport(0, 0, width, height) GL.glScissor(0, 0, width, height) with gl.glEnable(GL.GL_SCISSOR_TEST): drawFunc() GL.glBindTexture(GL.GL_TEXTURE_2D, tex) GL.glReadBuffer(GL.GL_BACK) GL.glCopyTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height) GL.glPopAttrib()
Example #24
Source File: ndwindow.py From spectral with MIT License | 4 votes |
def get_points_in_selection_box(self, **kwargs): '''Returns pixel IDs of all points in the current selection box. KEYWORD ARGS: `indices` (ndarray of ints): An alternate set of N-D image pixels to display. Pixels are identified by performing a background rendering loop wherein each pixel is rendered with a unique color. Then, glReadPixels is used to read colors of pixels in the current selection box. ''' import OpenGL.GL as gl indices = kwargs.get('indices', None) point_size_temp = self.point_size self.point_size = kwargs.get('point_size', 1) xsize = self._selection_box[2] - self._selection_box[0] + 1 ysize = self._selection_box[3] - self._selection_box[1] + 1 ids = np.zeros(xsize * ysize, int) self.create_display_lists(0, indices=indices) self.render_rgb_indexed_colors() gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) pixels = gl.glReadPixelsub(self._selection_box[0], self._selection_box[1], xsize, ysize, gl.GL_RGBA) pixels = np.frombuffer(pixels, dtype=np.uint8).reshape((ysize, xsize, 4)) for i in range(4): component = pixels[:, :, i].reshape((xsize * ysize,)) \ & self._rgba_masks[i] shift = (sum(self._rgba_bits[0:i]) - self._low_bits[i]) if shift > 0: ids += component.astype(int) << shift else: ids += component.astype(int) >> (-shift) points = ids[ids > 0] self.point_size = point_size_temp gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self._refresh_display_lists = True return points
Example #25
Source File: ndwindow.py From spectral with MIT License | 4 votes |
def on_paint(self, event): '''Renders the entire scene.''' 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() self.resize(*self.size) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) while len(self._display_commands) > 0: self._display_commands.pop(0)() if self._refresh_display_lists: self.create_display_lists() gl.glPushMatrix() # camera_pos_rtp is relative to target position. To get the absolute # camera position, we need to add the target position. 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)) if self.show_axes_tf: gl.glCallList(self.gllist_id) self.draw_data_set() gl.glPopMatrix() gl.glFlush() if self._selection_box is not None: self.draw_box(*self._selection_box) self.SwapBuffers() event.Skip()
Example #26
Source File: head_model_OGL.py From simnibs with GNU General Public License v3.0 | 4 votes |
def paintGL(self): GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() width = float(self.width()) height = float(self.height()) frustrumx = 60*width/self.sizeHint().width() frustrumy = 60*height/self.sizeHint().height() GL.glFrustum(-frustrumx, frustrumx, frustrumy, -frustrumy, 200, 500) GL.glMatrixMode(GL.GL_MODELVIEW) self.drawAxis() GL.glLoadIdentity() GL.glTranslatef(self.xTran, self.yTran, self.zTran) GL.glRotatef(self.xRot / 16.0, 1.0, 0.0, 0.0) GL.glRotatef(self.yRot / 16.0, 0.0, 1.0, 0.0) GL.glRotatef(self.zRot / 16.0, 0.0, 0.0, 1.0) GL.glScalef(-self.zoom,self.zoom,self.zoom) if self.model != 0: GL.glCallList(self.model) if self.indicator: GL.glCallList(self.indicator) for stimulator in self.stimulator_objects: try: GL.glCallList(stimulator) except: pass for tmp in self.tmp_objects: try: GL.glCallList(tmp) except: pass try: GL.glCallList(self.eegReferences) except: pass try: GL.glCallList(self.eegPositions) except: pass self.model_matrix = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) self.projection_matrix = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)