예제 #1
0
    def draw(self):
        if self.dae.scene is None:
            logging.debug('Empty draw, DAE has no scene.')
            return
        gl.glBegin(gl.GL_TRIANGLES)
        normal = [0.0, 0.0, 1.0]
        for geometry in self.dae.scene.objects('geometry'):
            for primitive in geometry.primitives():
                # Use primitive-specific ways to get triangles.
                primitive_type = type(primitive).__name__
                if primitive_type == 'BoundTriangleSet':
                    triangles = primitive
                elif primitive_type == 'BoundPolylist':
                    triangles = primitive.triangleset()
                else:
                    logging.warning(f'Unsupported mesh used: {primitive_type}')
                    break

                # Add triangles to the display list.
                for triangle in triangles:
                    nidx = 0
                    for vidx in triangle.indices:
                        if triangle.normals is None:
                            normal = [0.0, 0.0, 1.0]
                        else:
                            normal = triangle.normals[nidx]
                        nidx += 1
                        self.add_vertex(primitive.vertex[vidx], normal)
        get_gl_error()
        gl.glEnd()
예제 #2
0
def draw_rect(x, y, width, height):
	gl.glBegin(gl.GL_QUADS)
	gl.glVertex2f(x,  y)
	gl.glVertex2f(x + width, y)
	gl.glVertex2f(x + width, y + height)
	gl.glVertex2f(x, y + height)
	gl.glEnd()
예제 #3
0
        def on_draw():
            # clears the background with the background color
            gl.glClearColor(*background)
            gl.glClear(gl.GL_COLOR_BUFFER_BIT)

            # draw in a loop
            boundary = winsize - 100
            gap = (winsize - boundary) / 2
            i_width = boundary / len(rgb1)
            i_height = boundary / 2

            # the first line
            for idx, rgb in enumerate(rgb1):
                gl.glColor3f(*rgb)

                gl.glBegin(
                    gl.GL_QUADS
                )  # start drawing a rectangle in counter-clockwise (CCW) order

                gl.glVertex2f(gap + idx * i_width,
                              gap + i_height)  # bottom left point
                gl.glVertex2f(gap + (idx + 1) * i_width,
                              gap + i_height)  # bottom right point
                gl.glVertex2f(gap + (idx + 1) * i_width,
                              gap + boundary)  # top right point
                gl.glVertex2f(gap + idx * i_width,
                              gap + boundary)  # top left point

                gl.glEnd()

                label = pyglet.text.Label(str(color1[idx]),
                                          font_size=7,
                                          x=gap + idx * i_width,
                                          y=gap + boundary + 20)
                label.draw()

            # # # the second line
            for idx, rgb in enumerate(rgb2):
                gl.glColor3f(*rgb)

                gl.glBegin(
                    gl.GL_QUADS
                )  # start drawing a rectangle in counter-clockwise (CCW) order

                gl.glVertex2f(gap + idx * i_width, gap)  # bottom left point
                gl.glVertex2f(gap + (idx + 1) * i_width,
                              gap)  # bottom right point
                gl.glVertex2f(gap + (idx + 1) * i_width,
                              gap + i_height)  # top right point
                gl.glVertex2f(gap + idx * i_width,
                              gap + i_height)  # top left point
                gl.glEnd()

                label = pyglet.text.Label(str(color2[idx]),
                                          font_size=7,
                                          x=gap + idx * i_width,
                                          y=gap - 20)
                label.draw()
예제 #4
0
def on_draw():
    window.clear()
    # create a line context
    glBegin(GL_LINES)
    # create a line, x,y,z
    global drawing_vec
    if not drawing_vec == None:
        for bstart, bend, estart, eend in drawing_vec:
            glVertex3f(bstart, bend, 0.0)
            glVertex3f(estart, eend, 0.0)
    glEnd()
예제 #5
0
def circle(x, y, radius, color):
    iterations = 20
    s = sin(2*pi / iterations)
    c = cos(2*pi / iterations)

    dx, dy = radius, 0

    glColor4f(*color)
    glBegin(GL_TRIANGLE_FAN)
    glVertex2f(x, y)
    for i in range(iterations+1):
        glVertex2f(x+dx, y+dy)
        dx, dy = (dx*c - dy*s), (dy*c + dx*s)
    glEnd()
예제 #6
0
    def draw(self):
        def add_uv_vertex(u, v):
            self.add_vertex(*self.get_vertex_normal(u, v))

        def add_tl_triangle(u, v):
            add_uv_vertex(u - 1, v - 1)
            add_uv_vertex(u, v)
            add_uv_vertex(u - 1, v)

        def add_br_triangle(u, v):
            add_uv_vertex(u - 1, v - 1)
            add_uv_vertex(u, v - 1)
            add_uv_vertex(u, v)

        gl.glBegin(gl.GL_TRIANGLES)
        for u in range(1, self.num_u):
            for v in range(1, self.num_v):
                add_br_triangle(u, v)
                add_tl_triangle(u, v)
        get_gl_error()
        gl.glEnd()
예제 #7
0
파일: Graphics.py 프로젝트: Minoflaz/Chess
    def drawChessBoardGl(self):
        self.setupGl()

        # clears the background with the background color
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        # square color
        gl.glColor3f(*self.greenF3)

        squareWidth = 0.4
        minF = -1.6
        maxF = 1.6

        for h in np.arange(0.0, 2 * maxF, 2 * squareWidth):
            #Draws the chess board 2 lines by 2 lines
            for i in np.arange(minF, maxF, 2 * squareWidth):
                # draws a square
                gl.glBegin(gl.GL_QUADS)
                gl.glVertex3f(i + squareWidth, minF + squareWidth + h, 0)
                gl.glVertex3f(i, minF + squareWidth + h, 0)
                gl.glVertex3f(i, minF + h, 0)
                gl.glVertex3f(i + squareWidth, minF + h, 0)
                gl.glEnd()

                gl.glBegin(gl.GL_QUADS)
                gl.glVertex3f(i + 2 * squareWidth, minF + 2 * squareWidth + h,
                              0)
                gl.glVertex3f(i + squareWidth, minF + 2 * squareWidth + h, 0)
                gl.glVertex3f(i + squareWidth, minF + squareWidth + h, 0)
                gl.glVertex3f(i + 2 * squareWidth, minF + squareWidth + h, 0)
                gl.glEnd()

        pyglet.graphics.draw(
            8, pyglet.gl.GL_LINES,
            ("v2f", (minF, minF, minF, maxF, maxF, minF, maxF, maxF, minF,
                     minF, maxF, minF, minF, maxF, maxF, maxF)),
            ('c3B', (0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0,
                     255, 0, 0, 255, 0, 0, 255, 0)))