def drawCurrentLine(self): if self.currentLine is not None: glBegin(GL_LINES) # glColor(*clampColor(self.currentLineColor)) glColor(*clampColor(self.currentDrawColor)) glVertex(*self.currentLine.start.asGL().data()) glVertex(*self.focusLoc.asGL().data()) glEnd()
def drawBounds(self): # Just for optimization's sake if len(self.bounds): glColor(*clampColor(self.boundsColor)) for i in self.bounds: self.drawCircle(i, self.focusRadius * .75) if len(self.bounds) >= 2: glColor(*clampColor(self.boundsLineColor)) # glBegin(GL_QUADS) glBegin(GL_LINE_LOOP) bounds = getLargestRect(self.bounds) glVertex(*Pointf(bounds.topLeft()).dataf()) glVertex(*Pointf(bounds.topRight()).dataf()) glVertex(*Pointf(bounds.bottomRight()).dataf()) glVertex(*Pointf(bounds.bottomLeft()).dataf()) glEnd()
def drawDots(self): glColor(*clampColor(self.dotColor)) # bind the VBO self.dotVbo.bind() # tell OpenGL that the VBO contains an array of vertices glEnableClientState(GL_VERTEX_ARRAY) # these vertices contain 2 single precision coordinates glVertexPointer(2, GL_FLOAT, 0, self.dotVbo) # draw "count" points from the VBO glDrawArrays(GL_POINTS, 0, len(self.dots))
def drawBackground(self): # self.qp.begin(self) # self.qp.setPen(QColor(255, 0, 0, 255)) # self.qp.drawEllipse(*self.centerPoint.asTL().data(), 6, 6) # debug(self.background) if type(self.background) is tuple: # self.qp.fillRect(0, 0, self.width, self.height, QColor(*self.background)) # return glColor(*clampColor(*self.background)) glBegin(GL_QUADS) glVertex2f(1,1) glVertex2f(1,-1) glVertex2f(-1,-1) glVertex2f(-1,1) glEnd() elif type(self.background) is str: # if not self._image: # self._image = QLabel(self) # self._image.setPixmap(QPixmap(self.background)) # self._image.setPixmap(QPixmap(QColor(255, 255, 255, 0))) # pixmap = QPixmap(self.background) #, 'Format_ARGB32_Premultiplied') image = QImage(self.background).mirrored() #, 'Format_ARGB32_Premultiplied') texture = QOpenGLTexture(image) texture.bind() glDrawArrays(GL_TRIANGLE_FAN, 0, 4) # texture.bind() # for k, v in kwparams.items(): # gl.glTexParameteri(gl.GL_TEXTURE_2D, getattr(gl, k), v) # texture.release() # qp = QPainter(pixmap) # qp.fillRect(pixmap.rect(), QColor(0, 0, 0, 150)) # qp.end() # pixmap.transformed(QTransform()) # self.window()._image.setPixmap(pixmap) # else: # self._image.show() # self.imageimage = QImage(self.background) # QPainter painter(this) # self.qp.drawPixmap(0, 0, pixmap) elif type(self.background) is QGradient: todo('Drawing QGradient') elif type(self.background) is QImage: self.qp.drawImage(0, 0, self.background)
def drawFocus(self): # self.qp.setPen(QColor(*self.focusColor)) # self.qp.drawEllipse(*(self.focusLoc-6).datai(), self.focusRadius, self.focusRadius) glBegin(GL_LINES) glColor(*clampColor(self.focusColor)) glVertex(self.focusLoc.x - self.focusRadius, self.focusLoc.y) glVertex(self.focusLoc.x + self.focusRadius, self.focusLoc.y) # I'm not sure why this direction is shorter than the other. glVertex(self.focusLoc.x, self.focusLoc.y - self.focusRadius * 1.5) glVertex(self.focusLoc.x, self.focusLoc.y + self.focusRadius * 1.5) # for offset in ((-2, -2), (2, 2), (-2, 2), (2, -2)): # self.drawPoint(self.focusLoc + offset) glEnd()
def draw(self, width, height): """ This must be run from within glBegin/glEnd """ # if self.color is None: # assert(not 'No color was specified for a line') if not self.hidden: # display.setPen(self.color) # display.drawLine(self.QLine()) glColor(*clampColor(self.color)) # debug(f'drawing a line between {clampPoint(tlOriginToCenterOrigin(self.start, width, height), width, height)} and {clampPoint(tlOriginToCenterOrigin(self.end, width, height), width, height)}') # glVertex(*clampPoint(tlOriginToCenterOrigin(self.start, width, height), width, height).dataf()) # glVertex(*clampPoint(tlOriginToCenterOrigin(self.end, width, height), width, height).dataf()) glVertex(*self.start.asGL(width, height).data()) glVertex(*self.end.asGL(width, height).data())
def finish(self, loc, width, height, vbo, colorVbo, lines, color=None): if not self.color: self.color = color self.end = loc # vbo.bind() # tell OpenGL that the VBO contains an array of vertices # glEnableClientState(GL_VERTEX_ARRAY) # these vertices contain 2 single precision coordinates # glVertexPointer(2, GL_FLOAT, 0, vbo) # draw "count" points from the VBO # glDrawArrays(GL_POINTS, 0, len(self.dots)) # glBufferSubData(GL_ARRAY_BUFFER, self.index, self.vboSize * 32, self.data(width, height)) # vbo.write(self.index, self.data(width, height), self.vboSize) # // bind then map the VBO # glBindBuffer(GL_ARRAY_BUFFER, vboId) # vbo.bind() # data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY) # assert data # # // if the pointer is valid(mapped), update VBO # data. # updateMyVBO(ptr, ...) # glUnmapBuffer(GL_ARRAY_BUFFER) lineData = () colorData = () for i in lines: lineData += i.data(width, height) colorData += clampColor(i.color) debug(colorData, minItems=10) vbo.bind() # glEnableClientState(GL_VERTEX_ARRAY) #* BufferSubData # glBufferSubData(GL_ARRAY_BUFFER, 12, 8 * 32, newData) #* MapBuffer # data = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE) # debug(pointer(data)) # debug(data) #* BufferData glBufferData( GL_ARRAY_BUFFER, np.asarray(lineData + self.data(width, height), np.float32), GL_DYNAMIC_DRAW) glDisableClientState(GL_VERTEX_ARRAY) vbo.unbind() colorVbo.bind() # glEnableClientState(GL_COLOR_ARRAY) glBufferData(GL_ARRAY_BUFFER, np.asarray(colorData + clampColor(self.color)), GL_DYNAMIC_DRAW)