def bind_texture_region(texture, x, y, w, h, premultiplied=False, flip=False): gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_BLEND) if premultiplied: gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA) else: gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glViewport(x, y, w, h) gl.glScissor(x, y, w, h) gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, Manager.col_buffer.gl_buffer) gl.glFramebufferTexture2DEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, texture.target, texture.id, 0) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() if flip: gl.gluOrtho2D(0, w, h, 0) else: gl.gluOrtho2D(0, w, 0, h)
def set_state(self): """ Enables a scissor test on our region """ gl.glPushAttrib(gl.GL_ENABLE_BIT | gl.GL_TRANSFORM_BIT | gl.GL_CURRENT_BIT) self.was_scissor_enabled = gl.glIsEnabled(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(int(self.x), int(self.y), int(self.width), int(self.height))
def preDraw(self): """Called right before this layer draws; establishes e.g. scissor box and scaling.""" if self._scissorBox is not None: gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(*self._scissorBox) self._layerProjectLocalToScreen()
def bind_window(w, h): gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glViewport(0, 0, w, h) gl.glScissor(0, 0, w, h); gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.gluOrtho2D(0, w, h, 0)
def bind_window(w, h): gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glViewport(0, 0, w, h) gl.glScissor(0, 0, w, h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.gluOrtho2D(0, w, h, 0)
def set_state(self): # preserve gl scissors info self._scissor_enabled = gl.glIsEnabled(gl.GL_SCISSOR_TEST) self._old_scissor_flat = (gl.GLint * 4)() # 4-tuple gl.glGetIntegerv(gl.GL_SCISSOR_BOX, self._old_scissor_flat) # set our scissor if not self._scissor_enabled: gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(*self._scissor_flat)
def viewport(self, value: Tuple[int, int, int, int]): if not isinstance(value, tuple) or len(value) != 4: raise ValueError("viewport should be a 4-component tuple") self._viewport = value # If the framebuffer is bound we need to set the viewport. # Otherwise it will be set on use() if self._ctx.active_framebuffer == self: gl.glViewport(*self._viewport) gl.glScissor(*self._viewport)
def __enter__(self): from utils import Rect from pyglet.gl import GLint, glGetIntegerv, GL_SCISSOR_BOX, glScissor ob = (GLint * 4)() glGetIntegerv(GL_SCISSOR_BOX, ob) ob = list(ob) box = [int(i) for i in self.box] nb = Rect(*ob).intersect(Rect(*box)) if nb: glScissor(nb.x, nb.y, nb.width, nb.height) self.ob, self.nb = ob, nb return self
def __enter__(self): from utils import Rect from pyglet.gl import GLint, glGetIntegerv, GL_SCISSOR_BOX, glScissor ob = (GLint*4)() glGetIntegerv(GL_SCISSOR_BOX, ob) ob = list(ob) box = [int(i) for i in self.box] nb = Rect(*ob).intersect(Rect(*box)) if nb: glScissor(nb.x, nb.y, nb.width, nb.height) self.ob, self.nb = ob, nb return self
def set_state(self): ''' Enables a scissor test on our region ''' gl.glPushAttrib(gl.GL_ENABLE_BIT | gl.GL_TRANSFORM_BIT | gl.GL_CURRENT_BIT) self.was_scissor_enabled = gl.glIsEnabled(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(int(self.x), int(self.y), int(self.width), int(self.height)) if self._scale != 1.0: gl.glPushMatrix(gl.GL_MODELVIEW_MATRIX) gl.glScalef(self._scale,self._scale,1.0)
def _use(self, *, force: bool = False): """Internal use that do not change the global active framebuffer""" if self.ctx.active_framebuffer == self and not force: return gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self._glo) # NOTE: gl.glDrawBuffer(GL_NONE) if no texture attachments (future) # NOTE: Default framebuffer currently has this set to None if self._draw_buffers: gl.glDrawBuffers(len(self._draw_buffers), self._draw_buffers) gl.glDepthMask(self._depth_mask) gl.glViewport(*self._viewport) gl.glScissor(*self._viewport)
def bind_texture_region(texture, x, y, w, h, premultiplied=False, flip=False): gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_BLEND) if premultiplied: gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA) else: gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glViewport(x, y, w, h) gl.glScissor(x, y, w, h) gl.glBindFramebufferEXT( gl.GL_DRAW_FRAMEBUFFER_EXT, Manager.col_buffer.gl_buffer ) gl.glFramebufferTexture2DEXT( gl.GL_DRAW_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, texture.target, texture.id, 0 ) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() if flip: gl.gluOrtho2D(0, w, h, 0) else: gl.gluOrtho2D(0, w, 0, h)
def _set_view(self): left = int(self._pixel_per_point[0] * self.rect.left) bottom = int(self._pixel_per_point[1] * self.rect.bottom) width = int(self._pixel_per_point[0] * self.rect.width) height = int(self._pixel_per_point[1] * self.rect.height) gl.glPushAttrib(gl.GL_ENABLE_BIT) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(left, bottom, width, height) self._mode = (gl.GLint)() gl.glGetIntegerv(gl.GL_MATRIX_MODE, self._mode) self._viewport = (gl.GLint * 4)() gl.glGetIntegerv(gl.GL_VIEWPORT, self._viewport) gl.glViewport(left, bottom, width, height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() near = 0.01 far = 1000. gl.gluPerspective(self.scene.camera.fov[1], width / height, near, far) gl.glMatrixMode(gl.GL_MODELVIEW)
def draw(self): if self.updateDraw: self.updateDraw = False current = self.height - self.borderPad for item in self.lines: line = item.get_label() line.y = current current -= line.height self.update_scrollbar() glDisable(GL_TEXTURE_2D) glPushMatrix() glTranslatef(self.x, self.y - self.height, 0) # border if self.border: if self.border3d: draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR_3D_1) draw_rectangle(1, 1, self.width - 1, self.height - 1, BORDER_COLOR_3D_2) draw_rectangle(2, 2, self.width - 2, self.height - 2, BORDER_COLOR_3D_3) else: draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR) # background pad = self.borderPad glColor4ub(*(self.backColor + (255,))) glBegin(GL_QUADS) glVertex2f(pad, pad) glVertex2f(self.width - pad, pad) glVertex2f(self.width - pad, self.height - pad) glVertex2f(pad, self.height - pad) glEnd() glPushAttrib(GL_SCISSOR_BIT) x, y, width, height = self.player.get_scissor_box( self.x + self.borderPad, self.y - self.height + self.borderPad, self.listWidth, self.height - self.borderPad * 2) glScissor(x, y, width, height) glEnable(GL_SCISSOR_TEST) glTranslatef(0, self.yOffset, 0) for index, item in enumerate(self.lines): line = item.get_label() color = None if self.selected == index: color = (139, 190, 228) elif self.over == index: color = (191, 219, 240) if color is not None: draw_rectangle(pad, line.y - line.height, self.listWidth + self.borderPad, line.y, color) line.draw() glPopAttrib() glPopMatrix() if self.scrollBar is not None: self.scrollBar.draw()
def draw(self): gl.glDisable(gl.GL_TEXTURE_2D) border = True offset = False image = True color1 = self.border1 color2 = self.border2 if self.displayType == BUTTON: if not self.showBorder and not self.over: border = False if self.is_pressed(): offset = True color1, color2 = color2, color1 elif self.displayType == CHECKBOX: if not self.showBorder and not self.over: border = False value = self.checked or self.is_pressed() if self.imageCheckbox: if value: border = True else: image = False else: if value: offset = True color1, color2 = color2, color1 elif self.displayType == HYPERLINK: if self.is_pressed(): offset = True if not self.enabled: border = False offset = False draw_rectangle(self.x, self.y, self.x + self.width, self.y - self.height, self.fill) gl.glPushAttrib(gl.GL_SCISSOR_BIT) gl.glPushMatrix() x, y, width, height = self.player.get_scissor_box( self.x, self.y - self.height, self.width, self.height) gl.glScissor(x, y, width, height) gl.glEnable(gl.GL_SCISSOR_TEST) if offset: gl.glTranslatef(2, -2, 0) sprite = self.imageSprite if self.imageVisible and image and sprite is not None: if self.pattern: startX = self.x startY = self.y width = sprite.width height = sprite.height for y in xrange(int(math.ceil(float(self.height) / height))): sprite.y = startY - y * height for x in xrange(int(math.ceil(float(self.width) / width))): sprite.x = startX + x * width sprite.render() else: self.imageSprite.render() if self.displayType != HYPERLINK and self.textColor is not None: self.label.draw() gl.glPopMatrix() if self.displayType == HYPERLINK: if self.over: color = self.hyperlinkColor else: color = self.textColor if color is not None: self.label.draw() gl.glPopAttrib() gl.glDisable(gl.GL_TEXTURE_2D) if border: # top left draw_rectangle(self.x, self.y, self.x + self.width, self.y - 1, color1) draw_rectangle(self.x, self.y, self.x + 1, self.y - self.height, color1) # bottom right draw_rectangle(self.x + self.width, self.y - self.height, self.x, self.y - self.height + 1, color2) draw_rectangle(self.x + self.width, self.y - self.height, self.x + self.width - 1, self.y, color2)
def set_state(self): glEnable(GL_SCISSOR_TEST) glScissor(self.x, self.y, self.width, self.height)
def unset_state(self): # restore gl scissors info gl.glScissor(*self._old_scissor_flat) if not self._scissor_enabled: gl.glDisable(gl.GL_SCISSOR_TEST)
def render(self, draw_data): # perf: local for faster access io = self.io display_width, display_height = io.display_size fb_width = int(display_width * io.display_fb_scale[0]) fb_height = int(display_height * io.display_fb_scale[1]) if fb_width == 0 or fb_height == 0: return draw_data.scale_clip_rects(*io.display_fb_scale) # backup GL state # todo: provide cleaner version of this backup-restore code last_program = gl.GLint() gl.glGetIntegerv(gl.GL_CURRENT_PROGRAM, byref(last_program)) last_texture = gl.GLint() gl.glGetIntegerv(gl.GL_TEXTURE_BINDING_2D, byref(last_texture)) last_active_texture = gl.GLint() gl.glGetIntegerv(gl.GL_ACTIVE_TEXTURE, byref(last_active_texture)) last_array_buffer = gl.GLint() gl.glGetIntegerv(gl.GL_ARRAY_BUFFER_BINDING, byref(last_array_buffer)) last_element_array_buffer = gl.GLint() gl.glGetIntegerv(gl.GL_ELEMENT_ARRAY_BUFFER_BINDING, byref(last_element_array_buffer)) last_vertex_array = gl.GLint() gl.glGetIntegerv(gl.GL_VERTEX_ARRAY_BINDING, byref(last_vertex_array)) last_blend_src = gl.GLint() gl.glGetIntegerv(gl.GL_BLEND_SRC, byref(last_blend_src)) last_blend_dst = gl.GLint() gl.glGetIntegerv(gl.GL_BLEND_DST, byref(last_blend_dst)) last_blend_equation_rgb = gl.GLint() gl.glGetIntegerv(gl.GL_BLEND_EQUATION_RGB, byref(last_blend_equation_rgb)) last_blend_equation_alpha = gl.GLint() gl.glGetIntegerv(gl.GL_BLEND_EQUATION_ALPHA, byref(last_blend_equation_alpha)) last_viewport = (gl.GLint*4)() gl.glGetIntegerv(gl.GL_VIEWPORT, last_viewport) last_scissor_box = (gl.GLint*4)() gl.glGetIntegerv(gl.GL_SCISSOR_BOX, last_scissor_box) last_enable_blend = gl.GLint() gl.glIsEnabled(gl.GL_BLEND, byref(last_enable_blend)) last_enable_cull_face = gl.GLint() gl.glIsEnabled(gl.GL_CULL_FACE, byref(last_enable_cull_face)) last_enable_depth_test = gl.GLint() gl.glIsEnabled(gl.GL_DEPTH_TEST, byref(last_enable_depth_test)) last_enable_scissor_test = gl.GLint() gl.glIsEnabled(gl.GL_SCISSOR_TEST, byref(last_enable_scissor_test)) gl.glEnable(gl.GL_BLEND) gl.glBlendEquation(gl.GL_FUNC_ADD) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glDisable(gl.GL_CULL_FACE) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glViewport(0, 0, int(fb_width), int(fb_height)) ortho_projection = [ 2.0/display_width, 0.0, 0.0, 0.0, 0.0, 2.0/-display_height, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0 ] gl.glUseProgram(self._shader_handle) gl.glUniform1i(self._attrib_location_tex, 0) gl.glUniformMatrix4fv(self._attrib_proj_mtx, 1, gl.GL_FALSE, (gl.GLfloat * 16)(*ortho_projection)) gl.glBindVertexArray(self._vao_handle) for commands in draw_data.commands_lists: idx_buffer_offset = 0 gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo_handle) # todo: check this (sizes) gl.glBufferData(gl.GL_ARRAY_BUFFER, commands.vtx_buffer_size * imgui.VERTEX_SIZE, c_void_p(commands.vtx_buffer_data), gl.GL_STREAM_DRAW) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self._elements_handle) # todo: check this (sizes) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, commands.idx_buffer_size * imgui.INDEX_SIZE, c_void_p(commands.idx_buffer_data), gl.GL_STREAM_DRAW) # todo: allow to iterate over _CmdList for command in commands.commands: gl.glBindTexture(gl.GL_TEXTURE_2D, command.texture_id) # todo: use named tuple x, y, z, w = command.clip_rect gl.glScissor(int(x), int(fb_height - w), int(z - x), int(w - y)) if imgui.INDEX_SIZE == 2: gltype = gl.GL_UNSIGNED_SHORT else: gltype = gl.GL_UNSIGNED_INT gl.glDrawElements(gl.GL_TRIANGLES, command.elem_count, gltype, c_void_p(idx_buffer_offset)) idx_buffer_offset += command.elem_count * imgui.INDEX_SIZE # restore modified GL state gl.glUseProgram(cast((c_int*1)(last_program), POINTER(c_uint)).contents) gl.glActiveTexture(cast((c_int*1)(last_active_texture), POINTER(c_uint)).contents) gl.glBindTexture(gl.GL_TEXTURE_2D, cast((c_int*1)(last_texture), POINTER(c_uint)).contents) gl.glBindVertexArray(cast((c_int*1)(last_vertex_array), POINTER(c_uint)).contents) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, cast((c_int*1)(last_array_buffer), POINTER(c_uint)).contents) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, cast((c_int*1)(last_element_array_buffer), POINTER(c_uint)).contents) gl.glBlendEquationSeparate(cast((c_int*1)(last_blend_equation_rgb), POINTER(c_uint)).contents, cast((c_int*1)(last_blend_equation_alpha), POINTER(c_uint)).contents) gl.glBlendFunc(cast((c_int*1)(last_blend_src), POINTER(c_uint)).contents, cast((c_int*1)(last_blend_dst), POINTER(c_uint)).contents) if last_enable_blend: gl.glEnable(gl.GL_BLEND) else: gl.glDisable(gl.GL_BLEND) if last_enable_cull_face: gl.glEnable(gl.GL_CULL_FACE) else: gl.glDisable(gl.GL_CULL_FACE) if last_enable_depth_test: gl.glEnable(gl.GL_DEPTH_TEST) else: gl.glDisable(gl.GL_DEPTH_TEST) if last_enable_scissor_test: gl.glEnable(gl.GL_SCISSOR_TEST) else: gl.glDisable(gl.GL_SCISSOR_TEST) gl.glViewport(last_viewport[0], last_viewport[1], last_viewport[2], last_viewport[3]) gl.glScissor(last_scissor_box[0], last_scissor_box[1], last_scissor_box[2], last_scissor_box[3])
def render(self, draw_data): io = self.io display_width, display_height = io.display_size fb_width = int(display_width * io.display_fb_scale[0]) fb_height = int(display_height * io.display_fb_scale[1]) if fb_width == 0 or fb_height == 0: return self._program["ProjMtx"] = ( 2.0 / display_width, 0.0, 0.0, 0.0, 0.0, 2.0 / -display_height, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, ) draw_data.scale_clip_rects(*io.display_fb_scale) self._ctx.enable_only(self._ctx.BLEND) self._ctx.blend_func = self._ctx.BLEND_DEFAULT self._font_texture.use(0) for commands in draw_data.commands_lists: # Write the vertex and index buffer data without copying it vtx_type = ctypes.c_byte * commands.vtx_buffer_size * imgui.VERTEX_SIZE idx_type = ctypes.c_byte * commands.idx_buffer_size * imgui.INDEX_SIZE vtx_arr = (vtx_type).from_address(commands.vtx_buffer_data) idx_arr = (idx_type).from_address(commands.idx_buffer_data) self._vbo.write(vtx_arr) self._ibo.write(idx_arr) idx_pos = 0 for command in commands.commands: # Use low level pyglet call here instead because we only have the texture name gl.glBindTexture(gl.GL_TEXTURE_2D, command.texture_id) # Set scissor box x, y, z, w = command.clip_rect gl.glScissor(int(x), int(fb_height - w), int(z - x), int(w - y)) self._vao.render(self._program, mode=self._ctx.TRIANGLES, vertices=command.elem_count, first=idx_pos) idx_pos += command.elem_count # Just reset scissor back to default/viewport gl.glScissor(*self._ctx.viewport)
def _enable_scissor_test(self): gl.glPushAttrib(gl.GL_ENABLE_BIT | gl.GL_TRANSFORM_BIT | gl.GL_CURRENT_BIT) self._was_scissor_enabled = gl.glIsEnabled(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_SCISSOR_TEST) gl.glScissor(int(self.x), int(self.y), int(self.width), int(self.height))
def __exit__(self, exc_type, exc_value, tb): if exc_value is self.exc: return True else: from pyglet.gl import glScissor glScissor(*self.ob)
def unset_state(self): """Unsets OpenGL state for using scissor test.""" # restore gl scissors info gl.glScissor(*self._old_scissor_flat) if not self._scissor_enabled: gl.glDisable(gl.GL_SCISSOR_TEST)
def draw(self): if self.updateDraw: self.updateDraw = False current = self.height - self.borderPad for item in self.lines: line = item.get_label() line.y = current current -= line.height self.update_scrollbar() glDisable(GL_TEXTURE_2D) glPushMatrix() glTranslatef(self.x, self.y - self.height, 0) # border if self.border: if self.border3d: draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR_3D_1) draw_rectangle(1, 1, self.width - 1, self.height - 1, BORDER_COLOR_3D_2) draw_rectangle(2, 2, self.width - 2, self.height - 2, BORDER_COLOR_3D_3) else: draw_rectangle(0, 0, self.width, self.height, BORDER_COLOR) # background pad = self.borderPad glColor4ub(*(self.backColor + (255, ))) glBegin(GL_QUADS) glVertex2f(pad, pad) glVertex2f(self.width - pad, pad) glVertex2f(self.width - pad, self.height - pad) glVertex2f(pad, self.height - pad) glEnd() glPushAttrib(GL_SCISSOR_BIT) x, y, width, height = self.player.get_scissor_box( self.x + self.borderPad, self.y - self.height + self.borderPad, self.listWidth, self.height - self.borderPad * 2) glScissor(x, y, width, height) glEnable(GL_SCISSOR_TEST) glTranslatef(0, self.yOffset, 0) for index, item in enumerate(self.lines): line = item.get_label() color = None if self.selected == index: color = (139, 190, 228) elif self.over == index: color = (191, 219, 240) if color is not None: draw_rectangle(pad, line.y - line.height, self.listWidth + self.borderPad, line.y, color) line.draw() glPopAttrib() glPopMatrix() if self.scrollBar is not None: self.scrollBar.draw()
def draw(self): gl.glDisable(gl.GL_TEXTURE_2D) border = True offset = False image = True color1 = self.border1 color2 = self.border2 if self.displayType == BUTTON: if not self.showBorder and not self.over: border = False if self.is_pressed(): offset = True color1, color2 = color2, color1 elif self.displayType == CHECKBOX: if not self.showBorder and not self.over: border = False value = self.checked or self.is_pressed() if self.imageCheckbox: if value: border = True else: image = False else: if value: offset = True color1, color2 = color2, color1 elif self.displayType == HYPERLINK: if self.is_pressed(): offset = True if not self.enabled: border = False offset = False draw_rectangle(self.x, self.y, self.x + self.width, self.y - self.height, self.fill) gl.glPushAttrib(gl.GL_SCISSOR_BIT) gl.glPushMatrix() x, y, width, height = self.player.get_scissor_box(self.x, self.y - self.height, self.width, self.height) gl.glScissor(x, y, width, height) gl.glEnable(gl.GL_SCISSOR_TEST) if offset: gl.glTranslatef(2, -2, 0) sprite = self.imageSprite if self.imageVisible and image and sprite is not None: if self.pattern: startX = self.x startY = self.y width = sprite.width height = sprite.height for y in xrange(int(math.ceil(float(self.height) / height))): sprite.y = startY - y * height for x in xrange(int(math.ceil(float(self.width) / width))): sprite.x = startX + x * width sprite.render() else: self.imageSprite.render() if self.displayType != HYPERLINK and self.textColor is not None: self.label.draw() gl.glPopMatrix() if self.displayType == HYPERLINK: if self.over: color = self.hyperlinkColor else: color = self.textColor if color is not None: self.label.draw() gl.glPopAttrib() gl.glDisable(gl.GL_TEXTURE_2D) if border: # top left draw_rectangle(self.x, self.y, self.x + self.width, self.y - 1, color1) draw_rectangle(self.x, self.y, self.x + 1, self.y - self.height, color1) # bottom right draw_rectangle(self.x + self.width, self.y - self.height, self.x, self.y - self.height + 1, color2) draw_rectangle(self.x + self.width, self.y - self.height, self.x + self.width - 1, self.y, color2)