Пример #1
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()
Пример #2
0
    def draw_ground_plane(self):
        size = 100

        gl.glPushMatrix()
        gl.glColor3f(1, 1, 1)  # no textures drawn without this for some reason
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.tex.id)
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)  # you need two
        gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)  # I don't know why!

        pos = ('v3f', (-size, -self.cy, -size, size, -self.cy, -size, size,
                       -self.cy, size, -size, -self.cy, size))
        tex_coords = ('t2f', (0, 0, 1, 0, 1, 1, 0, 1))
        vlist = pyglet.graphics.vertex_list(4, pos, tex_coords)
        vlist.draw(gl.GL_QUADS)

        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glPopMatrix()
Пример #3
0
    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)))
Пример #4
0
def line(x1, y1, x2, y2, color):
    glColor3f(*color)
    pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2f', (x1, y1, x2, y2)))
Пример #5
0
	def draw(self):
		if self.charged:
			gl.glColor3f(1, 0, 0)
		draw_rect(self.x, self.y, self.width, self.height)
		gl.glColor3f(1, 1, 1)
		self.draw_label()
Пример #6
0
 def draw_quad(self, vs):
     """Draw a quad defined by vs"""
     gl.glColor3f(*self.colour)
     pyglet.graphics.draw(4, gl.GL_QUADS,
         ('v3f', list(walk((v.x, v.y, 0.5) for v in vs))),
     )
Пример #7
0
 def draw_quad(self, vs):
     """Draw a quad defined by vs"""
     gl.glColor3f(*self.colour)
     pyglet.graphics.draw(4, gl.GL_QUADS,
         ('v2f', list(walk(vs))),
     )