def swapBuffers(self): # first call the swap on the QGLWidget start = long(now() * 1000) self.glw.swapBuffers() #self.glw.makeCurrent() # The following is taken from the PsychToolbox # Draw a single pixel in left-top area of back-buffer. # This will wait/stall the rendering pipeline # until the buffer flip has happened, aka immediately after the VBL has started. # We need the pixel as "synchronization token", so the following glFinish() really # waits for VBL instead of just "falling through" due to the asynchronous nature of # OpenGL: glDrawBuffer(GL_BACK) # We draw our single pixel with an alpha-value of zero - so effectively it doesn't # change the color buffer - just the z-buffer if z-writes are enabled... glColor4f(0.0, 0.0, 0.0, 0.0) glBegin(GL_POINTS) glVertex2i(10, 10) glEnd() # This glFinish() will wait until point drawing is finished, ergo backbuffer was ready # for drawing, ergo buffer swap in sync with start of VBL has happened. glFinish() finish = long(now() * 1000) fdiff = finish - self.last_finish self.last_finish = finish return (start, finish - start, fdiff)
def draw(self): n = float( len(self.children) ) i = 0 for b in self.children: glColor4f(1-i/n,i/n,0,0.5) b.draw() i += 1
def swapBuffers(self): # first call the swap on the QGLWidget start = long(now()*1000) self.glw.swapBuffers() #self.glw.makeCurrent() # The following is taken from the PsychToolbox # Draw a single pixel in left-top area of back-buffer. # This will wait/stall the rendering pipeline # until the buffer flip has happened, aka immediately after the VBL has started. # We need the pixel as "synchronization token", so the following glFinish() really # waits for VBL instead of just "falling through" due to the asynchronous nature of # OpenGL: glDrawBuffer(GL_BACK) # We draw our single pixel with an alpha-value of zero - so effectively it doesn't # change the color buffer - just the z-buffer if z-writes are enabled... glColor4f(0.0,0.0,0.0,0.0) glBegin(GL_POINTS) glVertex2i(10,10) glEnd() # This glFinish() will wait until point drawing is finished, ergo backbuffer was ready # for drawing, ergo buffer swap in sync with start of VBL has happened. glFinish() finish = long(now()*1000) fdiff = finish - self.last_finish self.last_finish = finish return (start,finish-start,fdiff)
def _recursive_draw(grid_node: nav_map.NavMapGridNode): if grid_node.children is not None: for child in grid_node.children: _recursive_draw(child) else: # leaf node - render as a quad map_alpha = 0.5 cen = grid_node.center half_size = grid_node.size * 0.5 # Draw outline glColor4f(*color_light_gray, 1.0) # fully opaque glBegin(GL_LINE_STRIP) glVertex3f(cen.x + half_size, cen.y + half_size, cen.z) glVertex3f(cen.x + half_size, cen.y - half_size, cen.z) glVertex3f(cen.x - half_size, cen.y - half_size, cen.z) glVertex3f(cen.x - half_size, cen.y + half_size, cen.z) glVertex3f(cen.x + half_size, cen.y + half_size, cen.z) glEnd() # Draw filled contents glColor4f(*color_for_content(grid_node.content), map_alpha) glBegin(GL_TRIANGLE_STRIP) glVertex3f(cen.x + half_size, cen.y - half_size, fill_z) glVertex3f(cen.x + half_size, cen.y + half_size, fill_z) glVertex3f(cen.x - half_size, cen.y - half_size, fill_z) glVertex3f(cen.x - half_size, cen.y + half_size, fill_z) glEnd()
def draw(self): n = float(len(self.children)) i = 0 for b in self.children: glColor4f(1 - i / n, i / n, 0, 0.5) b.draw() i += 1
def render(self, offset): if self.alignment == "left": x = .1 elif self.alignment == "right": x = .9 - self.size[0] elif self.alignment == "center": x = .5 - self.size[0] / 2 glColor4f(*self.color) self.font.render(self.text, (x, offset), scale=self.scale)
def draw_arrowhead(x1, y1, x2, y2, noderadius, arrowwidth=20, angle=20, trans=1.0): ''' Draws an arrow head on the line segment between the coordinate pairs (x1,y1) and (x2,y2). The arrow head is placed in the (x2,y2)-end. ''' if x1 - x2 == 0: if y2 <= y1: LineAngle = math.pi / 2 else: LineAngle = 3 * math.pi / 2 else: LineAngle = math.atan((y2 - y1) / (x2 - x1)) EndAngle1 = LineAngle + angle * math.pi / 180 EndAngle2 = LineAngle - angle * math.pi / 180 xOffset = noderadius * math.cos(LineAngle) yOffset = noderadius * math.sin(LineAngle) if x1 < x2: Y3 = y2 - arrowwidth * math.sin(EndAngle1) Y4 = y2 - arrowwidth * math.sin(EndAngle2) X3 = x2 - arrowwidth * math.cos(EndAngle1) X4 = x2 - arrowwidth * math.cos(EndAngle2) x2 -= xOffset y2 -= yOffset Y3 -= yOffset Y4 -= yOffset X3 -= xOffset X4 -= xOffset else: Y3 = y2 + arrowwidth * math.sin(EndAngle1) Y4 = y2 + arrowwidth * math.sin(EndAngle2) X3 = x2 + arrowwidth * math.cos(EndAngle1) X4 = x2 + arrowwidth * math.cos(EndAngle2) x2 += xOffset y2 += yOffset Y3 += yOffset Y4 += yOffset X3 += xOffset X4 += xOffset glLineWidth(1.0) glColor4f(arrow_color()[0], arrow_color()[1], arrow_color()[2], trans) glBegin(GL_TRIANGLES) glVertex2f(x2, y2) glVertex2f(X3, Y3) glVertex2f(X4, Y4) glEnd()
def draw_border(self): bw, bh = self.size #double size since half the line will be off-screen log("draw_border: %s", self.border) glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (bw, 0), (bw, bh), (0, bh)): glVertex2i(px, py) glEnd()
def render(self, offset): offset = (offset*4.0)/3.0 # akedrou - font rendering fix if self.alignment == "left": x = .1 elif self.alignment == "right": x = .9 - self.size[0] elif self.alignment == "center": x = .5 - self.size[0] / 2 glColor4f(*self.color) self.font.render(self.text, (x, offset), scale = self.scale)
def draw_Dierkes_lines(self, result): glPushMatrix() glMatrixMode(GL_MODELVIEW) glColor4f(1.0, 0.0, 0.0, 0.1) glLineWidth(1.0) for line in result["debug_info"]["Dierkes_lines"][::4]: glBegin(GL_LINES) glVertex3f(line[0], line[1], line[2]) glVertex3f(line[3], line[4], line[5]) glEnd() glPopMatrix()
def draw_rect(x, y, width, height): glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 730, 0, 650, 0, 1) glMatrixMode(GL_MODELVIEW) glColor4f(0.71, 0.83, 1, 0.3) glBegin(GL_QUADS) glVertex2f(x, y) glVertex2f(x + width, y) glVertex2f(x + width, y + height) glVertex2f(x, y + height) glEnd()
def draw(self, time, line_width=None): if self.hidden: return time = time * 1e-9 if time <= self.time: return pos_start = self.pos + (self.speed * (-self.time) * self.dir) path = self.speed * (time - self.time) * self.dir if self.length: max_path = self.length * self.dir if np.linalg.norm(max_path) <= np.linalg.norm(path): path = max_path pos_end = self.pos + path glPushMatrix() if line_width: glLineWidth(line_width) else: glLineWidth(self.line_width) glColor3f(*self.color) glBegin(GL_LINES) glVertex3f(*pos_start) glVertex3f(*pos_end) glEnd() glPopMatrix() if self.cherenkov_cone_enabled and self.colourist.cherenkov_cone_enabled: height = np.linalg.norm(pos_end - pos_start) position = pos_end - self.dir * height glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST) glShadeModel(GL_FLAT) glColor4f(0.0, 0.0, 0.8, 0.3) glPushMatrix() glTranslated(*position) glPushMatrix() v = np.array(self.dir) glMultMatrixf(transform(v)) glutSolidCone(0.6691 * height, height, 128, 64) glPopMatrix() glPopMatrix() glDisable(GL_LIGHTING)
def draw(self): # draw gestures set_color(1, 1, 1, .6) for touch in getCurrentTouches(): if not 'desktop.gesture' in touch.userdata: continue drawLine(touch.userdata['desktop.gesture'], width=5.) if len(getCurrentTouches()): self.inactivity = 0 return self.inactivity += getFrameDt() if self.inactivity < self.inactivity_timeout: return alpha = (self.inactivity - self.inactivity_timeout) / 3. alpha = boundary(alpha, 0, 1.) w = self.get_parent_window() s2 = Vector(w.size) / 2. self.dt += getFrameDt() * 2 step = math.pi / 20. radius = 50 i = 0 with DO(gx_attrib(GL_LINE_BIT), gx_blending): glLineWidth(3) with gx_begin(GL_LINE_STRIP): while i < math.pi * 2: x, y = math.cos(self.dt - i) * radius, math.sin(self.dt - i) * radius glColor4f(1, 1, 1, min(alpha, i / math.pi)) glVertex2f(x + s2.x, y + s2.y - 70) i += step set_color(1, 1, 1, alpha) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=4) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=20, linewidth=2) label = 'Draw a circle to make the menu appear' k = {'font_size': 24, 'bold': True} pos = Vector(w.size) / 2. + Vector(0, 10) drawLabel(label=label, pos=pos, color=(.5, .5, .5, min(alpha, .5)), **k) pos += Vector(1, -1) drawLabel(label=label, pos=pos, color=(1, 1, 2, alpha), **k)
def draw_node(x, y, sizes, colors): ''' Draw a node at the given position using max(len(sizes), len(colors)) points having the specified sizes and colors. ''' if not len(sizes) == len(colors): print "Size and colour count for node drawer not equal. Adjusting." align_lists(sizes, colors) for i, size in enumerate(sizes): color = colors[i] glPointSize(size) glColor4f(color[0], color[1], color[2], color[3]) glBegin(GL_POINTS) glVertex2f(x, y) glEnd()
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if self.paint_box_line_width<=0: return glLineWidth(self.paint_box_line_width+0.5+int(encoding=="scroll")*2) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = get_paint_box_color(encoding) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def set_color(*colors, **kwargs): '''Define current color to be used (as float values between 0 and 1) :: set_color(1, 0, 0, 1) drawLabel('Hello', pos=(100, 0)) set_color(0, 1, 0, 1) drawLabel('World', pos=(200, 0)) .. Note: Blending is activated if alpha value != 1 :Parameters: `*colors` : list Can have 3 or 4 float value (between 0 and 1) `sfactor` : opengl factor, default to GL_SRC_ALPHA Default source factor to be used if blending is activated `dfactor` : opengl factor, default to GL_ONE_MINUS_SRC_ALPHA Default destination factor to be used if blending is activated `blend` : boolean, default to None Set True if you really want to activate blending, even if the alpha color is 1 (mean no blending in theory) ''' kwargs.setdefault('sfactor', GL_SRC_ALPHA) kwargs.setdefault('dfactor', GL_ONE_MINUS_SRC_ALPHA) kwargs.setdefault('blend', None) force_blend = kwargs['blend'] == True if len(colors) == 1: if type(colors[0]) in (unicode, str): colors = get_color_from_hex(colors[0]) else: colors = (colors[0], colors[0], colors[0]) if len(colors) == 4: glColor4f(*colors) if colors[3] == 1 and not force_blend: glDisable(GL_BLEND) else: glEnable(GL_BLEND) glBlendFunc(kwargs.get('sfactor'), kwargs.get('dfactor')) if len(colors) == 3: glColor3f(*colors) if force_blend: glEnable(GL_BLEND) glBlendFunc(kwargs.get('sfactor'), kwargs.get('dfactor')) else: glDisable(GL_BLEND)
def draw_line(x1, y1, x2, y2, widths, colors): ''' Draw a line between the two given points using max(len(widths), len(colors)) primitive lines with the specified widths and colors. ''' if not len(widths) == len(colors): print "Width and colour count for node drawer not equal. Adjusting." align_lists(widths, colors) for i, width in enumerate(widths): color = colors[i] glLineWidth(width) glColor4f(color[0], color[1], color[2], color[3]) glBegin(GL_LINES) glVertex2f(x1, y1) glVertex2f(x2, y2) glEnd()
def draw(self): # draw gestures set_color(1, 1, 1, 0.6) for touch in getCurrentTouches(): if not "desktop.gesture" in touch.userdata: continue drawLine(touch.userdata["desktop.gesture"], width=5.0) if len(getCurrentTouches()): self.inactivity = 0 return self.inactivity += getFrameDt() if self.inactivity < self.inactivity_timeout: return alpha = (self.inactivity - self.inactivity_timeout) / 3.0 alpha = boundary(alpha, 0, 1.0) w = self.get_parent_window() s2 = Vector(w.size) / 2.0 self.dt += getFrameDt() * 2 step = math.pi / 20.0 radius = 50 i = 0 with DO(gx_attrib(GL_LINE_BIT), gx_blending): glLineWidth(3) with gx_begin(GL_LINE_STRIP): while i < math.pi * 2: x, y = math.cos(self.dt - i) * radius, math.sin(self.dt - i) * radius glColor4f(1, 1, 1, min(alpha, i / math.pi)) glVertex2f(x + s2.x, y + s2.y - 70) i += step set_color(1, 1, 1, alpha) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=4) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=20, linewidth=2) label = "Draw a circle to make the menu appear" k = {"font_size": 24, "bold": True} pos = Vector(w.size) / 2.0 + Vector(0, 10) drawLabel(label=label, pos=pos, color=(0.5, 0.5, 0.5, min(alpha, 0.5)), **k) pos += Vector(1, -1) drawLabel(label=label, pos=pos, color=(1, 1, 2, alpha), **k)
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if self.paint_box_line_width<=0: return glDisable(GL_TEXTURE_RECTANGLE_ARB) glDisable(GL_FRAGMENT_PROGRAM_ARB) glLineWidth(self.paint_box_line_width+0.5) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if not OPENGL_PAINT_BOX>0: return glDisable(GL_TEXTURE_RECTANGLE_ARB) glDisable(GL_FRAGMENT_PROGRAM_ARB) glLineWidth(OPENGL_PAINT_BOX+0.5) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def _set_material(self, color=None, alpha=None): ''' ''' c = color if c is None: c = self.color if c is None: c = (1, 0, 0) if alpha: if isinstance(c, tuple): c += (alpha,) else: c.append(alpha) if len(c) == 3: glColor3f(*c) else: glColor4f(*c)
def draw_spinner(bw, bh): dim = min(bw / 3.0, bh / 3.0) t = monotonic_time() count = int(t * 4.0) bx = bw // 2 by = bh // 2 for i in range(8): #8 lines c = cv.trs[count % 8][i] mi1 = math.pi * i / 4 - math.pi / 16 mi2 = math.pi * i / 4 + math.pi / 16 si1 = math.sin(mi1) si2 = math.sin(mi2) ci1 = math.cos(mi1) ci2 = math.cos(mi2) glBegin(GL_POLYGON) glColor4f(c, c, c, 1) glVertex2i(int(bx + si1 * 10), int(by + ci1 * 10)) glVertex2i(int(bx + si1 * dim), int(by + ci1 * dim)) glVertex2i(int(bx + si2 * dim), int(by + ci2 * dim)) glVertex2i(int(bx + si2 * 10), int(by + ci2 * 10)) glEnd()
def draw(self): """ Draws each frame. """ print("draw()") # DRAW STUFF HERE glDisable(GL_TEXTURE_RECTANGLE_ARB) glColor4f(1.0, 0.8, 0.2, 1.0) glPushMatrix() glScale(0.5, 0.5, 1.0) draw_square() glPopMatrix() glColor4f(1.0, 1.0, 0.0, 0.8) num = 64 for i in range(num): x = (i / float(num)) * 4 - 2 draw_line(float(x), -2.0, float(x), 2.0) draw_line(-2.0, float(x), 2.0, float(x)) if self.texture_id is not None: glColor4f(1.0, 1.0, 1.0, 1.0) glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.texture_id) glPushMatrix() glScale(0.4, 0.3, 1.0) draw_textured_square(320, 240) glPopMatrix() else: print "No texture to draw"
def paint(self): super(Box, self).paint() l = self.length wh = self.width / 2.0 # h = self.height p = [ [0, wh, 0], [l, wh, 0], [l, -wh, 0], [0, -wh, 0], [0, wh, 1], [l, wh, 1], [l, -wh, 1], [0, -wh, 1], ] m = [ [0, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], ] glLineWidth(2.0) glBegin(GL_LINES) # lgtm [py/call/wrong-arguments] glColor4f(1, 0, 0, 1) for k in range(8): for j in range(k + 1, 8): if m[k][j] == 1: glVertex3f(*p[k]) glVertex3f(*p[j]) glEnd() # lgtm [py/call/wrong-arguments]
def display(): start_point = ( start_picture_coord[0] * HEIGHT * mosaic_factory.ratio / (args.tiles - 1), start_picture_coord[1] * HEIGHT / (args.tiles - 1) ) center = (HEIGHT * mosaic_factory.ratio / 2., HEIGHT / 2.) reverse_sigmoid_progress = fake_sigmoid(1 - progress) sigmoid_progress = 1 - reverse_sigmoid_progress max_zoom = args.tiles zoom = max_zoom ** reverse_sigmoid_progress angle = start_orientation + sigmoid_progress * angle_difference( current_mosaic_picture.orientation, start_orientation ) if reverse_sigmoid_progress > 0.1: alpha = 1.0 else: alpha = reverse_sigmoid_progress * 10.0 glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() glTranslatef(center[0], center[1], 0.0) glRotatef(angle, 0, 0, 1) glTranslatef(-center[0], -center[1], 0.0) glTranslatef(start_point[0], start_point[1], 0.0) glScalef(zoom, zoom, 1.0) glTranslatef(-start_point[0], -start_point[1], 0.0) glColor4f(0.0, 0.0, 0.0, alpha) glCallList(mosaic_display_lists[current_mosaic_picture]) glColor4f(0.0, 0.0, 0.0, 1.0 - alpha) glScalef(max_zoom, max_zoom, 1.0) glCallList(picture_display_lists[current_mosaic_picture]) glPopMatrix() glutSwapBuffers()
def _on_realize(self, *args): """ Called at the creation of the drawing area. Sets up the OpenGL rendering context. """ print("_on_realize(%s)" % str(args)) gldrawable = self.get_gl_drawable() glcontext = self.get_gl_context() if not gldrawable.gl_begin(glcontext): return self._set_view(WIDTH / float(HEIGHT)) glEnable(GL_TEXTURE_RECTANGLE_ARB) # 2D) glEnable(GL_BLEND) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 1.0) # black background glColor4f(1.0, 1.0, 1.0, 1.0) # default color is white glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) gldrawable.gl_end()
def draw_frustum(self, width, height, length): W = width / 2.0 H = height / 2.0 Z = length # draw it glLineWidth(1) glColor4f(1, 0.5, 0, 0.5) glBegin(GL_LINE_LOOP) glVertex3f(0, 0, 0) glVertex3f(-W, H, Z) glVertex3f(W, H, Z) glVertex3f(0, 0, 0) glVertex3f(W, H, Z) glVertex3f(W, -H, Z) glVertex3f(0, 0, 0) glVertex3f(W, -H, Z) glVertex3f(-W, -H, Z) glVertex3f(0, 0, 0) glVertex3f(-W, -H, Z) glVertex3f(-W, H, Z) glEnd()
def paint(self): """ Draw grid object """ self.setupGLState() if self.antialias: glEnable(GL_LINE_SMOOTH) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glBegin(GL_LINES) _x, _y = self.size() _xs, _ys = self.spacing() _x_vals = np.arange(0, _x + _xs * 0.001, _xs) _y_vals = np.arange(0, _y + _ys * 0.001, _ys) glColor4f(*self.color) for x in _x_vals: glVertex3f(x, _y_vals[0], 0) glVertex3f(x, _y_vals[-1], 0) for y in _y_vals: glVertex3f(_x_vals[0], y, 0) glVertex3f(_x_vals[-1], y, 0) glEnd()
def draw(self): if len(getCurrentTouches()): self.inactivity = 0 return self.inactivity += getFrameDt() if self.inactivity < self.inactivity_timeout: return alpha = (self.inactivity - self.inactivity_timeout) / 3.0 alpha = boundary(alpha, 0, 1.0) w = self.get_parent_window() s2 = Vector(w.size) / 2.0 self.dt += getFrameDt() * 2 step = math.pi / 20.0 radius = 50 i = 0 with DO(gx_attrib(GL_LINE_BIT), gx_blending): glLineWidth(3) with gx_begin(GL_LINE_STRIP): while i < math.pi * 2: x, y = math.cos(self.dt - i) * radius, math.sin(self.dt - i) * radius glColor4f(1, 1, 1, min(alpha, i / math.pi)) glVertex2f(x + s2.x, y + s2.y - 70) i += step set_color(1, 1, 1, alpha) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=4) drawCircle(pos=(x + s2.x, y + s2.y - 70), radius=20, linewidth=2) self.label.pos = Vector(w.size) / 2.0 self.label.color = (0.5, 0.5, 0.5, min(alpha, 0.5)) self.label.draw() self.label.y += 1 self.label.x -= 1 self.label.color = (1, 1, 1, alpha) self.label.draw()
def display(): start_point = (start_picture_coord[0] * HEIGHT * mosaic_factory.ratio / (args.tiles - 1), start_picture_coord[1] * HEIGHT / (args.tiles - 1)) center = (HEIGHT * mosaic_factory.ratio / 2., HEIGHT / 2.) reverse_sigmoid_progress = fake_sigmoid(1 - progress) sigmoid_progress = 1 - reverse_sigmoid_progress max_zoom = args.tiles zoom = max_zoom**reverse_sigmoid_progress angle = start_orientation + sigmoid_progress * angle_difference( current_mosaic_picture.orientation, start_orientation) if reverse_sigmoid_progress > 0.1: alpha = 1.0 else: alpha = reverse_sigmoid_progress * 10.0 glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() glTranslatef(center[0], center[1], 0.0) glRotatef(angle, 0, 0, 1) glTranslatef(-center[0], -center[1], 0.0) glTranslatef(start_point[0], start_point[1], 0.0) glScalef(zoom, zoom, 1.0) glTranslatef(-start_point[0], -start_point[1], 0.0) glColor4f(0.0, 0.0, 0.0, alpha) glCallList(mosaic_display_lists[current_mosaic_picture]) glColor4f(0.0, 0.0, 0.0, 1.0 - alpha) glScalef(max_zoom, max_zoom, 1.0) glCallList(picture_display_lists[current_mosaic_picture]) glPopMatrix() glutSwapBuffers()
def paint(self): super(Grid, self).paint() glEnable(GL_LINE_SMOOTH) glEnable(GL_POLYGON_SMOOTH) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glLineWidth(1.3) glBegin(GL_LINES) # lgtm [py/call/wrong-arguments] xvals = np.linspace(-self.x / 2.0, self.x / 2.0, self.x / self.xs + 1) yvals = np.linspace(-self.y / 2.0, self.y / 2.0, self.y / self.ys + 1) glColor4f(*self.edge_color) for x in xvals: glVertex3f(x, yvals[0], 0) glVertex3f(x, yvals[-1], 0) for y in yvals: glVertex3f(xvals[0], y, 0) glVertex3f(xvals[-1], y, 0) glEnd() # lgtm [py/call/wrong-arguments]
def paint(self): self.setupGLState() if self.antialias: glEnable(GL_LINE_SMOOTH) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glBegin(GL_LINES) x, y = self.size() xs, ys = self.spacing() xvals = np.arange(0, x + xs * 0.001, xs) yvals = np.arange(0, y + ys * 0.001, ys) glColor4f(*self.color) for x in xvals: glVertex3f(x, yvals[0], 0) glVertex3f(x, yvals[-1], 0) for y in yvals: glVertex3f(xvals[0], y, 0) glVertex3f(xvals[-1], y, 0) glEnd()
def paintGL(self): ''' Drawing routine ''' glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glLoadIdentity() incr = (math.pi * 2) / 90.0 for p in points: glBegin(GL_TRIANGLE_FAN) glColor4f(p['r'], p['g'], p['b'], 1.0) glVertex3f(p['x'], p['y'], -0.1) glColor4f(p['r'], p['g'], p['b'], 1.0) wide = p['wide'] for i in range(0, 91): ang = i * incr glVertex3f(p['x'] + sin(ang) * wide, p['y'] + cos(ang) * wide, -wide) glEnd() incr = (math.pi * 2) / 32.0 glBegin(GL_TRIANGLE_FAN) glColor4f(p['r'] / 2.0, p['g'] / 2, p['b'] / 2, 1.0) glVertex3f(p['x'], p['y'], -0.1) glColor4f(p['r'] / 2.0, p['g'] / 2, p['b'] / 2, 0.0) for i in range(0, 33): ang = i * incr glVertex3f(p['x'] + sin(ang) * 5, p['y'] + cos(ang) * 5, -0.05) glEnd() glFlush() self.iterate()
def paint(self): super(CoordinateCross, self).paint() glLineWidth(20.0) glBegin(GL_LINES) # X glColor4f(1, 0, 0, 0.3) glVertex3f(0, 0, 0) glVertex3f(1, 0, 0) glColor4f(0, 1, 0, 0.3) glVertex3f(0, 0, 0) glVertex3f(0, 1, 0) glColor4f(0, 0, 1, 0.3) glVertex3f(0, 0, 0) glVertex3f(0, 0, 1) glEnd()
def do_present_fbo(self): self.gl_marker("Presenting FBO on screen") # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() bw, bh = self.size ww, wh = self.render_size if self.glconfig.is_double_buffered() or bw!=ww or bh!=wh: #refresh the whole window: rectangles = ((0, 0, bw, bh), ) else: #paint just the rectangles we have accumulated: rectangles = self.pending_fbo_paint self.pending_fbo_paint = [] log("do_present_fbo: painting %s", rectangles) glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) #viewport for painting to window: glViewport(0, 0, ww, wh) if ww!=bw or wh!=bh: glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) for x,y,w,h in rectangles: #note how we invert coordinates.. tx1, ty1, tx2, ty2 = x, bh-y, x+w, bh-y-h vx1, vy1, vx2, vy2 = x, y, x+w, y+h glTexCoord2i(tx1, ty1) glVertex2i(vx1, vy1) #top-left of window viewport glTexCoord2i(tx1, ty2) glVertex2i(vx1, vy2) #bottom-left of window viewport glTexCoord2i(tx2, ty2) glVertex2i(vx2, vy2) #bottom-right of window viewport glTexCoord2i(tx2, ty1) glVertex2i(vx2, vy1) #top-right of window viewport glEnd() glDisable(GL_TEXTURE_RECTANGLE_ARB) if self.paint_spinner: #add spinner: dim = min(bw/3.0, bh/3.0) t = time.time() count = int(t*4.0) bx = bw//2 by = bh//2 for i in range(8): #8 lines glBegin(GL_POLYGON) c = cv.trs[count%8][i] glColor4f(c, c, c, 1) mi1 = math.pi*i/4-math.pi/16 mi2 = math.pi*i/4+math.pi/16 glVertex2i(int(bx+math.sin(mi1)*10), int(by+math.cos(mi1)*10)) glVertex2i(int(bx+math.sin(mi1)*dim), int(by+math.cos(mi1)*dim)) glVertex2i(int(bx+math.sin(mi2)*dim), int(by+math.cos(mi2)*dim)) glVertex2i(int(bx+math.sin(mi2)*10), int(by+math.cos(mi2)*10)) glEnd() #if desired, paint window border if self.border and self.border.shown: #double size since half the line will be off-screen glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (bw, 0), (bw, bh), (0, bh)): glVertex2i(px, py) glEnd() # Show the backbuffer on screen self.gl_show() self.gl_frame_terminator() #restore pbo viewport glViewport(0, 0, bw, bh) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST) self.unset_rgb_paint_state() log("%s(%s, %s)", glBindFramebuffer, GL_FRAMEBUFFER, self.offscreen_fbo) glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.do_present_fbo() done", self)
def do_present_fbo(self): bw, bh = self.size ww, wh = self.render_size self.gl_marker("Presenting FBO on screen") # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() rect_count = len(self.pending_fbo_paint) if self.glconfig.is_double_buffered() or bw!=ww or bh!=wh: #refresh the whole window: rectangles = ((0, 0, bw, bh), ) else: #paint just the rectangles we have accumulated: rectangles = self.pending_fbo_paint self.pending_fbo_paint = [] log("do_present_fbo: painting %s", rectangles) glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) if SAVE_BUFFERS: glBindFramebuffer(GL_READ_FRAMEBUFFER, self.offscreen_fbo) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0) glReadBuffer(GL_COLOR_ATTACHMENT0) glViewport(0, 0, bw, bh) from OpenGL.GL import glGetTexImage size = bw*bh*4 import numpy data = numpy.empty(size) img_data = glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA, GL_UNSIGNED_BYTE, data) from PIL import Image, ImageOps img = Image.frombuffer("RGBA", (bw, bh), img_data, "raw", "BGRA", bw*4) img = ImageOps.flip(img) kwargs = {} if SAVE_BUFFERS=="jpeg": kwargs = { "quality" : 0, "optimize" : False, } t = time.time() tstr = time.strftime("%H-%M-%S", time.localtime(t)) filename = "./W%i-FBO-%s.%03i.%s" % (self.wid, tstr, (t*1000)%1000, SAVE_BUFFERS) log("do_present_fbo: saving %4ix%-4i pixels, %7i bytes to %s", bw, bh, size, filename) img.save(filename, SAVE_BUFFERS, **kwargs) glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) #viewport for painting to window: glViewport(0, 0, ww, wh) if ww!=bw or wh!=bh: glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) for x,y,w,h in rectangles: #note how we invert coordinates.. tx1, ty1, tx2, ty2 = x, bh-y, x+w, bh-y-h vx1, vy1, vx2, vy2 = x, y, x+w, y+h glTexCoord2i(tx1, ty1) glVertex2i(vx1, vy1) #top-left of window viewport glTexCoord2i(tx1, ty2) glVertex2i(vx1, vy2) #bottom-left of window viewport glTexCoord2i(tx2, ty2) glVertex2i(vx2, vy2) #bottom-right of window viewport glTexCoord2i(tx2, ty1) glVertex2i(vx2, vy1) #top-right of window viewport glEnd() glDisable(GL_TEXTURE_RECTANGLE_ARB) if self.paint_spinner: #add spinner: dim = min(bw/3.0, bh/3.0) t = time.time() count = int(t*4.0) bx = bw//2 by = bh//2 for i in range(8): #8 lines glBegin(GL_POLYGON) c = cv.trs[count%8][i] glColor4f(c, c, c, 1) mi1 = math.pi*i/4-math.pi/16 mi2 = math.pi*i/4+math.pi/16 glVertex2i(int(bx+math.sin(mi1)*10), int(by+math.cos(mi1)*10)) glVertex2i(int(bx+math.sin(mi1)*dim), int(by+math.cos(mi1)*dim)) glVertex2i(int(bx+math.sin(mi2)*dim), int(by+math.cos(mi2)*dim)) glVertex2i(int(bx+math.sin(mi2)*10), int(by+math.cos(mi2)*10)) glEnd() #if desired, paint window border if self.border and self.border.shown: #double size since half the line will be off-screen glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (bw, 0), (bw, bh), (0, bh)): glVertex2i(px, py) glEnd() if self.pointer_overlay: x, y, _, _, size, start_time = self.pointer_overlay elapsed = time.time()-start_time if elapsed<6: alpha = max(0, (5.0-elapsed)/5.0) glLineWidth(1) glBegin(GL_LINES) glColor4f(0, 0, 0, alpha) glVertex2i(x-size, y) glVertex2i(x+size, y) glVertex2i(x, y-size) glVertex2i(x, y+size) glEnd() else: self.pointer_overlay = None # Show the backbuffer on screen self.gl_show(rect_count) self.gl_frame_terminator() #restore pbo viewport glViewport(0, 0, bw, bh) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST) self.unset_rgb_paint_state() log("%s(%s, %s)", glBindFramebuffer, GL_FRAMEBUFFER, self.offscreen_fbo) glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.do_present_fbo() done", self)
def present_fbo(self, drawable): if not self.paint_screen: return self.gl_marker("Presenting FBO on screen for drawable %s" % drawable) assert drawable # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() w, h = self.size glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBegin(GL_QUADS) glTexCoord2i(0, h) glVertex2i(0, 0) glTexCoord2i(0, 0) glVertex2i(0, h) glTexCoord2i(w, 0) glVertex2i(w, h) glTexCoord2i(w, h) glVertex2i(w, 0) glEnd() #if desired, paint window border if self.border and self.border.shown: glDisable(GL_TEXTURE_RECTANGLE_ARB) #double size since half the line will be off-screen glLineWidth(self.border.size * 2) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) glBegin(GL_LINE_LOOP) for x, y in ((0, 0), (w, 0), (w, h), (0, h)): glVertex2i(x, y) glEnd() #reset color to default glColor4f(1.0, 1.0, 1.0, 1.0) # Show the backbuffer on screen if drawable.is_double_buffered(): log("%s.present_fbo() swapping buffers now", self) drawable.swap_buffers() # Clear the new backbuffer to illustrate that its contents are undefined glClear(GL_COLOR_BUFFER_BIT) else: glFlush() self.gl_frame_terminator() self.unset_rgb_paint_state() glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.present_fbo() done", self)
def present_fbo(self, drawable): if not self.paint_screen: return self.gl_marker("Presenting FBO on screen for drawable %s" % drawable) assert drawable # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() w, h = self.size glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBegin(GL_QUADS) glTexCoord2i(0, h) glVertex2i(0, 0) glTexCoord2i(0, 0) glVertex2i(0, h) glTexCoord2i(w, 0) glVertex2i(w, h) glTexCoord2i(w, h) glVertex2i(w, 0) glEnd() #if desired, paint window border if self.border and self.border.shown: glDisable(GL_TEXTURE_RECTANGLE_ARB) #double size since half the line will be off-screen glLineWidth(self.border.size*2) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) glBegin(GL_LINE_LOOP) for x,y in ((0, 0), (w, 0), (w, h), (0, h)): glVertex2i(x, y) glEnd() #reset color to default glColor4f(1.0, 1.0, 1.0, 1.0) # Show the backbuffer on screen if drawable.is_double_buffered(): log("%s.present_fbo() swapping buffers now", self) drawable.swap_buffers() # Clear the new backbuffer to illustrate that its contents are undefined glClear(GL_COLOR_BUFFER_BIT) else: glFlush() self.gl_frame_terminator() self.unset_rgb_paint_state() glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.present_fbo() done", self)
def __enter__(self): glPushAttrib(GL_COLOR_BUFFER_BIT) if len(self.color) == 3: glColor3f(*self.color) else: glColor4f(*self.color)
def setup_style(self): colour = self._style.get('colour',(1,1,1,1)) glColor4f(*colour) if self.tex: enable_usual() self.tex.bind()
def do_present_fbo(self): bw, bh = self.size ww, wh = self.render_size self.gl_marker("Presenting FBO on screen") # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) left, top, right, bottom = self.offsets #viewport for clearing the whole window: glViewport(0, 0, left+ww+right, top+wh+bottom) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # black, no alpha: glClearColor(0.0, 0.0, 0.0, 1.0) if left or top or right or bottom: try: glClear(GL_COLOR_BUFFER_BIT) except: log("ignoring glClear(GL_COLOR_BUFFER_BIT) error, buggy driver?", exc_info=True) #viewport for painting to window: glViewport(left, top, ww, wh) # Draw FBO texture on screen self.set_rgb_paint_state() rect_count = len(self.pending_fbo_paint) if self.glconfig.is_double_buffered() or bw!=ww or bh!=wh: #refresh the whole window: rectangles = ((0, 0, bw, bh), ) else: #paint just the rectangles we have accumulated: rectangles = self.pending_fbo_paint self.pending_fbo_paint = [] log("do_present_fbo: painting %s", rectangles) glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) if SAVE_BUFFERS: glBindFramebuffer(GL_READ_FRAMEBUFFER, self.offscreen_fbo) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0) glReadBuffer(GL_COLOR_ATTACHMENT0) glViewport(0, 0, bw, bh) from OpenGL.GL import glGetTexImage size = bw*bh*4 import numpy data = numpy.empty(size) img_data = glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA, GL_UNSIGNED_BYTE, data) from PIL import Image, ImageOps img = Image.frombuffer("RGBA", (bw, bh), img_data, "raw", "BGRA", bw*4) img = ImageOps.flip(img) kwargs = {} if SAVE_BUFFERS=="jpeg": kwargs = { "quality" : 0, "optimize" : False, } t = time.time() tstr = time.strftime("%H-%M-%S", time.localtime(t)) filename = "./W%i-FBO-%s.%03i.%s" % (self.wid, tstr, (t*1000)%1000, SAVE_BUFFERS) log("do_present_fbo: saving %4ix%-4i pixels, %7i bytes to %s", bw, bh, size, filename) img.save(filename, SAVE_BUFFERS, **kwargs) glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) if ww!=bw or wh!=bh: glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBegin(GL_QUADS) for x,y,w,h in rectangles: #note how we invert coordinates.. tx1, ty1, tx2, ty2 = x, bh-y, x+w, bh-y-h vx1, vy1, vx2, vy2 = x, y, x+w, y+h glTexCoord2i(tx1, ty1) glVertex2i(vx1, vy1) #top-left of window viewport glTexCoord2i(tx1, ty2) glVertex2i(vx1, vy2) #bottom-left of window viewport glTexCoord2i(tx2, ty2) glVertex2i(vx2, vy2) #bottom-right of window viewport glTexCoord2i(tx2, ty1) glVertex2i(vx2, vy1) #top-right of window viewport glEnd() glDisable(GL_TEXTURE_RECTANGLE_ARB) if self.paint_spinner: #add spinner: dim = min(bw/3.0, bh/3.0) t = time.time() count = int(t*4.0) bx = bw//2 by = bh//2 for i in range(8): #8 lines glBegin(GL_POLYGON) c = cv.trs[count%8][i] glColor4f(c, c, c, 1) mi1 = math.pi*i/4-math.pi/16 mi2 = math.pi*i/4+math.pi/16 glVertex2i(int(bx+math.sin(mi1)*10), int(by+math.cos(mi1)*10)) glVertex2i(int(bx+math.sin(mi1)*dim), int(by+math.cos(mi1)*dim)) glVertex2i(int(bx+math.sin(mi2)*dim), int(by+math.cos(mi2)*dim)) glVertex2i(int(bx+math.sin(mi2)*10), int(by+math.cos(mi2)*10)) glEnd() #if desired, paint window border if self.border and self.border.shown: #double size since half the line will be off-screen glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (bw, 0), (bw, bh), (0, bh)): glVertex2i(px, py) glEnd() if self.pointer_overlay: x, y, _, _, size, start_time = self.pointer_overlay elapsed = time.time()-start_time if elapsed<6: alpha = max(0, (5.0-elapsed)/5.0) glLineWidth(1) glBegin(GL_LINES) glColor4f(0, 0, 0, alpha) glVertex2i(x-size, y) glVertex2i(x+size, y) glVertex2i(x, y-size) glVertex2i(x, y+size) glEnd() else: self.pointer_overlay = None # Show the backbuffer on screen self.gl_show(rect_count) self.gl_frame_terminator() #restore pbo viewport glViewport(0, 0, bw, bh) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST) self.unset_rgb_paint_state() log("%s(%s, %s)", glBindFramebuffer, GL_FRAMEBUFFER, self.offscreen_fbo) glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.do_present_fbo() done", self)
def __init__(self, mesh): self.outline_color = (1, 1, 1) vertices = mesh.vertex_list.getVertices() minV = Vector3() maxV = Vector3() vertices.sort(lambda x, y: cmp(y.x, x.x)) minV.x = vertices[0].x maxV.x = vertices[-1].x vertices.sort(lambda x, y: cmp(y.y, x.y)) minV.y = vertices[0].y maxV.y = vertices[-1].y vertices.sort(lambda x, y: cmp(y.z, x.z)) minV.z = vertices[0].z maxV.z = vertices[-1].z self.points = [] for i in range(8): self.points.append(Vector3()) for i in range(2): for j in range(2): self.points[int('%d%d%d' % (0, i, j), 2)].x = minV.x self.points[int('%d%d%d' % (1, i, j), 2)].x = maxV.x self.points[int('%d%d%d' % (i, 0, j), 2)].y = minV.y self.points[int('%d%d%d' % (i, 1, j), 2)].y = maxV.y self.points[int('%d%d%d' % (i, j, 0), 2)].z = minV.z self.points[int('%d%d%d' % (i, j, 1), 2)].z = maxV.z self.center = Vector3() for p in self.points: self.center += p self.center /= float(8) self.dl = glGenLists(1) glNewList(self.dl, GL_COMPILE) glLineWidth(5) c = self.outline_color glColor4f(c[0], c[1], c[2], 0.2) glBegin(GL_LINE_STRIP) for v in self.points: glVertex(v()) glEnd() c = self.points glBegin(GL_LINES) glVertex(c[0]()) glVertex(c[2]()) glVertex(c[6]()) glVertex(c[4]()) glVertex(c[1]()) glVertex(c[3]()) glVertex(c[7]()) glVertex(c[5]()) glVertex(c[0]()) glVertex(c[1]()) glVertex(c[3]()) glVertex(c[2]()) glVertex(c[2]()) glVertex(c[3]()) glVertex(c[7]()) glVertex(c[6]()) glVertex(c[7]()) glVertex(c[6]()) glVertex(c[4]()) glVertex(c[5]()) glVertex(c[0]()) glVertex(c[1]()) glVertex(c[5]()) glVertex(c[4]()) glEnd() glPushMatrix() glTranslatef(self.center.x, self.center.y, self.center.z) q = gluNewQuadric() gluSphere(q, GLdouble(0.25), GLint(10), GLint(10)) glPopMatrix() glEndList()
def present_fbo(self, encoding, is_delta, x, y, w, h): if not self.paint_screen: return self.gl_marker("Presenting FBO on screen") # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() ww, wh = self.size if self.glconfig.is_double_buffered(): #refresh the whole window: x, y = 0, 0 w, h = ww, wh glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glBegin(GL_QUADS) #note how we invert coordinates.. glTexCoord2i(x, wh-y) glVertex2i(x, y) #top-left of window viewport glTexCoord2i(x, wh-y-h) glVertex2i(x, y+h) #bottom-left of window viewport glTexCoord2i(x+w, wh-y-h) glVertex2i(x+w, y+h) #bottom-right of window viewport glTexCoord2i(x+w, wh-y) glVertex2i(x+w, y) #top-right of window viewport glEnd() glDisable(GL_TEXTURE_RECTANGLE_ARB) #show region being painted: if OPENGL_PAINT_BOX: glLineWidth(1) if is_delta: glLineStipple(1, 0xf0f0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE) if self.paint_spinner: #add spinner: dim = min(ww/3.0, wh/3.0) t = time.time() count = int(t*4.0) bx = ww//2 by = wh//2 for i in range(8): #8 lines glBegin(GL_POLYGON) c = cv.trs[count%8][i] glColor4f(c, c, c, 1) mi1 = math.pi*i/4-math.pi/16 mi2 = math.pi*i/4+math.pi/16 glVertex2i(int(bx+math.sin(mi1)*10), int(by+math.cos(mi1)*10)) glVertex2i(int(bx+math.sin(mi1)*dim), int(by+math.cos(mi1)*dim)) glVertex2i(int(bx+math.sin(mi2)*dim), int(by+math.cos(mi2)*dim)) glVertex2i(int(bx+math.sin(mi2)*10), int(by+math.cos(mi2)*10)) glEnd() #if desired, paint window border if self.border and self.border.shown: #double size since half the line will be off-screen glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (ww, 0), (ww, wh), (0, wh)): glVertex2i(px, py) glEnd() # Show the backbuffer on screen self.gl_show() self.gl_frame_terminator() self.unset_rgb_paint_state() log("%s(%s, %s)", glBindFramebuffer, GL_FRAMEBUFFER, self.offscreen_fbo) glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.present_fbo() done", self)
def cb(): glBegin(GL_POINTS) for idx, val in numpy.ndenumerate(PILToNumpy(NumpyToPIL(img).convert("L"))): glColor4f(float(val) / 255.0, float(val) / 255.0, float(val) / 255.0, 1.0) glVertex3f(idx[1], img.shape[0] - idx[0], float(depth[idx[0],idx[1]])) glEnd()
def __init__(self, mesh): self.outline_color = (1, 1, 1) vertices = mesh.vertex_list.getVertices() minV = Vector3() maxV = Vector3() vertices.sort(lambda x, y: cmp(y.x, x.x)) minV.x = vertices[0].x maxV.x = vertices[-1].x vertices.sort(lambda x, y: cmp(y.y, x.y)) minV.y = vertices[0].y maxV.y = vertices[-1].y vertices.sort(lambda x, y: cmp(y.z, x.z)) minV.z = vertices[0].z maxV.z = vertices[-1].z self.points = [] for i in range(8): self.points.append(Vector3()) for i in range(2): for j in range(2): self.points[int("%d%d%d" % (0, i, j), 2)].x = minV.x self.points[int("%d%d%d" % (1, i, j), 2)].x = maxV.x self.points[int("%d%d%d" % (i, 0, j), 2)].y = minV.y self.points[int("%d%d%d" % (i, 1, j), 2)].y = maxV.y self.points[int("%d%d%d" % (i, j, 0), 2)].z = minV.z self.points[int("%d%d%d" % (i, j, 1), 2)].z = maxV.z self.center = Vector3() for p in self.points: self.center += p self.center /= float(8) self.dl = glGenLists(1) glNewList(self.dl, GL_COMPILE) glLineWidth(5) c = self.outline_color glColor4f(c[0], c[1], c[2], 0.2) glBegin(GL_LINE_STRIP) for v in self.points: glVertex(v()) glEnd() c = self.points glBegin(GL_LINES) glVertex(c[0]()) glVertex(c[2]()) glVertex(c[6]()) glVertex(c[4]()) glVertex(c[1]()) glVertex(c[3]()) glVertex(c[7]()) glVertex(c[5]()) glVertex(c[0]()) glVertex(c[1]()) glVertex(c[3]()) glVertex(c[2]()) glVertex(c[2]()) glVertex(c[3]()) glVertex(c[7]()) glVertex(c[6]()) glVertex(c[7]()) glVertex(c[6]()) glVertex(c[4]()) glVertex(c[5]()) glVertex(c[0]()) glVertex(c[1]()) glVertex(c[5]()) glVertex(c[4]()) glEnd() glPushMatrix() glTranslatef(self.center.x, self.center.y, self.center.z) q = gluNewQuadric() gluSphere(q, GLdouble(0.25), GLint(10), GLint(10)) glPopMatrix() glEndList()