def stencilPush(): '''Create a new stack in stencil stack. All the next draw will be done in stencil buffer until stencilUse() will be called.''' global __stencil_stack glPushAttrib(GL_STENCIL_BUFFER_BIT | GL_STENCIL_TEST) # enable stencil test if not yet enabled if not glIsEnabled(GL_STENCIL_TEST): glClearStencil(0) glClear(GL_STENCIL_BUFFER_BIT) glEnable(GL_STENCIL_TEST) # increment the draw buffer glStencilFunc(GL_NEVER, 0x0, 0x0) glStencilOp(GL_INCR, GL_INCR, GL_INCR) glColorMask(0, 0, 0, 0) # save model view m = glGetFloatv(GL_MODELVIEW_MATRIX) __stencil_stack_view.append(m) # start recording GL operation dl = GlDisplayList() dl.start() __stencil_stack_dl.append(dl) __stencil_stack += 1
def drawGrid(self): grids_per_screen = 10 eye_dist = self.camera_xyz[2] meters_per_grid = round_to_125(eye_dist / grids_per_screen) num_lines = 300 glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LINE_BIT) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_DEPTH_TEST) glPushMatrix() glTranslatef(0, 0, 0) glColor3f(0.2, 0.2, 0.2) glBegin(GL_LINES) for i in range(num_lines): glVertex2f((-num_lines / 2 + i) * meters_per_grid, -num_lines / 2 * meters_per_grid) glVertex2f((-num_lines / 2 + i) * meters_per_grid, num_lines / 2 * meters_per_grid) glVertex2f(-num_lines / 2 * meters_per_grid, (-num_lines / 2 + i) * meters_per_grid) glVertex2f(num_lines / 2 * meters_per_grid, (-num_lines / 2 + i) * meters_per_grid) glEnd() glPopMatrix() glPopAttrib()
def render(self): ''' ''' super(Shaft, self).render() glPushAttrib(GL_CURRENT_BIT) n = int(self.length) lim = n - 1 if self.orientation in ['down', 'forward', 'backward']: lim = 0 self._set_material() # print lim for i in range(n): glPushMatrix() glTranslatef(0, i / 2.0, 0) if i == lim: self._can_(0.66, 0.5) self._cylinder_(0.5, 0.5) glPopMatrix() # if self.state and animate: # if ac % 20 == 0 and self.prev_ac != ac: # if self.orientation == 'left' or self.orientation == 'up': # self.colorlist = shift(self.colorlist) # else: # self.colorlist = deshift(self.colorlist) # self.prev_ac = ac glPopAttrib()
def draw(self, camera_matrix: numpy.ndarray, camera_position: PointCoordinatesAny = None): """ Draw the selection box :param camera_matrix: 4x4 transformation matrix for the camera :param camera_position: The position of the camera. Used to flip draw direction if camera inside box. :return: """ self._setup() if self._rebuild: self._create_geometry() self._draw_mode = GL_TRIANGLES transformation_matrix = numpy.matmul(camera_matrix, self.transformation_matrix) glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_POLYGON_BIT) # store opengl state if camera_position is not None and camera_position in self: glCullFace(GL_FRONT) else: glCullFace(GL_BACK) self.draw_start = 0 self.draw_count = 36 super()._draw(transformation_matrix) # draw the lines around the boxes glDisable(GL_DEPTH_TEST) self._draw_mode = GL_LINE_STRIP super()._draw(transformation_matrix) glPopAttrib() # reset to starting state
def bind(self): super(HardwareFbo, self).bind() HardwareFbo.fbo_stack.append(self.framebuffer) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.framebuffer) if self.push_viewport: glPushAttrib(GL_VIEWPORT_BIT) glViewport(0, 0, self.size[0], self.size[1])
def render(self, text: str) -> None: glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glEnable(GL_BLEND) glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA) pen = numpy.array([0.0, 0.0]) for i in range(len(text)): char = text[i] if char not in self._glyphs: self._glyphs[char] = _Glyph(self._face, char) self._glyphs[char].render(pen) pen += self._glyphs[char].advance if i + 1 < len(text): kerning = self._face.get_kerning( self._face.get_char_index(char), self._face.get_char_index(text[i + 1])) pen += numpy.array([kerning.x / 64.0, kerning.y / 64.0]) glPopAttrib()
def draw(self): '''Draw the mesh on screen (using display list if compiled)''' if self.list: glCallList(self.list) return glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT) glEnable(GL_CULL_FACE) glCullFace(GL_BACK) for group in self.groups: if group.material: group.material.apply() if group.array is None: if group.material and group.material.texture: if group.material.texture.rectangle: # texture is a rectangle texture # that's mean we need to adjust the range of texture # coordinate from original 0-1 to 0-width/0-height group.vertices[0::8] = map( lambda x: x * group.material.texture.width, group.vertices[0::8]) group.vertices[1::8] = map( lambda x: x * group.material.texture.height, group.vertices[1::8]) group.array = (GLfloat * len(group.vertices))(*group.vertices) group.triangles = len(group.vertices) / 8 glInterleavedArrays(GL_T2F_N3F_V3F, 0, group.array) glDrawArrays(GL_TRIANGLES, 0, group.triangles) if group.material: group.material.unapply() glPopAttrib() glPopClientAttrib()
def draw(self): '''Draw the mesh on screen (using display list if compiled)''' if self.list: glCallList(self.list) return glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT) glEnable(GL_CULL_FACE) glCullFace(GL_BACK) for group in self.groups: if group.material: group.material.apply() if group.array is None: if group.material and group.material.texture: if group.material.texture.rectangle: # texture is a rectangle texture # that's mean we need to adjust the range of texture # coordinate from original 0-1 to 0-width/0-height group.vertices[0::8] = map( lambda x: x * group.material.texture.width, group.vertices[0::8] ) group.vertices[1::8] = map( lambda x: x * group.material.texture.height, group.vertices[1::8] ) group.array = (GLfloat * len(group.vertices))(*group.vertices) group.triangles = len(group.vertices) / 8 glInterleavedArrays(GL_T2F_N3F_V3F, 0, group.array) glDrawArrays(GL_TRIANGLES, 0, group.triangles) if group.material: group.material.unapply() glPopAttrib() glPopClientAttrib()
def draw(self, camera_matrix: numpy.ndarray): """Draw all of the levels.""" for level, transform, is_mirrored in zip(self._objects, self._transformation_matrices, self._is_mirrored): glPushAttrib(GL_POLYGON_BIT) # store opengl state if is_mirrored: glCullFace(GL_FRONT) else: glCullFace(GL_BACK) level.draw(numpy.matmul(camera_matrix, transform)) glPopAttrib() # reset to starting state
def _draw_orbitals(self): r = 1.5 glPushAttrib(GL_CURRENT_BIT) self._set_material((0, 0, 1)) for a in [60, -60, 0]: glPushMatrix() glRotatef(a, 1, 0, 0) glTranslatef(0, 0, -0.25 / 2) self._torus_(radius=r, inner_radius=0.15, xs=25, ys=25 ) glPopMatrix() glPopAttrib()
def render(self): ''' ''' super(Bone, self).render() glPushAttrib(GL_CURRENT_BIT) glPushMatrix() self._set_material() # glTranslatef(0, 0, 0) self._cube_() for _i in range(self.length - 1): glTranslatef(1, 0, 0) self._cube_() glPopMatrix() glPopAttrib()
def render(self): ''' ''' super(Turbo, self).render() if self.identify: tag = self.name.split('_') tag = ' '.join([i.capitalize() for i in tag]) self._text_(tag, [-2, 2]) glPushAttrib(GL_CURRENT_BIT) glPushMatrix() self._set_material(color=[0, 0, 0]) glTranslatef(0, 0.5, 0) ac = 1 glPushMatrix() glRotatef(ac * 5, 0, 1, 0) self._fan_() glPopMatrix() glPushMatrix() glRotatef(-ac * 5, 0, 1, 0) glTranslatef(0, 0.5, 0) self._fan_() glPopMatrix() glPushMatrix() glRotatef(ac * 5, 0, 1, 0) glTranslatef(0, 1, 0) self._fan_() glPopMatrix() glPopMatrix() glPopAttrib() # self._set_material() # draw main body glPushAttrib(GL_CURRENT_BIT) for r, h, alpha in [(1, 3, 0.5), (1.5, 0.5, False)]: self._set_material(alpha=alpha) glTranslatef(0, h, 0) self._can_(radius=r, height=h) glPopAttrib()
def drawGround(self): GROUND_SIZE = 1000 glColor3f(0.9, 0.9, 0.9) glPushAttrib(GL_POLYGON_BIT) glEnable(GL_POLYGON_OFFSET_FILL) glPolygonOffset(2.0, 2.0) glDisable(GL_COLOR_MATERIAL) glPushMatrix() glTranslatef(0, 0, 0) glScalef(GROUND_SIZE, GROUND_SIZE, 1.0) glBegin(GL_QUADS) glVertex2d(1, 1) glVertex2d(1, -1) glVertex2d(-1, -1) glVertex2d(-1, 1) glEnd() glPopMatrix() glPopAttrib()
def drawpolycone_multicolor_worker(params): """ Draw a polycone. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) piotr 080311: this variant accepts a color array as an additional parameter """ (pos_array, color_array, rad_array) = params glEnable(GL_COLOR_MATERIAL) # have to enable GL_COLOR_MATERIAL for # the GLE function glPushAttrib(GL_CURRENT_BIT) # store current attributes in case glePolyCone # modifies the (e.g. current color) # piotr 080411 glePolyCone(pos_array, color_array, rad_array) glPopAttrib() # This fixes the 'disappearing cylinder' bug # glPopAttrib doesn't take any arguments # piotr 080415 glDisable(GL_COLOR_MATERIAL) return
def bind(self): super(SoftwareFbo, self).bind() # Save current buffer w = pymt.getWindow() glReadBuffer(GL_BACK) self.pixels = glReadPixels(0, 0, w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE) # Push current attrib glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_TEST | GL_STENCIL_BUFFER_BIT) glDisable(GL_STENCIL_TEST) # Save viewport if asked if self.push_viewport: glPushAttrib(GL_VIEWPORT_BIT) glViewport(0, 0, self.size[0], self.size[1]) # Draw old Framebuffer set_color(1, 1, 1) drawTexturedRectangle(self.texture, size=self.size)
def drawpolycone_multicolor_worker(params): """ Draw a polycone. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) piotr 080311: this variant accepts a color array as an additional parameter """ (pos_array, color_array, rad_array) = params glEnable(GL_COLOR_MATERIAL) # have to enable GL_COLOR_MATERIAL for # the GLE function glPushAttrib( GL_CURRENT_BIT) # store current attributes in case glePolyCone # modifies the (e.g. current color) # piotr 080411 glePolyCone(pos_array, color_array, rad_array) glPopAttrib() # This fixes the 'disappearing cylinder' bug # glPopAttrib doesn't take any arguments # piotr 080415 glDisable(GL_COLOR_MATERIAL) return
def drawItemTree(self, item=None, useItemNames=False): """ :param item: :param useItemNames: :return: """ if item is None: items = [x for x in self.items if x.parentItem() is None] else: items = item.childItems() items.append(item) for i in items: if not i.visible(): continue if i is item: try: glPushAttrib(GL_ALL_ATTRIB_BITS) if useItemNames: glLoadName(i._id) self._itemNames[i._id] = i i.paint() except GLError as ex: _log.info("Error while drawing items: {}".format(ex)) if CONFIG.debug: raise finally: glPopAttrib() else: glMatrixMode(GL_MODELVIEW) glPushMatrix() try: tr = i.transform() a = np.array(tr.copyDataTo()).reshape((4, 4)) glMultMatrixf(a.transpose()) self.drawItemTree(i, useItemNames=useItemNames) finally: glMatrixMode(GL_MODELVIEW) glPopMatrix()
def render(self): ''' ''' # super(Laser, self).render() MultiStateObject3D.render(self) glPushAttrib(GL_CURRENT_BIT) self._set_material() glPushMatrix() glRotatef(90, 1, 0, 0) self._disk_() glPopMatrix() glPushMatrix() glTranslatef(0, -1, 0) glRotatef(90, 1, 0, 0) self._disk_() glPopMatrix() self._cylinder_(1, 1) glPopAttrib()
def _draw_halo(self): glPushAttrib(GL_CURRENT_BIT) self._set_material((1, 1, 0), alpha=0.3) self._sphere_(radius=1.5) glPopAttrib()
def __enter__(self): glPushAttrib(GL_COLOR_BUFFER_BIT) if len(self.color) == 3: glColor3f(*self.color) else: glColor4f(*self.color)
def drawCSSRectangle(pos=(0, 0), size=(100, 100), style=dict(), prefix=None, state=None): '''Draw a rectangle with CSS :Parameters: `state`: if a certain state string is passed, we will use styles with this postifx instead. for example: style[bg-color] and style[bg-color-down] are both set. if state == "down", we wil use bg-color-down instead of bg-color :Styles: * alpha-background (color) * border-radius (float) * border-radius-precision (float) * border-width (float) * draw-alpha-background (bool) * draw-background (bool) * draw-border (bool) ''' bg_image = style.get('bg-image-'+str(state)) if not bg_image: bg_image = style.get('bg-image') # Check if we have a cached version cache_id = '%s:%s:%s:%s:%s' % (pos, size, style, prefix, state) cache = Cache.get('pymt.cssrect', cache_id) if cache: cache.draw() if bg_image: bg_image.size = size bg_image.pos = pos bg_image.draw() return # lets use the ones for given state, # and ignore the regular ones if the state ones are there if state: state = "-" + state newstyle = {} overwrites = [] for s in style: if state in s: overwrite = s.replace(state, '') newstyle[overwrite] = style[s] overwrites.append(overwrite) if s not in overwrites: newstyle[s] = style[s] style = newstyle # hack to remove prefix in style if prefix is not None: prefix += '-' newstyle = {} for k in style: newstyle[k] = style[k] for k in style: if prefix in k: newstyle[k.replace(prefix, '')] = style[k] style = newstyle style.setdefault('border-width', 1.5) style.setdefault('border-radius', 0) style.setdefault('border-radius-precision', .1) style.setdefault('draw-border', 0) style.setdefault('draw-background', 1) style.setdefault('draw-alpha-background', 0) style.setdefault('alpha-background', (1, 1, .5, .5)) k = { 'pos': pos, 'size': size } new_cache = GlDisplayList() with new_cache: if state: set_color(*style['bg-color']) #hack becasue old widgets set this themselves linewidth = style.get('border-width') bordercolor = None if 'border-color' in style: bordercolor = style['border-color'] if style['border-radius'] > 0: k.update({ 'radius': style['border-radius'], 'precision': style['border-radius-precision'] }) if style['draw-background']: drawRoundedRectangle(**k) if style['draw-border']: if linewidth: glPushAttrib(GL_LINE_BIT) glLineWidth(linewidth) if bordercolor: with gx_color(*bordercolor): drawRoundedRectangle(style=GL_LINE_LOOP, **k) else: drawRoundedRectangle(style=GL_LINE_LOOP, **k) if linewidth: glPopAttrib() if style['draw-alpha-background']: drawRoundedRectangleAlpha(alpha=style['alpha-background'], **k) else: if style['draw-background']: drawRectangle(**k) if style['draw-border']: if linewidth: glPushAttrib(GL_LINE_BIT) glLineWidth(linewidth) if bordercolor: with gx_color(*bordercolor): drawRectangle(style=GL_LINE_LOOP, **k) else: drawRectangle(style=GL_LINE_LOOP, **k) if linewidth: glPopAttrib() if style['draw-alpha-background']: drawRectangleAlpha(alpha=style['alpha-background'], **k) # if the drawCSSRectangle is already inside a display list # compilation will not happen, but drawing yes. # so, store only if a cache is created ! if new_cache.is_compiled(): Cache.append('pymt.cssrect', cache_id, new_cache) new_cache.draw() if bg_image: bg_image.size = size bg_image.pos = pos bg_image.draw()
def _enable_stereo(self, stereo_image, preserve_colors = False, no_clipping = False): """ Enables stereo rendering. This should be called before entering a drawing phase and should be accompanied by a self._disable_stereo call after the drawing for that phase. These methods push a modelview matrix on the matrix stack and modify the matrix. @param stereo_image: Indicates which stereo image is being drawn (-1 == left, 1 == right, 0 == stereo is disabled) @param preserve_colors: Disable color mask manipulations, which normally occur in anaglyph mode. (Also disable depth buffer clearing for 2nd image, which occurs then.) @param no_clipping: Disable clipping, which normally occurs in side-by-side mode. """ if not self.stereo_enabled: return glPushAttrib(GL_TRANSFORM_BIT) stereo_mode = self.stereo_mode stereo_separation = self.stereo_separation stereo_angle = self.stereo_angle # push the modelview matrix on the stack glMatrixMode(GL_MODELVIEW) glPushMatrix() separation = stereo_separation * self.scale angle = stereo_angle # might be modified below if stereo_mode <= 2: # side-by-side stereo mode # clip left or right image # reset the modelview matrix if not no_clipping: glPushMatrix() # Note: this might look redundant with the # glPushMatrix above, but removing it (and its glPopMatrix # 10 lines below) causes a bug (no image visible). # Guess: it's needed so the glLoadIdentity needed to set up # the clipping plane just below has only a temporary effect. # [bruce 080911 comment] glLoadIdentity() if stereo_image == -1: clip_eq = (-1.0, 0.0, 0.0, 0.0) else: clip_eq = ( 1.0, 0.0, 0.0, 0.0) # using GL_CLIP_PLANE5 for stereo clipping glClipPlane(GL_CLIP_PLANE5, clip_eq) glEnable(GL_CLIP_PLANE5) glPopMatrix() # for cross-eyed mode, exchange left and right views if stereo_mode == 2: angle *= -1 # translate images for side-by-side stereo glTranslatef(separation * stereo_image * self.right[0], separation * stereo_image * self.right[1], separation * stereo_image * self.right[2]) # rotate the stereo image ("toe-in" method) glRotatef(angle * stereo_image, self.up[0], self.up[1], self.up[2]) else: # Anaglyphs stereo mode - Red plus Blue, Cyan, or Green image. angle *= 0.5 if not preserve_colors: if stereo_image == -1: # red image glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE) else: # clear depth buffer to combine red/blue images # REVIEW: this would cause bugs in the predraw_glselectdict code # used for depth-testing selobj candidates. Maybe it does # not happen then? The name of the flag 'preserve_colors' # does not say anything about preserving depths. # Anyway, it *does* happen then, so I think there is a bug. # Also, remind me, what's the 4th arg to glColorMask? # [bruce 080911 comment] # # piotr 080911 response: You are right. This technically # causes a bug: the red image is not highlightable, # but actually when using anaglyph glasses, the bug is not # noticeable, as both red and blue images converge. # The bug becomes noticeable if user tries to highlight an # object without wearing the anaglyph glasses. # At this point, I think we can either leave it as it is, # or consider implementing anaglyph stereo by using # OpenGL alpha blending. # Also, I am not sure if highlighting problem is the only bug # that is caused by clearing the GL_DEPTH_BUFFER_BIT. glClear(GL_DEPTH_BUFFER_BIT) if stereo_mode == 3: # blue image glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE) elif stereo_mode == 4: # cyan image glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE) elif stereo_mode == 5: # green image glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE) # rotate the stereo image ("toe-in" method) glRotatef(angle * stereo_image, self.up[0], self.up[1], self.up[2]) return
def __enter__(self): glPushAttrib(self.flag)
def bind(self): '''Bind the texture on the current context / texture unit''' target = self.get_target() glPushAttrib(GL_ENABLE_BIT) glEnable(target) glBindTexture(target, self.get_id())
def _enable_stereo(self, stereo_image, preserve_colors=False, no_clipping=False): """ Enables stereo rendering. This should be called before entering a drawing phase and should be accompanied by a self._disable_stereo call after the drawing for that phase. These methods push a modelview matrix on the matrix stack and modify the matrix. @param stereo_image: Indicates which stereo image is being drawn (-1 == left, 1 == right, 0 == stereo is disabled) @param preserve_colors: Disable color mask manipulations, which normally occur in anaglyph mode. (Also disable depth buffer clearing for 2nd image, which occurs then.) @param no_clipping: Disable clipping, which normally occurs in side-by-side mode. """ if not self.stereo_enabled: return glPushAttrib(GL_TRANSFORM_BIT) stereo_mode = self.stereo_mode stereo_separation = self.stereo_separation stereo_angle = self.stereo_angle # push the modelview matrix on the stack glMatrixMode(GL_MODELVIEW) glPushMatrix() separation = stereo_separation * self.scale angle = stereo_angle # might be modified below if stereo_mode <= 2: # side-by-side stereo mode # clip left or right image # reset the modelview matrix if not no_clipping: glPushMatrix() # Note: this might look redundant with the # glPushMatrix above, but removing it (and its glPopMatrix # 10 lines below) causes a bug (no image visible). # Guess: it's needed so the glLoadIdentity needed to set up # the clipping plane just below has only a temporary effect. # [bruce 080911 comment] glLoadIdentity() if stereo_image == -1: clip_eq = (-1.0, 0.0, 0.0, 0.0) else: clip_eq = (1.0, 0.0, 0.0, 0.0) # using GL_CLIP_PLANE5 for stereo clipping glClipPlane(GL_CLIP_PLANE5, clip_eq) glEnable(GL_CLIP_PLANE5) glPopMatrix() # for cross-eyed mode, exchange left and right views if stereo_mode == 2: angle *= -1 # translate images for side-by-side stereo glTranslatef(separation * stereo_image * self.right[0], separation * stereo_image * self.right[1], separation * stereo_image * self.right[2]) # rotate the stereo image ("toe-in" method) glRotatef(angle * stereo_image, self.up[0], self.up[1], self.up[2]) else: # Anaglyphs stereo mode - Red plus Blue, Cyan, or Green image. angle *= 0.5 if not preserve_colors: if stereo_image == -1: # red image glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE) else: # clear depth buffer to combine red/blue images # REVIEW: this would cause bugs in the predraw_glselectdict code # used for depth-testing selobj candidates. Maybe it does # not happen then? The name of the flag 'preserve_colors' # does not say anything about preserving depths. # Anyway, it *does* happen then, so I think there is a bug. # Also, remind me, what's the 4th arg to glColorMask? # [bruce 080911 comment] # # piotr 080911 response: You are right. This technically # causes a bug: the red image is not highlightable, # but actually when using anaglyph glasses, the bug is not # noticeable, as both red and blue images converge. # The bug becomes noticeable if user tries to highlight an # object without wearing the anaglyph glasses. # At this point, I think we can either leave it as it is, # or consider implementing anaglyph stereo by using # OpenGL alpha blending. # Also, I am not sure if highlighting problem is the only bug # that is caused by clearing the GL_DEPTH_BUFFER_BIT. glClear(GL_DEPTH_BUFFER_BIT) if stereo_mode == 3: # blue image glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE) elif stereo_mode == 4: # cyan image glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE) elif stereo_mode == 5: # green image glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE) # rotate the stereo image ("toe-in" method) glRotatef(angle * stereo_image, self.up[0], self.up[1], self.up[2]) return
def processFrame(self, timePassedSecs): """ draws a scene """ # update the model view matrix self.sceneCamera.updateKeys() self.sceneCamera.update() # process queued GLObject events GLObject.signalsEmit() # enable some default scene states glEnable(GL_DEPTH_TEST) ######## SHADOW MAP RENDERING START ######## # offset the geometry slightly to prevent z-fighting # note that this introduces some light-leakage artifacts glEnable(GL_POLYGON_OFFSET_FILL) glPolygonOffset(1.1, 4096.0) # cull front faces for shadow rendering, # this moves z-fighting to backfaces. glCullFace(GL_FRONT) # enable depth rendering shader. # FIXME: support segment geometry shader! # geometry shader could change the shadow shape! self.depthShader.enable() map(_updateLightShadowMap, self.lights) glBindFramebuffer(GL_FRAMEBUFFER, 0) glDisable(GL_POLYGON_OFFSET_FILL) ######## SHADOW MAP RENDERING STOP ######## #### TODO: FOG: integrate FOG #### glEnable(GL_FOG) glFogi(GL_FOG_MODE, GL_EXP2) # approximate the atmosphere's filtering effect as a linear function sunDir = array([4.0, 4.0, 4.0, 0.0], float32) # TODO: FOG: what is the sun dir ? skyColor = array([0.8, sunDir[1] * 0.1 + 0.7, sunDir[1] * 0.4 + 0.5, 1.0], float32) glClearColor(*skyColor) glFogf(GL_FOG_DENSITY, 0.4) glFogf(GL_FOG_START, 16.0) glFogf(GL_FOG_END, self.farClip) glFogfv(GL_FOG_COLOR, skyColor) # fill projection matrix glMatrixMode(GL_PROJECTION) glLoadMatrixf(self.projectionMatrix) glMatrixMode(GL_MODELVIEW) # draw stuff in 3d projection lastCam = None glPushAttrib(GL_COLOR_BUFFER_BIT) for (fbo, draw, cam) in self.sceneFBOS: # render to fbo fbo.enable() if cam != lastCam: cam.enable() lastCam = cam draw() # disable render to texture FBO.disable() glPopAttrib() glViewport(0, 0, self.winSize[0], self.winSize[1]) #### TODO: FOG: integrate FOG #### glDisable(GL_FOG) # change to orthogonal projection glMatrixMode(GL_PROJECTION) glLoadMatrixf(self.orthoMatrix) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # no depth test needed in orthogonal rendering glDisable(GL_DEPTH_TEST) # draw orthogonal to the screen self.orthogonalPass()