def draw_me(self):

        # figure color
        glColor3ub(DisplayMaster.figure_color[0],
                   DisplayMaster.figure_color[1],
                   DisplayMaster.figure_color[2])

        # drawing figure
        glBegin(GL_QUADS)
        for coords in self.list_of_vertex:
            glVertex2f(
                DisplayMaster.x_center_coordinate +
                coords[0] * DisplayMaster.scaling_coef,
                DisplayMaster.y_center_coordinate +
                coords[1] * DisplayMaster.scaling_coef)
        glEnd()

        # border color
        glColor3ub(0, 0, 0)

        # drawing border
        glBegin(GL_LINE_LOOP)
        for coords in self.list_of_vertex:
            glVertex2f(
                DisplayMaster.x_center_coordinate +
                coords[0] * DisplayMaster.scaling_coef,
                DisplayMaster.y_center_coordinate +
                coords[1] * DisplayMaster.scaling_coef)
        glEnd()
Exemple #2
0
def draw_line(line_width, color, x1, y1, x2, y2):
    glLineWidth(line_width)
    set_color(color)
    
    with mode(GL_LINES):
        glVertex2f(x1, y1)
        glVertex2f(x2, y2)
 def Render(self, point, arrow_head_length=0.3):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_LINES
     from math2d_affine_transform import AffineTransform
     from math2d_line_segment import LineSegment
     transform = AffineTransform()
     transform.linear_transform.x_axis = self.Normalized()
     transform.linear_transform.y_axis = transform.linear_transform.x_axis.Rotated(
         math.pi / 2.0)
     transform.translation = point
     line_segment_list = []
     head = Vector(self.Length(), 0.0)
     line_segment_list.append(LineSegment(Vector(0.0, 0.0), head))
     if arrow_head_length > 0.0:
         line_segment_list.append(
             LineSegment(
                 head, head + Vector(radius=arrow_head_length,
                                     angle=(7.0 / 8.0) * math.pi)))
         line_segment_list.append(
             LineSegment(
                 head, head + Vector(radius=arrow_head_length,
                                     angle=-(7.0 / 8.0) * math.pi)))
     glBegin(GL_LINES)
     try:
         for line_segment in line_segment_list:
             line_segment = transform * line_segment
             glVertex2f(line_segment.point_a.x, line_segment.point_a.y)
             glVertex2f(line_segment.point_b.x, line_segment.point_b.y)
     finally:
         glEnd()
Exemple #4
0
    def draw_geometric2d(shape):
        """
        Draw a 2D shape, of type GeometricPrimitive
        """
        if shape.type == "POINTS":
            glBegin(GL_POINTS)
        elif shape.type == "LINES":
            glBegin(GL_LINES)
        elif shape.type == "LINE_STRIP":
            glBegin(GL_LINE_STRIP)
        elif shape.type == "LINE_LOOP":
            glBegin(GL_LINE_LOOP)
        elif shape.type == "POLYGON":
            glBegin(GL_POLYGON)
        elif shape.type == "TRIANGLES":
            glBegin(GL_TRIANGLES)
        elif shape.type == "TRIANGLE_STRIP":
            glBegin(GL_TRIANGLE_STRIP)
        elif shape.type == "TRIANGLE_FAN":
            glBegin(GL_TRIANGLE_FAN)
        elif shape.type == "QUADS":
            glBegin(GL_QUADS)
        elif shape.type == "QUAD_STRIP":
            glBegin(GL_QUAD_STRIP)
        else:
            logger.error("Invalid type for geometric primitive!")
            raise NameError

        # set color
        glColor3f(shape.color[0], shape.color[1], shape.color[2])

        # create vertices
        for vertex in shape.vertices:
            glVertex2f(vertex[0], vertex[1])
        glEnd()
Exemple #5
0
def draw_rectangle(width, height, color, line_width=2):
    glColor3f(*color)
    glLineWidth(line_width)
    glBegin(GL_LINE_LOOP)
    for coords in [[1, 1], [1, -1], [-1, -1], [-1, 1]]:
        glVertex2f(*shift_scale_point(
            vec.Vec([width / 2, height / 2]) * vec.Vec(coords)))
    glEnd()
def draw_line(from_x, from_y, to_x, to_y):
    """
    Draws a line between given points.
    """
    glBegin(GL_LINES)
    glVertex2f(from_x, from_y)
    glVertex2f(to_x, to_y)
    glEnd()
def draw_line(from_x, from_y, to_x, to_y):
    """
    Draws a line between given points.
    """
    glBegin(GL_LINES)
    glVertex2f(from_x, from_y)
    glVertex2f(to_x, to_y)
    glEnd()
Exemple #8
0
def draw_line(x1, y1, x2, y2):
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, 730, 0, 650, 0, 1)
    glMatrixMode(GL_MODELVIEW)
    glBegin(GL_LINES)
    glVertex2f(x1, y1)
    glVertex2f(x2, y2)
    glEnd()
Exemple #9
0
def draw_points_2d(points, color, line_width=2):
    glColor3f(*color)
    #draw each point as a line with (almost) identical start and end points
    glLineWidth(line_width)
    for point in points:
        glBegin(GL_LINES)
        glVertex2f(*shift_scale_point(point))
        glVertex2f(*(shift_scale_point(point) + vec.Vec([1, 0])))
        glEnd()
Exemple #10
0
 def Render(self):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_LINE_LOOP
     glBegin(GL_LINE_LOOP)
     try:
         for i in range(len(self.vertex_list)):
             point = self.vertex_list[i]
             glVertex2f(point.x, point.y)
     finally:
         glEnd()
Exemple #11
0
def draw_lines_2d(lines, color, line_width=2):

    glColor3f(*color)
    glLineWidth(line_width)
    glBegin(GL_LINES)
    for line in lines:
        for point in line:
            glVertex2f(*shift_scale_point(point))
    glEnd()
 def Render(self):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_LINES
     glBegin(GL_LINES)
     try:
         for edge_segment in self.GenerateEdgeSegments():
             glVertex2f(edge_segment.point_a.x, edge_segment.point_a.y)
             glVertex2f(edge_segment.point_b.x, edge_segment.point_b.y)
     finally:
         glEnd()
Exemple #13
0
 def Render(self):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_POINTS, glPointSize
     glBegin(GL_POINTS)
     #glPointSize(3.0)
     try:
         for i in range(len(self.point_list)):
             point = self.point_list[i]
             glVertex2f(point.x, point.y)
     finally:
         glEnd()
 def Render(self, sides=12):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_TRIANGLE_FAN
     glBegin(GL_TRIANGLE_FAN)
     try:
         glVertex2f(self.center.x, self.center.y)
         for i in range(sides + 1):
             angle = 2.0 * math.pi * (float(i) / float(sides))
             point = self.center + Vector(radius=self.radius, angle=angle)
             glVertex2f(point.x, point.y)
     finally:
         glEnd()
Exemple #15
0
def draw_textured_quad(coords):
    tex_coords = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))
    
    with mode(GL_QUADS):
        for i in range(4):
            tex_x = tex_coords[i][0]
            tex_y = tex_coords[i][1]
            glTexCoord2f(tex_x, tex_y)
            
            x = coords[i][0]
            y = coords[i][1]
            glVertex2f(x, y)
Exemple #16
0
def paintLine(points, numsteps=None, **kwargs):
    '''Paint a line with current brush
    ::

        set_brush("mybrush.png", 10)
        paintLine((0, 0, 20, 50))
        paintLine((1, 2, 1, 5, 4, 6, 8, 7))

    '''
    if not __brush_texture:
        pymt.pymt_logger.warning('Graphx: No brush set to paint line, abort')
        return
    if len(points) % 2 == 1:
        raise Exception('Points list must be a pair length number (not impair)')
    kwargs.setdefault('sfactor', GL_SRC_ALPHA)
    kwargs.setdefault('dfactor', GL_ONE_MINUS_SRC_ALPHA)
    blending = GlBlending(sfactor=kwargs.get('sfactor'),
                          dfactor=kwargs.get('dfactor'))
    with DO(blending, gx_enable(GL_POINT_SPRITE_ARB),
            gx_enable(__brush_texture.target)):

        # prepare env
        set_texture(__brush_texture.id, target=__brush_texture.target)
        glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)
        glPointSize(__brush_size)

        # initialize outputList
        outputList = []

        # extract 4 points each 2 points
        for x1, y1, x2, y2 in zip(points[::2], points[1::2],
                                  points[2::2], points[3::2]):

            # calculate vector and distance
            dx, dy = x2 - x1, y2 - y1
            dist = sqrt(dx * dx + dy * dy)

            # determine step
            steps = numsteps
            if steps is None:
                steps = max(1, int(dist) / 4)

            # construct pointList
            for i in xrange(steps):
                outputList.extend([x1 + dx * (float(i) / steps),
                                   y1 + dy * (float(i) / steps)])

        # draw !
        if len(outputList) < 2:
            return
        with gx_begin(GL_POINTS):
            for x, y in zip(outputList[::2], outputList[1::2]):
                glVertex2f(x, y)
Exemple #17
0
    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, tri_strip_sequence=None):
     if tri_strip_sequence is None:
         for triple in self.triangle_list:
             triangle = self.MakeTriangleFromTriple(triple)
             triangle.Render()
     else:
         from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_TRIANGLE_STRIP
         glBegin(GL_TRIANGLE_STRIP)
         try:
             for i in tri_strip_sequence:
                 point = self.vertex_list[i]
                 glVertex2f(point.x, point.y)
         finally:
             glEnd()
Exemple #19
0
    def render(self, viewBox):
        if not self.intersectsBox(viewBox):
            return
        if self.shouldRefresh:
            self.refresh()
            self.shouldRefresh = False
        
        glColor3f(1, 1, 1)

        img = self.textureData
        pic_ny, pic_nx = img.shape
        tex_nx,tex_ny = getTexSize(pic_nx,pic_ny)
        picTexRatio_x = float(pic_nx) / tex_nx
        picTexRatio_y = float(pic_ny) / tex_ny

        (x,y) = self.pos[:2]

        glBindTexture(GL_TEXTURE_2D, self.texture)
        glBegin(GL_QUADS)
        glTexCoord2f(0, picTexRatio_y)
        glVertex2f(x, y)
        glTexCoord2f(picTexRatio_x, picTexRatio_y)
        glVertex2f(x + self.size[0], y)
        glTexCoord2f(picTexRatio_x, 0)
        glVertex2f(x + self.size[0], y + self.size[1])
        glTexCoord2f(0, 0)
        glVertex2f(x, y + self.size[1])
        glEnd()
Exemple #20
0
def draw_circle_2d(radius,
                   color,
                   n_points=60,
                   line_width=2,
                   draw_origin=vec.zero_vec(2)):
    glColor3f(*color)
    glLineWidth(line_width)
    glBegin(GL_LINE_LOOP)
    for i in range(n_points):
        x = math.cos(math.pi * 2 * i / n_points) * radius
        y = math.sin(math.pi * 2 * i / n_points) * radius
        p = vec.Vec([x, y]) + draw_origin
        glVertex2f(*shift_scale_point(p))
    glEnd()
Exemple #21
0
    def draw_colour_legend(self):
        menubar_height = self.logo.size[1] + 4
        width = glutGet(GLUT_WINDOW_WIDTH)
        height = glutGet(GLUT_WINDOW_HEIGHT)
        # Colour legend
        left_x = width - 20
        right_x = width - 10
        min_y = menubar_height + 5
        max_y = height - 20
        time_step_size = math.ceil(self.max_hit_time / 20 / 50) * 50
        hit_times = list(range(int(self.min_hit_time), int(self.max_hit_time), int(time_step_size)))
        if len(hit_times) > 1:
            segment_height = int((max_y - min_y) / len(hit_times))
            glMatrixMode(GL_MODELVIEW)
            glLoadIdentity()
            glDisable(GL_LIGHTING)
            glBegin(GL_QUADS)
            for hit_time in hit_times:
                segment_nr = hit_times.index(hit_time)
                glColor3f(*self.spectrum(hit_time))
                glVertex2f(left_x, max_y - segment_height * segment_nr)
                glVertex2f(right_x, max_y - segment_height * segment_nr)
                glColor3f(*self.spectrum(hit_time + time_step_size))
                glVertex2f(left_x, max_y - segment_height * (segment_nr + 1))
                glVertex2f(right_x, max_y - segment_height * (segment_nr + 1))
            glEnd()

            # Colour legend labels
            self.colourist.now_text()
            for hit_time in hit_times:
                segment_nr = hit_times.index(hit_time)
                draw_text_2d("{0:>5}ns".format(hit_time), width - 80, (height - max_y) + segment_height * segment_nr)
Exemple #22
0
def get_gl_info_string(glpane):  # grantham 20051129
    """Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent()  #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_info_string += 'GL_EXTENSIONS : "%s"\n' % glGetString(GL_EXTENSIONS)

    from utilities.debug_prefs import debug_pref, Choice_boolean_False
    if debug_pref("get_gl_info_string call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a, b: a and b, residences)
            # bruce 070308 sees this exception from this line:
            # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
    return gl_info_string
Exemple #23
0
def get_gl_info_string(glpane): # grantham 20051129
    """Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_info_string += 'GL_EXTENSIONS : "%s"\n' % glGetString(GL_EXTENSIONS)

    from utilities.debug_prefs import debug_pref, Choice_boolean_False
    if debug_pref("get_gl_info_string call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a,b: a and b, residences)
                # bruce 070308 sees this exception from this line:
                # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
    return gl_info_string
Exemple #24
0
def plot():
    glClear(GL_COLOR_BUFFER_BIT)

    glPointSize(3.0)
    glColor3f(1.0, 0.0, 0.0)

    glBegin(GL_POINTS)

    x_lst, y_lst = circle(0, 0, 1, 100)
    for x, y in zip(x_lst, y_lst):
        glVertex2f(x, y)

    glEnd()

    glFlush()
Exemple #25
0
 def draw(self):
     size = self.mass
     if size < 0.2:
         size = 0.2
     glBegin(GL_TRIANGLE_FAN)
     glColor3f(1.0, 0.0, 0.0)
     """glVertex2f(-self.mass, -self.mass)
     glColor3f(0.0, 1.0, 0.0)
     glVertex2f(0.0, self.mass)
     glColor3f(0.0, 0.0, 1.0)
     glVertex2f(self.mass, -self.mass)"""
     glVertex2f(0.0, 0.0)
     glColor3f(0.0, 1.0, 0.0)
     for angle in xrange(0,370,10):
         glVertex2f(math.sin(angle)*size, math.cos(angle)*size)
     glEnd()
Exemple #26
0
def draw_rect(x, y, width, height):
    glColor3f(0.71, 0.83, 1)
    glBegin(GL_QUADS)
    glVertex2f(x, y)
    glVertex2f(x + width, y)
    glVertex2f(x + width, y + height)
    glVertex2f(x, y + height)
    glEnd()
    glColor3f(1, 1, 1)
Exemple #27
0
    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)
Exemple #28
0
def draw_rect(x, y, width, height):
    glColor3f(0.71, 0.83, 1)
    glBegin(GL_QUADS)
    glVertex2f(x, y)
    glVertex2f(x + width, y)
    glVertex2f(x + width, y + height)
    glVertex2f(x, y + height)
    glEnd()
    glColor3f(1, 1, 1)
Exemple #29
0
 def Render(self, step_length=0.0, step_size=0.5):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_LINE_STRIP
     glBegin(GL_LINE_STRIP)
     value = 0.0
     try:
         while value < 1.0:
             point = self.Interpolate(value)
             glVertex2f(point.x, point.y)
             if step_length > 0.0:
                 step_size = self.FindStepSizeForDistance(
                     value, step_length)
             value += step_size
         value = 1.0
         point = self.Interpolate(value)
         glVertex2f(point.x, point.y)
     finally:
         glEnd()
Exemple #30
0
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()
Exemple #31
0
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_square():
    """
    Draws a square of 2 x 2 size centered at 0, 0

    Make sure to call glDisable(GL_TEXTURE_RECTANGLE_ARB) first.
    """
    glBegin(GL_QUADS)
    glVertex2f(-1.0, -1.0) # Bottom Left of Quad
    glVertex2f(1.0, -1.0) # Bottom Right of Quad
    glVertex2f(1.0, 1.0) # Top Right Of Quad
    glVertex2f(-1.0, 1.0) # Top Left Of Quad
    glEnd()
Exemple #33
0
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_square():
    """
    Draws a square of 2 x 2 size centered at 0, 0
    
    Make sure to call glDisable(GL_TEXTURE_RECTANGLE_ARB) first.
    """
    glBegin(GL_QUADS)
    glVertex2f(-1.0, -1.0)  # Bottom Left of Quad
    glVertex2f(1.0, -1.0)  # Bottom Right of Quad
    glVertex2f(1.0, 1.0)  # Top Right Of Quad
    glVertex2f(-1.0, 1.0)  # Top Left Of Quad
    glEnd()
Exemple #35
0
    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)
Exemple #36
0
    def _rect2D_(self, x, y, w, h):
        '''
        '''
        glDisable(GL_LIGHTING)

        glBegin(GL_LINE_LOOP)
        glVertex2f(x, y)
        glVertex2f(x + w, y)
        glVertex2f(x + w, y + h)
        glVertex2f(x, y + h)
        glEnd()
        glEnable(GL_LIGHTING)
Exemple #37
0
def copy_pixels(tox, toy, w, h, fromx, fromy):
    glEnable(GL_TEXTURE_2D)
    glBegin(GL_QUADS)
    glTexCoord2f(fromx, fromy)
    glVertex2f(tox, toy)
    glTexCoord2f(fromx+w, fromy)
    glVertex2f(tox+w, toy)
    glTexCoord2f(fromx+w, fromy+h)
    glVertex2f(tox+w, toy+h)
    glTexCoord2f(fromx, fromy+h)
    glVertex2f(tox, toy+h)
    glEnd()
    glDisable(GL_TEXTURE_2D)
 def Render(self, arrow_head_length=0.3):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, glColor3f, glPointSize, GL_POINTS
     for edge in self.edge_list:
         if edge[2] == PlanarGraphEdgeLabel.CUT:
             glColor3f(0.0, 1.0, 0.0)
         elif edge[2] == PlanarGraphEdgeLabel.REGION_BORDER:
             glColor3f(0.6, 0.6, 0.6)
         else:
             glColor3f(1.0, 0.0, 0.0)
         vector = self.EdgeVector(edge)
         point = self.vertex_list[edge[0]]
         vector.Render(point, arrow_head_length=arrow_head_length)
     glPointSize(2.0)
     glBegin(GL_POINTS)
     try:
         for point in self.vertex_list:
             glColor3f(0.0, 0.0, 0.0)
             glVertex2f(point.x, point.y)
     finally:
         glEnd()
Exemple #39
0
def copy_pixels(tox, toy, w, h, fromx, fromy):
    glEnable(GL_TEXTURE_2D)
    glBegin(GL_QUADS)
    glTexCoord2f(fromx, fromy)
    glVertex2f(tox, toy)
    glTexCoord2f(fromx + w, fromy)
    glVertex2f(tox + w, toy)
    glTexCoord2f(fromx + w, fromy + h)
    glVertex2f(tox + w, toy + h)
    glTexCoord2f(fromx, fromy + h)
    glVertex2f(tox, toy + h)
    glEnd()
    glDisable(GL_TEXTURE_2D)
Exemple #40
0
    def draw(self):
        if not self.visible:
            return

        for objectID in self.objects:
            x, y, angle = self.objects[objectID]
            with gx_matrix:
                glTranslatef(x, y, 0.0)
                glRotatef(angle, 0.0, 0.0, 1.0)

                set_color(.5)
                drawCSSRectangle(
                    pos=(-0.5 * self.width, -0.5 * self.height),
                    size=(self.width, self.height),
                    style=self.style
                )

                set_color(*self.style['vector-color'])
                with gx_begin(GL_LINES):
                    glVertex2f(0., 0.)
                    glVertex2f(0., -0.5 * self.height)
 def Render(self):
     from OpenGL.GL import glBegin, glEnd, glVertex2f, GL_TRIANGLES
     glBegin(GL_TRIANGLES)
     glVertex2f(self.vertex_a.x, self.vertex_a.y)
     glVertex2f(self.vertex_b.x, self.vertex_b.y)
     glVertex2f(self.vertex_c.x, self.vertex_c.y)
     glEnd()
Exemple #42
0
    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()
Exemple #43
0
def draw_picture(picture, x, y, width, height):
    glBindTexture(GL_TEXTURE_2D, textures[picture])
    glPushMatrix()
    glTranslatef(x, y, 0.0)
    glBegin(GL_QUADS)
    # Bottom Left Of The Texture and Quad:
    glTexCoord2f(0.0, 0.0)
    glVertex2f(0, 0)
    # Bottom Right Of The Texture and Quad:
    glTexCoord2f(1.0, 0.0)
    glVertex2f(width, 0)
    # Top Right Of The Texture and Quad:
    glTexCoord2f(1.0, 1.0)
    glVertex2f(width, height)
    # Top Left Of The Texture and Quad:
    glTexCoord2f(0.0, 1.0)
    glVertex2f(0, height)
    glEnd()
    glPopMatrix()
Exemple #44
0
    def draw_gui(self):
        menubar_height = logo.size[1] + 4
        width = glutGet(GLUT_WINDOW_WIDTH)
        height = glutGet(GLUT_WINDOW_HEIGHT)
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(0.0, width, height, 0.0, -1.0, 10.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glDisable(GL_CULL_FACE)

        glClear(GL_DEPTH_BUFFER_BIT)

        glBegin(GL_QUADS)
        glColor3f(0.14, 0.49, 0.87)
        glVertex2f(0, 0)
        glVertex2f(width - logo.size[0] - 10, 0)
        glVertex2f(width - logo.size[0] - 10, menubar_height)
        glVertex2f(0, menubar_height)
        glEnd()

        glPushMatrix()
        glLoadIdentity()
        glRasterPos(width - logo.size[0] - 4, logo.size[1] + 2)
        glDrawPixels(logo.size[0], logo.size[1], GL_RGB, GL_UNSIGNED_BYTE, logo_bytes)
        glPopMatrix()

        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)

        glColor3f(1.0, 1.0, 1.0)

        draw_text_2d("FPS:  {0:.1f}\nTime: {1:.0f} ns"
                     .format(self.clock.fps, self.clock.time),
                     10, 30)
        if self.show_help:
            self.display_help()

        if self.show_info:
            self.display_info()
Exemple #45
0
 def drawTexture(self):
     """
     Renders the current context as a texture. 
     Precondition: OpenGL mode and OpenGL context active.
     """
     
     tx = self.rect.x()
     ty = self.rect.y()
     w = self.rect.width()
     h = self.rect.height()
     glBindTexture(GL_TEXTURE_2D, self.texture)
     glBegin(GL_QUADS)
     glTexCoord2f(0.0, 1.0)
     glVertex2f(tx, ty)
     glTexCoord2f(1.0, 1.0)
     glVertex2f(tx + w, ty)
     glTexCoord2f(1.0, 0.0)
     glVertex2f(tx + w, ty + h)
     glTexCoord2f(0.0, 0.0)
     glVertex2f(tx, ty + h)
     glEnd()
Exemple #46
0
    def draw(self):
        # Background
        set_color(*self.style.get('bg-color'))
        drawCircle(self.pos, self.radius)

        # A good size for the hand, proportional to the size of the widget
        hd = self.radius / 10
        # Draw center of the hand
        set_color(*self.style.get('vector-color'))
        drawCircle(self.pos, hd)
        # Rotate the triangle so its not skewed
        l = prot((self.pos[0] - hd, self.pos[1]), self.angle-90, self.pos)
        h = prot((self.pos[0] + hd, self.pos[1]), self.angle-90, self.pos)
        # Draw triable of the hand
        with gx_begin(GL_POLYGON):
            glVertex2f(*l)
            glVertex2f(*h)
            glVertex2f(self.vector[0], self.vector[1])
def draw_textured_square(w=None, h=None):
    """
    Draws a texture square of 2 x 2 size centered at 0, 0

    Make sure to call glEnable(GL_TEXTURE_RECTANGLE_ARB) first.

    :param w: width of the image in pixels
    :param h: height of the image in pixels
    """
    if w is None or h is None:
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(-1.0, -1.0) # Bottom Left Of The Texture and Quad
        glTexCoord2f(1.0, 0.0)
        glVertex2f(1.0, -1.0) # Bottom Right Of The Texture and Quad
        glTexCoord2f(1.0, 1.0)
        glVertex2f(1.0, 1.0) # Top Right Of The Texture and Quad
        glTexCoord2f(0.0, 1.0)
        glVertex2f(-1.0, 1.0) # Top Left Of The Texture and Quad
        glEnd()
    else:
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0)
        glVertex2f(-1.0, -1.0) # Bottom Left
        glTexCoord2f(w, 0.0)
        glVertex2f(1.0, -1.0) # Bottom Right
        glTexCoord2f(w, h)
        glVertex2f(1.0, 1.0) # Top Right
        glTexCoord2f(0.0, h)
        glVertex2f(-1.0, 1.0) # Top Left
        glEnd()
Exemple #48
0
def arrow_2d():
   ''' Draw a 2-dimensional arrow in the x-y plane.'''

   length = 0.05 # length of the arrow head
   theta  = math.radians(20.0) # angle of the arrow head
   
   glBegin(GL_LINES)

   # Draw the shaft of the array along the y-axis
   glVertex2f(0.0, 0.0)
   glVertex2f(0.0, 1.0)
   
   # Draw the left side of the arrow head
   glVertex2f(0.0, 1.0)
   glVertex2f(-length*math.cos(theta), 1.0-length*math.sin(theta))

   # Draw the right side of the arrow head
   glVertex2f(0.0, 1.0)
   glVertex2f(length*math.cos(theta), 1.0-length*math.sin(theta))

   glEnd()
def get_gl_info_string(glpane): # grantham 20051129
    """
    Return a string containing some useful information about the OpenGL
    implementation.

    Use the GL context from the given QGLWidget glpane (by calling
    glpane.makeCurrent()).
    """

    glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call

    gl_info_string = ''

    gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR)
    gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION)
    gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER)
    gl_extensions = glGetString(GL_EXTENSIONS)
    gl_extensions = gl_extensions.strip()
    gl_extensions = gl_extensions.replace(" ", "\n* ")
    gl_info_string += 'GL_EXTENSIONS : \n* %s\n' % gl_extensions

    if debug_pref("Graphics Card Info: call glAreTexturesResident?",
                  Choice_boolean_False):
        # Give a practical indication of how much video memory is available.
        # Should also do this with VBOs.

        # I'm pretty sure this code is right, but PyOpenGL seg faults in
        # glAreTexturesResident, so it's disabled until I can figure that
        # out. [grantham] [bruce 070308 added the debug_pref]

        all_tex_in = True
        tex_bytes = '\0' * (512 * 512 * 4)
        tex_names = []
        tex_count = 0
        tex_names = glGenTextures(1024)
        glEnable(GL_TEXTURE_2D)
        while all_tex_in:
            glBindTexture(GL_TEXTURE_2D, tex_names[tex_count])
            gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA,
                              GL_UNSIGNED_BYTE, tex_bytes)
            tex_count += 1

            glTexCoord2f(0.0, 0.0)
            glBegin(GL_QUADS)
            glVertex2f(0.0, 0.0)
            glVertex2f(1.0, 0.0)
            glVertex2f(1.0, 1.0)
            glVertex2f(0.0, 1.0)
            glEnd()
            glFinish()

            residences = glAreTexturesResident(tex_names[:tex_count])
            all_tex_in = reduce(lambda a,b: a and b, residences)
                # bruce 070308 sees this exception from this line:
                # TypeError: reduce() arg 2 must support iteration

        glDisable(GL_TEXTURE_2D)
        glDeleteTextures(tex_names)

        gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \
                          % tex_count
        pass

    if True: ## or could be a debug_pref("Graphics Card Info: get all GL_MAX symbols?")
        #bruce 090314 new feature
        import OpenGL.GL
        symbols = [x for x in dir(OpenGL.GL) if x.startswith('GL_MAX_')]
        symbols.sort()
        gl_info_string += '\n'
        for symbol in symbols:
            try:
                numeric_symbol = getattr(OpenGL.GL, symbol)
                intval = glGetInteger(numeric_symbol)
            except:
                # this happens to most symbols, not sure why
                if debug_flags.atom_debug:
                    print_compact_traceback( "%s = ??: " % symbol )
                        # overkill, only the exception itself matters
                    # typical output (on Bruce's MacBookPro, 090314):
                    ## GL_MAX_4D_TEXTURE_SIZE_SGIS = ??:
                    ## <type 'exceptions.KeyError'>:
                    ## ('Unknown specifier GL_MAX_4D_TEXTURE_SIZE_SGIS (33080)',
                    ##  'Failure in cConverter <OpenGL.converters.SizedOutput object at 0x1457fab0>',
                    ##  [GL_MAX_4D_TEXTURE_SIZE_SGIS], 1, <OpenGL.wrapper.glGetIntegerv object at 0x1458aa30>)
                    ## [graphics_card_info.py:122] [wrapper.py:676] [converters.py:195] [converters.py:234]
                    pass
                pass ## gl_info_string += "%s = ??\n" % symbol
            else:
                gl_info_string += "%s = %r\n" % (symbol, intval)
            continue
        pass

    return gl_info_string
Exemple #50
0
 def draw_filled_path(self):
     for style, points in self.filled_path:
         with gx_begin(style):
             for x, y in zip(points[::2], points[1::2]):
                 glVertex2f(x, y)
Exemple #51
0
def draw_line(x1, y1, x2, y2):
    glBegin(GL_LINES)
    glVertex2f(x1, y1)
    glVertex2f(x2, y2)
    glEnd()
Exemple #52
0
def arrow_2d():
   l = 0.05
   theta = math.radians(20.0)
   
   glBegin(GL_LINES)
   glVertex2f(0.0, 0.0)
   glVertex2f(0.0, 1.0)
   
   glVertex2f(0.0, 1.0)
   glVertex2f(-l*math.cos(theta), 1.0-l*math.sin(theta))

   glVertex2f(0.0, 1.0)
   glVertex2f(l*math.cos(theta), 1.0-l*math.sin(theta))
   glEnd()