def drawSelf(self): if self._tex is None: filename = os.path.join("toolicons", "compass.png") self._tex = loadPNGTexture(filename) self._tex.bind() size = 0.001 * config.settings.compassSize.get() with gl.glPushMatrix(GL.GL_MODELVIEW): GL.glLoadIdentity() yaw, pitch = self.yawPitch if config.settings.viewMode.get() == "Chunk": yaw = -180 GL.glTranslatef(1. - (size + self.x), size + self.y, 0.0) # position on upper right corner GL.glRotatef(180 - yaw, 0., 0., 1.) # adjust to north GL.glColor3f(1., 1., 1.) with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY): GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2 * size, 2 * size)) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256)) with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D): GL.glDrawArrays(GL.GL_QUADS, 0, 4)
def gl_draw(self): if self.schematic.chunkCount > len(self.renderer.chunkRenderers): self.gl_draw_thumb() else: if self.fbo is None: w, h = self.fboSize self.fbo = FramebufferTexture(w, h, self.gl_draw_tex) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) GL.glColor(1.0, 1.0, 1.0, 1.0) GL.glVertexPointer(2, GL.GL_FLOAT, 0, array([-1, -1, - 1, 1, 1, 1, 1, -1, ], dtype='float32')) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, array([0, 0, 0, 256, 256, 256, 256, 0], dtype='float32')) e = (GL.GL_TEXTURE_2D,) if not self.drawBackground: e += (GL.GL_ALPHA_TEST,) with gl.glEnable(*e): self.fbo.bind() GL.glDrawArrays(GL.GL_QUADS, 0, 4) GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY)
def drawSelf(self): if self._tex is None: filename = os.path.join("toolicons", "compass.png") self._tex = loadPNGTexture(filename) self._tex.bind() size = 0.001 * config.settings.compassSize.get() with gl.glPushMatrix(GL.GL_MODELVIEW): GL.glLoadIdentity() yaw, pitch = self.yawPitch if config.settings.viewMode.get() == "Chunk": yaw = -180 GL.glTranslatef(1. - size, size, 0.0) # position on upper right corner GL.glRotatef(180 - yaw, 0., 0., 1.) # adjust to north GL.glColor3f(1., 1., 1.) with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY): GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2 * size, 2 * size)) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256)) with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D): GL.glDrawArrays(GL.GL_QUADS, 0, 4)
def gl_draw_thumb(self): GL.glPushAttrib(GL.GL_SCISSOR_BIT) r = self.rect x, y = self.local_to_global_offset() self.set_position_modifiers() if hasattr(self.parent, 'axis'): s_sz = 0 if self.widget_index > 0: s_sz = getattr(self.parent.subwidgets[self.widget_index - 1], self.parent.longways, 0) #-# Do we have a bad hack or the real solution with `(self.parent.height - self.height) / 2 + 1` stuff? #-# Need extensive tests to confirm... if self.parent.axis == 'h': r = r.move( x + (self.parent.height - self.height) / 2 + 1 + self.p_margin - self.p_spacing - s_sz, y - (self.parent.height - self.height) / 2) else: r = r.move( x - (self.parent.width - self.height) / 2, y - (self.parent.width - self.height) / 2 + 1 + self.p_margin - self.p_spacing - s_sz) else: r = r.move(*self.local_to_global_offset()) GL.glScissor(r.x, self.root.height - r.y - r.height, r.width, r.height) with gl.glEnable(GL.GL_SCISSOR_TEST): self.clear() self.renderer.draw() GL.glPopAttrib()
def _drawFloorQuad(self): GL.glDepthMask(True) GL.glPolygonOffset(DepthOffset.ChunkMarkers + 2, DepthOffset.ChunkMarkers + 2) GL.glVertexPointer(3, GL.GL_FLOAT, 0, self.floorQuad) GL.glColor(*self.floorColor) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST, GL.GL_POLYGON_OFFSET_FILL): GL.glDrawArrays(GL.GL_QUADS, 0, 4)
def drawSelf(self): if self._tex is None: if self.small: filename = "compass_small.png" else: filename = "compass.png" self._tex = loadPNGTexture("toolicons/" + filename)#, minFilter=GL.GL_LINEAR, magFilter=GL.GL_LINEAR) self._tex.bind() size = 0.075 with gl.glPushMatrix(GL.GL_MODELVIEW): GL.glLoadIdentity() yaw, pitch = self.yawPitch GL.glTranslatef(1.-size, size, 0.0) # position on upper right corner GL.glRotatef(180-yaw, 0., 0., 1.) # adjust to north GL.glColor3f(1., 1., 1.) with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY): GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2*size, 2*size)) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256)) with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D): GL.glDrawArrays(GL.GL_QUADS, 0, 4)
def gl_draw_thumb(self): GL.glPushAttrib(GL.GL_SCISSOR_BIT) r = self.rect r = r.move(*self.local_to_global_offset()) GL.glScissor(r.x, self.root.height - r.y - r.height, r.width, r.height) with gl.glEnable(GL.GL_SCISSOR_TEST): self.clear() self.renderer.draw() GL.glPopAttrib()
def gl_draw_thumb(self): GL.glPushAttrib(GL.GL_SCISSOR_BIT) r = self.rect r = r.move(*self.local_to_global_offset()) GL.glScissor(r.x, self.get_root().height - r.y - r.height, r.width, r.height) with gl.glEnable(GL.GL_SCISSOR_TEST): self.clear() self.renderer.draw() GL.glPopAttrib()
def drawToolReticle(self): if self.level is None: return GL.glPolygonOffset(DepthOffset.CloneMarkers, DepthOffset.CloneMarkers) color = self.color if self.destPoint is not None: color = (self.color[0], self.color[1], self.color[2], 0.06) box = self.getDestBox() if self.draggingFace is not None: o = list(self.draggingOrigin()) s = list(box.size) for i in range(3): if i == self.draggingFace >> 1: continue o[i] -= 1000 s[i] += 2000 guideBox = BoundingBox(o, s) color = self.draggingColor GL.glColor(1.0, 1.0, 1.0, 0.33) with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D, GL.GL_DEPTH_TEST): self.editor.sixteenBlockTex.bind() drawFace(guideBox, self.draggingFace ^ 1) else: box = self.getReticleBox() if box is None: return self.drawRepeatedCube(box, color) GL.glPolygonOffset(DepthOffset.CloneReticle, DepthOffset.CloneReticle) if self.destPoint: box = self.getDestBox() if self.draggingFace is not None: face = self.draggingFace box = BoundingBox(self.draggingOrigin(), box.size) face, point = self.boxFaceUnderCursor(box) if face is not None: GL.glEnable(GL.GL_BLEND) GL.glDisable(GL.GL_DEPTH_TEST) GL.glColor(*self.color) drawFace(box, face) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST)
def gl_draw_thumb(self): GL.glPushAttrib(GL.GL_SCISSOR_BIT) r = self.rect x, y = self.local_to_global_offset() self.set_position_modifiers() if hasattr(self.parent, 'axis'): s_sz = 0 if self.widget_index > 0: s_sz = getattr(self.parent.subwidgets[self.widget_index - 1], self.parent.longways, 0) #-# Do we have a bad hack or the real solution with `(self.parent.height - self.height) / 2 + 1` stuff? #-# Need extensive tests to confirm... if self.parent.axis == 'h': r = r.move(x + (self.parent.height - self.height) / 2 + 1 + self.p_margin - self.p_spacing - s_sz, y - (self.parent.height - self.height) / 2) else: r = r.move(x - (self.parent.width - self.height) / 2, y - (self.parent.width - self.height) / 2 + 1 + self.p_margin - self.p_spacing - s_sz) else: r = r.move(*self.local_to_global_offset()) GL.glScissor(r.x, self.root.height - r.y - r.height, r.width, r.height) with gl.glEnable(GL.GL_SCISSOR_TEST): self.clear() self.renderer.draw() GL.glPopAttrib()
def _drawToolMarkers(self): lines = ( ((-1, 0), (0, 0, 0, 1), []), ((1, 0), (1, 0, 1, 1), []), ((0, -1), (0, 0, 1, 0), []), ((0, 1), (0, 1, 1, 1), []), ) for ch in self._selectedChunks: cx, cz = ch for (dx, dz), points, positions in lines: n = (cx + dx, cz + dz) if n not in self._selectedChunks: positions.append([ch]) color = self.editor.selectionTool.selectionColor + (0.3, ) GL.glColor(*color) with gl.glEnable(GL.GL_BLEND): import renderer sizedChunks = renderer.chunkMarkers(self._selectedChunks) for size, chunks in sizedChunks.iteritems(): if not len(chunks): continue chunks = numpy.array(chunks, dtype='float32') chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3), dtype='float32') chunkPosition[..., (0, 2)] = numpy.array( ((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32') chunkPosition[..., (0, 2)] *= size chunkPosition[..., (0, 2)] += chunks[:, newaxis, :] chunkPosition *= 16 chunkPosition[..., 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel()) # chunkPosition *= 8 GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4) for d, points, positions in lines: if 0 == len(positions): continue vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32') vertexArray[..., [0, 2]] = positions vertexArray.shape = len(positions), 2, 2, 3 vertexArray[..., 0, 0, 0] += points[0] vertexArray[..., 0, 0, 2] += points[1] vertexArray[..., 0, 1, 0] += points[2] vertexArray[..., 0, 1, 2] += points[3] vertexArray[..., 1, 0, 0] += points[2] vertexArray[..., 1, 0, 2] += points[3] vertexArray[..., 1, 1, 0] += points[0] vertexArray[..., 1, 1, 2] += points[1] vertexArray *= 16 vertexArray[..., 1, :, 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST): GL.glDepthMask(False) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glDepthMask(True)
def _drawToolMarkers(self): lines = ( ((-1, 0), (0, 0, 0, 1), []), ((1, 0), (1, 0, 1, 1), []), ((0, -1), (0, 0, 1, 0), []), ((0, 1), (0, 1, 1, 1), []), ) for ch in self._selectedChunks: cx, cz = ch for (dx, dz), points, positions in lines: n = (cx + dx, cz + dz) if n not in self._selectedChunks: positions.append([ch]) color = self.editor.selectionTool.selectionColor + (0.3, ) GL.glColor(*color) with gl.glEnable(GL.GL_BLEND): import renderer sizedChunks = renderer.chunkMarkers(self._selectedChunks) for size, chunks in sizedChunks.iteritems(): if not len(chunks): continue chunks = numpy.array(chunks, dtype='float32') chunkPosition = numpy.zeros(shape=(chunks.shape[0], 4, 3), dtype='float32') chunkPosition[..., (0, 2)] = numpy.array(((0, 0), (0, 1), (1, 1), (1, 0)), dtype='float32') chunkPosition[..., (0, 2)] *= size chunkPosition[..., (0, 2)] += chunks[:, newaxis, :] chunkPosition *= 16 chunkPosition[..., 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, chunkPosition.ravel()) # chunkPosition *= 8 GL.glDrawArrays(GL.GL_QUADS, 0, len(chunkPosition) * 4) for d, points, positions in lines: if 0 == len(positions): continue vertexArray = numpy.zeros((len(positions), 4, 3), dtype='float32') vertexArray[..., [0, 2]] = positions vertexArray.shape = len(positions), 2, 2, 3 vertexArray[..., 0, 0, 0] += points[0] vertexArray[..., 0, 0, 2] += points[1] vertexArray[..., 0, 1, 0] += points[2] vertexArray[..., 0, 1, 2] += points[3] vertexArray[..., 1, 0, 0] += points[2] vertexArray[..., 1, 0, 2] += points[3] vertexArray[..., 1, 1, 0] += points[0] vertexArray[..., 1, 1, 2] += points[1] vertexArray *= 16 vertexArray[..., 1, :, 1] = self.editor.level.Height GL.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArray) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) with gl.glEnable(GL.GL_BLEND, GL.GL_DEPTH_TEST): GL.glDepthMask(False) GL.glDrawArrays(GL.GL_QUADS, 0, len(positions) * 4) GL.glDepthMask(True)