Python OpenGL.GL.glViewport() Examples
The following are 21
code examples of OpenGL.GL.glViewport().
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: hellovr_glfw.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def render_companion_window(self): GL.glDisable(GL.GL_DEPTH_TEST) GL.glViewport(0, 0, self.companion_width, self.companion_height) GL.glBindVertexArray(self.companion_window_vao) GL.glUseProgram(self.companion_window_program) # render left eye (first half of index array) i_size = sizeof(c_uint16) count = int(self.companion_window_index_size / 2) GL.glBindTexture(GL.GL_TEXTURE_2D, self.left_eye_desc.resolve_texture_id) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) GL.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_SHORT, cast(0 * i_size, c_void_p)) # render right eye (second half of index array) GL.glBindTexture(GL.GL_TEXTURE_2D, self.right_eye_desc.resolve_texture_id) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) GL.glDrawElements(GL.GL_TRIANGLES, count, GL.GL_UNSIGNED_SHORT, cast(count * i_size, c_void_p)) GL.glBindVertexArray(0) GL.glUseProgram(0)
Example #2
Source File: widget.py From MCEdit-Unified with ISC License | 5 votes |
def gl_draw_all(self, root, offset): if not self.visible: return #from OpenGL import GL, GLU rect = self.rect.move(offset) if self.is_gl_container: self.gl_draw_self(root, offset) suboffset = rect.topleft for subwidget in self.subwidgets: subwidget.gl_draw_all(root, suboffset) else: try: surface = Surface(self.size, SRCALPHA) except: #size error? return self.draw_all(surface) data = image.tostring(surface, 'RGBA', 1) w, h = root.size GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, 0, h) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0)) GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glDrawPixels(self.width, self.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8')) GL.glPopAttrib() GL.glFlush()
Example #3
Source File: openglwidgets.py From MCEdit-Unified with ISC License | 5 votes |
def gl_draw_self(self, root, offset): rect = self.rect.move(offset) # GL_CLIENT_ALL_ATTRIB_BITS is borked: defined as -1 but # glPushClientAttrib insists on an unsigned long. #GL.glPushClientAttrib(0xffffffff) #GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS) GL.glViewport(rect.left, root.height - rect.bottom, rect.width, rect.height) self.gl_draw_viewport() #GL.glPopAttrib() #GL.glPopClientAttrib()
Example #4
Source File: hellovr_glfw.py From pyopenvr with BSD 3-Clause "New" or "Revised" License | 5 votes |
def render_stereo_targets(self): GL.glClearColor(0, 0, 0, 1) GL.glEnable(GL.GL_MULTISAMPLE) # Left Eye GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, self.left_eye_desc.render_framebuffer_id) GL.glViewport(0, 0, self.render_width, self.render_height) self.render_scene(openvr.Eye_Left) GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0) GL.glDisable(GL.GL_MULTISAMPLE) GL.glBindFramebuffer(GL.GL_READ_FRAMEBUFFER, self.left_eye_desc.render_framebuffer_id) GL.glBindFramebuffer(GL.GL_DRAW_FRAMEBUFFER, self.left_eye_desc.resolve_framebuffer_id) GL.glBlitFramebuffer( 0, 0, self.render_width, self.render_height, 0, 0, self.render_width, self.render_height, GL.GL_COLOR_BUFFER_BIT, GL.GL_LINEAR) GL.glBindFramebuffer(GL.GL_READ_FRAMEBUFFER, 0) GL.glBindFramebuffer(GL.GL_DRAW_FRAMEBUFFER, 0) # Right Eye GL.glEnable(GL.GL_MULTISAMPLE) GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, self.right_eye_desc.render_framebuffer_id) GL.glViewport(0, 0, self.render_width, self.render_height) self.render_scene(openvr.Eye_Right) GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0) GL.glDisable(GL.GL_MULTISAMPLE) GL.glBindFramebuffer(GL.GL_READ_FRAMEBUFFER, self.right_eye_desc.render_framebuffer_id) GL.glBindFramebuffer(GL.GL_DRAW_FRAMEBUFFER, self.right_eye_desc.resolve_framebuffer_id) GL.glBlitFramebuffer( 0, 0, self.render_width, self.render_height, 0, 0, self.render_width, self.render_height, GL.GL_COLOR_BUFFER_BIT, GL.GL_LINEAR) GL.glBindFramebuffer(GL.GL_READ_FRAMEBUFFER, 0) GL.glBindFramebuffer(GL.GL_DRAW_FRAMEBUFFER, 0)
Example #5
Source File: hypercube.py From spectral with MIT License | 5 votes |
def resize(self, width, height): """Reshape the OpenGL viewport based on dimensions of the window.""" import OpenGL.GL as gl import OpenGL.GLU as glu self.size = (width, height) gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(self.fovy, float(width) / height, self.znear, self.zfar) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
Example #6
Source File: ndwindow.py From spectral with MIT License | 5 votes |
def resize(self, width, height): """Reshape the OpenGL viewport based on dimensions of the window.""" import OpenGL.GL as gl import OpenGL.GLU as glu self.size = (width, height) gl.glViewport(0, 0, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() glu.gluPerspective(self.fovy, float(width) / height, self.znear, self.zfar) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity()
Example #7
Source File: openglwidgets.py From GDMC with ISC License | 5 votes |
def gl_draw_self(self, root, offset): rect = self.rect.move(offset) # GL_CLIENT_ALL_ATTRIB_BITS is borked: defined as -1 but # glPushClientAttrib insists on an unsigned long. #GL.glPushClientAttrib(0xffffffff) #GL.glPushAttrib(GL.GL_ALL_ATTRIB_BITS) GL.glViewport(rect.left, root.height - rect.bottom, rect.width, rect.height) self.gl_draw_viewport() #GL.glPopAttrib() #GL.glPopClientAttrib()
Example #8
Source File: widget.py From GDMC with ISC License | 5 votes |
def gl_draw_all(self, root, offset): if not self.visible: return from OpenGL import GL, GLU rect = self.rect.move(offset) if self.is_gl_container: self.gl_draw_self(root, offset) suboffset = rect.topleft for subwidget in self.subwidgets: subwidget.gl_draw_all(root, suboffset) else: try: surface = Surface(self.size, SRCALPHA) except Exception: #size error? return self.draw_all(surface) data = image.tostring(surface, 'RGBA', 1) w, h = root.size GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, 0, h) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0)) GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glDrawPixels(self.width, self.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8')) GL.glPopAttrib() GL.glFlush()
Example #9
Source File: fullscreen_quad.py From dm_control with Apache License 2.0 | 5 votes |
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 #10
Source File: opengl_test.py From PFramer with GNU General Public License v3.0 | 5 votes |
def resizeGL(self, width, height): side = min(width, height) GL.glViewport((width - side) / 2, (height - side) / 2, side, side) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0) GL.glMatrixMode(GL.GL_MODELVIEW)
Example #11
Source File: gui-glut.py From filmkodi with Apache License 2.0 | 5 votes |
def resize(width,height): gl.glViewport(0, 0, width, height+4) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height+4, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
Example #12
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 #13
Source File: PlotCurveItem.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
def paintGL(self, p, opt, widget): p.beginNativePainting() import OpenGL.GL as gl ## set clipping viewport view = self.getViewBox() if view is not None: rect = view.mapRectToItem(self, view.boundingRect()) #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height())) #gl.glTranslate(-rect.x(), -rect.y(), 0) gl.glEnable(gl.GL_STENCIL_TEST) gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer gl.glDepthMask(gl.GL_FALSE) # disable drawing to depth buffer gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF) gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP) ## draw stencil pattern gl.glStencilMask(0xFF) gl.glClear(gl.GL_STENCIL_BUFFER_BIT) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(rect.x(), rect.y()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glEnd() gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE) gl.glDepthMask(gl.GL_TRUE) gl.glStencilMask(0x00) gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF) try: x, y = self.getData() pos = np.empty((len(x), 2)) pos[:,0] = x pos[:,1] = y gl.glEnableClientState(gl.GL_VERTEX_ARRAY) try: gl.glVertexPointerf(pos) pen = fn.mkPen(self.opts['pen']) color = pen.color() gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.) width = pen.width() if pen.isCosmetic() and width < 1: width = 1 gl.glPointSize(width) gl.glEnable(gl.GL_LINE_SMOOTH) 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.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1]) finally: gl.glDisableClientState(gl.GL_VERTEX_ARRAY) finally: p.endNativePainting()
Example #14
Source File: PlotCurveItem.py From soapy with GNU General Public License v3.0 | 4 votes |
def paintGL(self, p, opt, widget): p.beginNativePainting() import OpenGL.GL as gl ## set clipping viewport view = self.getViewBox() if view is not None: rect = view.mapRectToItem(self, view.boundingRect()) #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height())) #gl.glTranslate(-rect.x(), -rect.y(), 0) gl.glEnable(gl.GL_STENCIL_TEST) gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer gl.glDepthMask(gl.GL_FALSE) # disable drawing to depth buffer gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF) gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP) ## draw stencil pattern gl.glStencilMask(0xFF) gl.glClear(gl.GL_STENCIL_BUFFER_BIT) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(rect.x(), rect.y()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glEnd() gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE) gl.glDepthMask(gl.GL_TRUE) gl.glStencilMask(0x00) gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF) try: x, y = self.getData() pos = np.empty((len(x), 2)) pos[:,0] = x pos[:,1] = y gl.glEnableClientState(gl.GL_VERTEX_ARRAY) try: gl.glVertexPointerf(pos) pen = fn.mkPen(self.opts['pen']) color = pen.color() gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.) width = pen.width() if pen.isCosmetic() and width < 1: width = 1 gl.glPointSize(width) gl.glEnable(gl.GL_LINE_SMOOTH) 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.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1]) finally: gl.glDisableClientState(gl.GL_VERTEX_ARRAY) finally: p.endNativePainting()
Example #15
Source File: blipdriver.py From bluesky with GNU General Public License v3.0 | 4 votes |
def paintGL(self): """Paint the scene.""" # pass if the framebuffer isn't complete yet or if not initialized if not (gl.glCheckFramebufferStatus(gl.GL_FRAMEBUFFER) == gl.GL_FRAMEBUFFER_COMPLETE and self.isVisible() and self.initialized): return gl.glClearColor(0, 0, 0, 0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) # Set the viewport and clear the framebuffer # --- Draw the ND in its viewport ---- gl.glViewport(*self.ndviewport) self.color_shader.use() self.arcs.draw() self.ownship.draw() self.mask.draw() self.edge.draw() self.ticks.draw() # Select the text shader self.text_shader.use() self.font.use() self.font.set_block_size((0, 0)) self.globaldata.set_vertex_modifiers(VERTEX_IS_GLXY, True) self.ticklbls.draw() self.globaldata.set_vertex_modifiers(VERTEX_IS_GLXY, False) self.spdlabel_text.draw() self.spdlabel_val.draw() # --- Draw the MCP in its viewport --- gl.glViewport(*self.mcpviewport) self.mcp_tex_shader.use() gl.glActiveTexture(gl.GL_TEXTURE0 + 0) gl.glBindTexture(gl.GL_TEXTURE_2D, self.mcp_texture) self.mcp.draw() gl.glBindTexture(gl.GL_TEXTURE_2D, self.btn_tex) self.btn_leds.draw() if self.updownpos is not None: self.mcp_col_shader.use() gl.glVertexAttrib2f(2, *self.updownpos) self.updown.draw() gl.glVertexAttrib2f(2, 0.0, 0.0) self.mcp_txt_shader.use() gl.glActiveTexture(gl.GL_TEXTURE0 + 0) gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.lcd_tex) self.mcp_text.draw() # Unbind everything RenderObject.unbind_all() gl.glUseProgram(0)
Example #16
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 #17
Source File: controller.py From renpy-shader with MIT License | 4 votes |
def renderImage(self, context): width, height = self.getSize() gl.glViewport(0, 0, width, height) gl.glDisable(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, 0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.frameBuffer.bind() self.renderer.render(context) self.frameBuffer.unbind() #TODO Restore blend state. Any other states that need restoring...? gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
Example #18
Source File: PlotCurveItem.py From tf-pose with Apache License 2.0 | 4 votes |
def paintGL(self, p, opt, widget): p.beginNativePainting() import OpenGL.GL as gl ## set clipping viewport view = self.getViewBox() if view is not None: rect = view.mapRectToItem(self, view.boundingRect()) #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height())) #gl.glTranslate(-rect.x(), -rect.y(), 0) gl.glEnable(gl.GL_STENCIL_TEST) gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer gl.glDepthMask(gl.GL_FALSE) # disable drawing to depth buffer gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF) gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP) ## draw stencil pattern gl.glStencilMask(0xFF) gl.glClear(gl.GL_STENCIL_BUFFER_BIT) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(rect.x(), rect.y()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glEnd() gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE) gl.glDepthMask(gl.GL_TRUE) gl.glStencilMask(0x00) gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF) try: x, y = self.getData() pos = np.empty((len(x), 2)) pos[:,0] = x pos[:,1] = y gl.glEnableClientState(gl.GL_VERTEX_ARRAY) try: gl.glVertexPointerf(pos) pen = fn.mkPen(self.opts['pen']) color = pen.color() gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.) width = pen.width() if pen.isCosmetic() and width < 1: width = 1 gl.glPointSize(width) gl.glEnable(gl.GL_LINE_SMOOTH) 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.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1]) finally: gl.glDisableClientState(gl.GL_VERTEX_ARRAY) finally: p.endNativePainting()
Example #19
Source File: electrodeGUI.py From simnibs with GNU General Public License v3.0 | 3 votes |
def resizeGL(self, width, height): side = min(width, height) GL.glViewport((width - side) // 2, (height - side) // 2, side, side) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() #GL.glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0) GL.glFrustum(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0) GL.glMatrixMode(GL.GL_MODELVIEW)
Example #20
Source File: gui-glut.py From PyDev.Debugger with Eclipse Public License 1.0 | 2 votes |
def resize(width,height): gl.glViewport(0, 0, width, height+4) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, width, 0, height+4, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW)
Example #21
Source File: head_model_OGL.py From simnibs with GNU General Public License v3.0 | 2 votes |
def resizeGL(self, width, height): GL.glViewport(0, 0, width, height) self.view = [0, 0, width, height]