Exemplo n.º 1
0
def draw_obj(body, tex):
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP)
    gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id)
    transformed = [world_to_screen(body.GetWorldPoint(p)) for p in POINTS]
    gl.glBegin(gl.GL_QUADS)
    for p, tc in zip(transformed, TEX_COORDS):
        gl.glTexCoord2f(*tc)
        gl.glVertex2f(*p)
    gl.glEnd()
Exemplo n.º 2
0
    def blit_buffer(self, framebuffer, parent_width, parent_height, **kwargs):
        """Draw the texture into the parent scene

        .. warning:

            This method's arguments are not part of the API yet and may change
            at any time.
        """
        gl.glViewport(0, 0, parent_width, parent_height)

        gl.glTexParameteri(gl.GL_TEXTURE_2D,
            gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        gl.glBindTexture(gl.GL_TEXTURE_2D, framebuffer.texture_id)
        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glColor4fv((gl.GLfloat * 4)(*self.color + (self.opacity, )))
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)  # premultipl.
        gl.glBegin(gl.GL_TRIANGLE_STRIP)
        gl.glTexCoord2f(0, 0)
        gl.glVertex2i(0, 0)
        gl.glTexCoord2f(0, parent_height)
        gl.glVertex2i(0, parent_height)
        gl.glTexCoord2f(parent_width, 0)
        gl.glVertex2i(parent_width, 0)
        gl.glTexCoord2f(parent_width, parent_height)
        gl.glVertex2i(parent_width, parent_height)
        gl.glEnd()
        gl.glTexParameteri(gl.GL_TEXTURE_2D,
            gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glTexParameteri(gl.GL_TEXTURE_2D,
            gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glViewport(0, 0, parent_width, parent_height)
Exemplo n.º 3
0
	def compileDisplayList(self, triangulate=True):
		quad = gl.glGenLists(1)
		gl.glNewList(quad, gl.GL_COMPILE)
		if triangulate:
			gl.glBegin(gl.GL_TRIANGLES)
			triangles = self.triangulate()
			for triangle in triangles:
				for node in triangle:
					gl.glTexCoord2f(node[0], node[1])
					gl.glVertex2f(node[0], node[1])
			gl.glEnd()
		else:
			gl.glBegin(gl.GL_LINE_STRIP)
			for node in self:
				gl.glVertex2f(node[0], node[1])
			gl.glEnd()
		gl.glEndList()
		return quad
Exemplo n.º 4
0
 def blit(self, x, y, w, h, z=0, s=(0,1), **kwargs):
     ''' Draw texture to active framebuffer. '''
     gl.glEnable (gl.GL_TEXTURE_2D)
     gl.glDisable (gl.GL_TEXTURE_1D)
     gl.glBindTexture(self.target, self._id)
     gl.glBegin(gl.GL_QUADS)
     gl.glTexCoord2f(s[0], 1), gl.glVertex2f(x,   y)
     gl.glTexCoord2f(s[0], 0), gl.glVertex2f(x,   y+h)
     gl.glTexCoord2f(s[1], 0), gl.glVertex2f(x+w, y+h)
     gl.glTexCoord2f(s[1], 1), gl.glVertex2f(x+w, y)
     gl.glEnd()
Exemplo n.º 5
0
def draw_rect(texture, points, direction=0, use_cam=True):
    # Set the texture
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
    # Allow alpha blending
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    # draw
    gl.glBegin(gl.GL_QUADS)
    for i, vert in enumerate(points):
        b = (i + direction) % 4 # render according to the direction
        if use_cam:
            x, y = adjust_for_cam(vert)
        else:
            x, y = vert
        texture = b // 2, ((b + 1) // 2) % 2
        gl.glTexCoord2f(*texture)
        gl.glVertex3f(x, y, 0)
    gl.glEnd()
Exemplo n.º 6
0
    def draw(self):
        # TODO: Let's use particles. And lighting! Way more fun.

        p = adjust_for_cam(self._body.position)

        if off_screen(self._body.position):
            return

        gl.glEnable(gl.GL_TEXTURE_2D) # enables texturing, without it everything is white
        gl.glBindTexture(gl.GL_TEXTURE_2D, EXPLOSION_ANIM.id)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA);

        # TODO: more optimized to draw as one large batch
        gl.glBegin(gl.GL_QUADS)

        r = (self.radius + BLOCK_SIZE) * SPACE.scale
        for i, vert in enumerate([Vec2d(p.x - r, p.y - r),
                                  Vec2d(p.x + r, p.y - r),
                                  Vec2d(p.x + r, p.y + r),
                                  Vec2d(p.x - r, p.y + r),]):

            # TODO: This is really ugly, and a lot of shared code with the
            #       blocks. Let's write a draw_rect function to handle this
            #       with an optional animation option.

            x = (i // 2)
            if x == 0:
                x = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][0]
            else:
                x = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][0] + 1 / ANIM_COLUMNS
            y = ((i + 1) // 2) % 2
            if y == 0:
                y = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][1]
            else:
                y = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][1] + 1 / ANIM_ROWS

            gl.glTexCoord2f(x, y)
            gl.glVertex3f(vert.x, vert.y, 0)

        gl.glEnd()
Exemplo n.º 7
0
    def render_textured(self):
        gl.glEnable(GL_TEXTURE_2D)
        gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
        gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
        gl.glBindTexture(GL_TEXTURE_2D, self.texture.id)
        gl.glBegin(gl.GL_QUADS)
        gl.glColor4f(1, 1, 1, 1)
        gl.glTexCoord2f(-TEXTURE_SCALE, TEXTURE_SCALE)
        gl.glVertex3f(-PLAYFIELD, +PLAYFIELD, 0)
        gl.glTexCoord2f(TEXTURE_SCALE, TEXTURE_SCALE)
        gl.glVertex3f(+PLAYFIELD, +PLAYFIELD, 0)
        gl.glTexCoord2f(TEXTURE_SCALE, -TEXTURE_SCALE)
        gl.glVertex3f(+PLAYFIELD, -PLAYFIELD, 0)
        gl.glTexCoord2f(-TEXTURE_SCALE, -TEXTURE_SCALE)
        gl.glVertex3f(-PLAYFIELD, -PLAYFIELD, 0)

        gl.glEnd()
        gl.glDisable(GL_TEXTURE_2D)

        gl.glEnable(GL_TEXTURE_2D)
        gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
        gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
        gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        gl.glBindTexture(GL_TEXTURE_2D, self.road_texture.id)

        gl.glBegin(gl.GL_QUADS)
        k = PLAYFIELD / 20.0
        tile_count = len(self.road_poly)
        tile_corners = ((-1, -1), (1, -1), (1, 1), (-1, 1))

        for i in range(len(self.road_poly)):
            poly, color = self.road_poly[i]
            gl.glColor4f(color[0], color[1], color[2], 1)
            for j in range(len(poly)):
                p = poly[j]
                gl.glTexCoord2f(*tile_corners[j % 4])
                gl.glVertex3f(p[0], p[1], 0)
        gl.glEnd()
        gl.glDisable(GL_TEXTURE_2D)
Exemplo n.º 8
0
    def multi_draw(*args, **kwargs):
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glClearColor(0, 0, 0, 0)
        gl.glColor4f(1, 1, 1, 1)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        if not buffers:
            buffers.append(image.get_buffer_manager())
        x, y, w, h = buffers[0].get_viewport()

        #Draw lowres version
        gl.glViewport(0, 0, 256, 256)
        func(*args, **kwargs)
        texes.append(buffers[0].get_color_buffer().texture)
        if len(texes) > num_texes:
            texes.pop(0)

        #Lay down copies of lowres version
        gl.glViewport(x, y, w, h)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        if texes:
            alphas = range(1, len(texes) + 1)
            alphas = [float(f) / sum(alphas) for f in alphas]
            for tex, alpha in zip(texes, alphas):
                gl.glBindTexture(tex.target, tex.id)

                gl.glEnable(gl.GL_TEXTURE_2D)
                gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                                   gl.GL_LINEAR)

                gl.glColor4f(1, 1, 1, alpha)
                gl.glBegin(gl.GL_QUADS)
                gl.glTexCoord2f(0, 0)
                gl.glVertex3f(0, 0, -.5)
                gl.glTexCoord2f(1, 0)
                gl.glVertex3f(w, 0, -.5)
                gl.glTexCoord2f(1, 1)
                gl.glVertex3f(w, h, -.5)
                gl.glTexCoord2f(0, 1)
                gl.glVertex3f(0, h, -.5)
                gl.glEnd()
                gl.glDisable(gl.GL_TEXTURE_2D)

        #Draw real thing
        gl.glColor4f(1, 1, 1, 1)
        func(*args, **kwargs)
Exemplo n.º 9
0
    def multi_draw(*args, **kwargs):
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glClearColor(0, 0, 0, 0)
        gl.glColor4f(1, 1, 1, 1)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        if not buffers:
            buffers.append(image.get_buffer_manager())
        x, y, w, h = buffers[0].get_viewport()

        #Draw lowres version
        gl.glViewport(0, 0, 256, 256)
        func(*args, **kwargs)
        ctex[0] = buffers[0].get_color_buffer().texture

        #Lay down copies of lowres version
        gl.glViewport(x, y, w, h)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glBindTexture(ctex[0].target, ctex[0].id)
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_LINEAR)
        if not disp_list:
            disp_list.append(gl.glGenLists(1))
            gl.glNewList(disp_list[0], gl.GL_COMPILE)
            for u in range(-3, 4, 3):
                for v in range(-3, 4, 3):
                    gl.glColor4f(1, 1, 1, (20.0 - u**2 - v**2) / 72)
                    gl.glBegin(gl.GL_QUADS)
                    gl.glTexCoord2f(0, 0)
                    gl.glVertex3f(u, v, -.5)
                    gl.glTexCoord2f(1, 0)
                    gl.glVertex3f(u + w, v, -.5)
                    gl.glTexCoord2f(1, 1)
                    gl.glVertex3f(u + w, v + h, -.5)
                    gl.glTexCoord2f(0, 1)
                    gl.glVertex3f(u, v + h, -.5)
                    gl.glEnd()
            gl.glEndList()
        gl.glCallList(disp_list[0])
        gl.glDisable(gl.GL_TEXTURE_2D)

        #Draw real thing
        gl.glColor4f(1, 1, 1, 1)
        func(*args, **kwargs)
Exemplo n.º 10
0
    def render(self):

        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.rgb_texture)
        gl.glEnable(gl.GL_TEXTURE_2D)

        width, height = self.render_target_size

        gl.glColor4f(1.0,1.0,1.0,1.0)

        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(0.0, 0.0) ; gl.glVertex3f(0, 0, 0)
        gl.glTexCoord2f(1.0, 0.0) ; gl.glVertex3f(width, 0, 0)
        gl.glTexCoord2f(1.0, 1.0) ; gl.glVertex3f(width , height, 0)
        gl.glTexCoord2f(0.0, 1.0) ; gl.glVertex3f(0, height, 0)
        gl.glEnd()

        gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
        gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 11
0
    def on_draw():
        window.clear()

        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glBindTexture(gl.GL_TEXTURE_2D, texture.id)
        gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, pic.width, pic.height,
                        0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, data)

        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(0.0, 1.0)
        gl.glVertex2i(0, 0)
        gl.glTexCoord2f(1.0, 1.0)
        gl.glVertex2i(pic.width, 0)
        gl.glTexCoord2f(1.0, 0.0)
        gl.glVertex2i(pic.width, pic.height)
        gl.glTexCoord2f(0.0, 0.0)
        gl.glVertex2i(0, pic.height)
        gl.glEnd()
Exemplo n.º 12
0
    def blit_image(self, matrix, position, scale, image):
        x, y = image.width * scale, image.height * scale
        # dx = self.x + position[0]
        # dy = self.y + position[1]
        dx, dy = position
        gl.glEnable(image.target)
        gl.glBindTexture(image.target, image.id)
        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        # blit img
        points = [
            (-dx, -dy),
            (x - dx, -dy),
            (x - dx, y - dy),
            (-dx, y - dy)
            ]
        a, b, _, c, d, _, e, f, _, g, h, _ = image.texture.tex_coords
        textures = [a, b, c, d, e, f, g, h]
        np = [matrix * euclid.Point2(*p) for p in points]

        gl.glColor4ub(255, 255, 255, self.alpha)
        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(a, b)
        gl.glVertex2f(*np[0])
        gl.glTexCoord2f(c, d)
        gl.glVertex2f(*np[1])
        gl.glTexCoord2f(e, f)
        gl.glVertex2f(*np[2])
        gl.glTexCoord2f(g, h)
        gl.glVertex2f(*np[3])
        gl.glEnd()
        gl.glColor4ub(255, 255, 255, 255)
        # pyglet.graphics.draw(4, GL_QUADS,
        #     ("v2f", new_points),
        #     ("t2f", textures),
        #     ("c4B", [255, 255, 255, self.alpha] * 4),
        #     )

        gl.glPopAttrib()
        gl.glDisable(image.target)
Exemplo n.º 13
0
    def blit_image(self, matrix, position, scale, image):
        x, y = image.width * scale, image.height * scale
        # dx = self.x + position[0]
        # dy = self.y + position[1]
        dx, dy = position
        gl.glEnable(image.target)
        gl.glBindTexture(image.target, image.id)
        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        # blit img
        points = [
            (-dx, -dy),
            (x - dx, -dy),
            (x - dx, y - dy),
            (-dx, y - dy)
            ]
        a, b, _, c, d, _, e, f, _, g, h, _ = image.texture.tex_coords
        textures = [a, b, c, d, e, f, g, h]
        np = [matrix * euclid.Point2(*p) for p in points]

        gl.glColor4ub(255, 255, 255, self.alpha)
        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(a, b)
        gl.glVertex2f(*np[0])
        gl.glTexCoord2f(c, d)
        gl.glVertex2f(*np[1])
        gl.glTexCoord2f(e, f)
        gl.glVertex2f(*np[2])
        gl.glTexCoord2f(g, h)
        gl.glVertex2f(*np[3])
        gl.glEnd()
        gl.glColor4ub(255, 255, 255, 255)
        # pyglet.graphics.draw(4, GL_QUADS,
        #     ("v2f", new_points),
        #     ("t2f", textures),
        #     ("c4B", [255, 255, 255, self.alpha] * 4),
        #     )

        gl.glPopAttrib()
        gl.glDisable(image.target)
Exemplo n.º 14
0
def on_draw():
    window.clear()
    # Draw texture backed by ImageSurface

    gl.glEnable(gl.GL_TEXTURE_2D)

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture.id)
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, width, height, 0,
                    gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, surface_data)

    gl.glBegin(gl.GL_QUADS)
    gl.glTexCoord2f(0.0, 1.0)
    gl.glVertex2i(0, 0)
    gl.glTexCoord2f(1.0, 1.0)
    gl.glVertex2i(width, 0)
    gl.glTexCoord2f(1.0, 0.0)
    gl.glVertex2i(width, height)
    gl.glTexCoord2f(0.0, 0.0)
    gl.glVertex2i(0, height)
    gl.glEnd()
Exemplo n.º 15
0
def on_draw():
    window.clear()

    gl.glEnable(gl.GL_TEXTURE_2D)

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture.id)
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, WIDTH, HEIGHT, 0,
                    gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, data)

    gl.glBegin(gl.GL_QUADS)
    gl.glTexCoord2f(0.0, 1.0)
    gl.glVertex2i(0, 0)
    gl.glTexCoord2f(1.0, 1.0)
    gl.glVertex2i(WIDTH, 0)
    gl.glTexCoord2f(1.0, 0.0)
    gl.glVertex2i(WIDTH, HEIGHT)
    gl.glTexCoord2f(0.0, 0.0)
    gl.glVertex2i(0, HEIGHT)
    gl.glEnd()

    text.draw()
Exemplo n.º 16
0
    def createDisplayLists(self):
        glyph_count = len(self.charcode2unichr)
        max_tile_width = self.max_tile_width
        max_tile_height = self.max_tile_height
        display_lists_for_chars = {}

        base = glGenLists(glyph_count)
        for i, (charcode, glyph) in enumerate(self.charcode2glyph.items()):
            dl_index = base + i
            uchar = self.charcode2unichr[charcode]

            # update tex coords to reflect earlier resize of atlas height.
            gx1, gy1, gx2, gy2 = glyph['texcoords']
            gx1 = gx1 / float(self.atlas.width)
            gy1 = gy1 / float(self.atlas.height)
            gx2 = gx2 / float(self.atlas.width)
            gy2 = gy2 / float(self.atlas.height)
            glyph['texcoords'] = [gx1, gy1, gx2, gy2]

            glNewList(dl_index, GL_COMPILE)
            if uchar not in [u'\t', u'\n']:
                glBegin(GL_QUADS)
                x1 = glyph['offset'][0]
                x2 = x1 + glyph['size'][0]
                y1 = (self.max_ascender - glyph['offset'][1])
                y2 = y1 + glyph['size'][1]

                glTexCoord2f(gx1, gy2), glVertex2f(x1, -y2)
                glTexCoord2f(gx1, gy1), glVertex2f(x1, -y1)
                glTexCoord2f(gx2, gy1), glVertex2f(x2, -y1)
                glTexCoord2f(gx2, gy2), glVertex2f(x2, -y2)
                glEnd()
                glTranslatef(max_tile_width, 0, 0)
            glEndList()

            display_lists_for_chars[charcode] = dl_index

        self.charcode2displaylist = display_lists_for_chars
Exemplo n.º 17
0
    def createDisplayLists(self):
        glyph_count = len(self.charcode2unichr)
        max_tile_width = self.max_tile_width
        max_tile_height = self.max_tile_height
        display_lists_for_chars = {}

        base = glGenLists(glyph_count)
        for i, (charcode, glyph) in enumerate(self.charcode2glyph.items()):
            dl_index = base + i
            uchar = self.charcode2unichr[charcode]

            # update tex coords to reflect earlier resize of atlas height.
            gx1, gy1, gx2, gy2 = glyph['texcoords']
            gx1 = gx1/float(self.atlas.width)
            gy1 = gy1/float(self.atlas.height)
            gx2 = gx2/float(self.atlas.width)
            gy2 = gy2/float(self.atlas.height)
            glyph['texcoords'] = [gx1, gy1, gx2, gy2]

            glNewList(dl_index, GL_COMPILE)
            if uchar not in [u'\t', u'\n']:
                glBegin(GL_QUADS)
                x1 = glyph['offset'][0]
                x2 = x1 + glyph['size'][0]
                y1 = (self.max_ascender - glyph['offset'][1])
                y2 = y1 + glyph['size'][1]

                glTexCoord2f(gx1, gy2), glVertex2f(x1, -y2)
                glTexCoord2f(gx1, gy1), glVertex2f(x1, -y1)
                glTexCoord2f(gx2, gy1), glVertex2f(x2, -y1)
                glTexCoord2f(gx2, gy2), glVertex2f(x2, -y2)
                glEnd()
                glTranslatef(max_tile_width, 0, 0)
            glEndList()

            display_lists_for_chars[charcode] = dl_index

        self.charcode2displaylist = display_lists_for_chars
Exemplo n.º 18
0
    def on_draw(self):
        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glBindTexture(gl.GL_TEXTURE_2D, self.pypen.texture.id)
        gl.glTexImage2D(gl.GL_TEXTURE_2D,
                        0,
                        gl.GL_RGBA,
                        self.pypen.user_sketch.settings.width,
                        self.pypen.user_sketch.settings.height,
                        0,
                        gl.GL_BGRA,
                        gl.GL_UNSIGNED_BYTE,
                        self.pypen.surface_data)

        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(0.0, 1.0)
        gl.glVertex2i(0, 0)
        gl.glTexCoord2f(1.0, 1.0)
        gl.glVertex2i(self.pypen.user_sketch.settings.width, 0)
        gl.glTexCoord2f(1.0, 0.0)
        gl.glVertex2i(self.pypen.user_sketch.settings.width, self.pypen.user_sketch.settings.height)
        gl.glTexCoord2f(0.0, 0.0)
        gl.glVertex2i(0, self.pypen.user_sketch.settings.height)
        gl.glEnd()
Exemplo n.º 19
0
 def render(self):
     s = self.size
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_LIGHTING)
     gl.glBegin(gl.GL_TRIANGLES)
     gl.glNormal3f(1.0, 0.0, 0.0)
     gl.glTexCoord2f(0.0, 0.0)
     gl.glVertex3f(0.0, -s, -s)
     gl.glTexCoord2f(1.0, 0.0)
     gl.glVertex3f(0.0, s, -s)
     gl.glTexCoord2f(1.0, 1.0)
     gl.glVertex3f(0.0, s, s)
     gl.glTexCoord2f(0.0, 0.0)
     gl.glVertex3f(0.0, -s, -s)
     gl.glTexCoord2f(1.0, 1.0)
     gl.glVertex3f(0.0, s, s)
     gl.glTexCoord2f(0.0, 1.0)
     gl.glVertex3f(0.0, -s, s)
     gl.glEnd()
     gl.glEnable(gl.GL_LIGHTING)
     gl.glEnable(gl.GL_DEPTH_TEST)
Exemplo n.º 20
0
def draw_texture_rectangle(center_x: float,
                           center_y: float,
                           width: float,
                           height: float,
                           texture: Texture,
                           angle: float = 0,
                           alpha: float = 1,
                           transparent: bool = True,
                           repeat_count_x=1,
                           repeat_count_y=1):
    """
    Draw a textured rectangle on-screen.

    Args:
        :center_x: x coordinate of rectangle center.
        :center_y: y coordinate of rectangle center.
        :width: width of the rectangle.
        :height: height of the rectangle.
        :texture: identifier of texture returned from load_texture() call
        :angle: rotation of the rectangle. Defaults to zero.
        :alpha: Transparency of image.
    Returns:
        None
    Raises:
        None

    :Example:

    >>> import arcade
    >>> arcade.open_window(800,600,"Drawing Example")
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12)
    >>> name = "arcade/examples/images/playerShip1_orange.png"
    >>> texture = arcade.load_texture(name)
    >>> scale = .6
    >>> arcade.draw_texture_rectangle(540, 120, scale * texture.width, \
scale * texture.height, texture, 0)
    >>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, \
scale * texture.height, texture, 90)
    >>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, \
scale * texture.height, texture, 90, 1, False)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    if transparent:
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    else:
        gl.glDisable(gl.GL_BLEND)

    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)

    gl.glLoadIdentity()

    gl.glColor4f(1, 1, 1, alpha)
    z = 0.5  # pylint: disable=invalid-name

    x1 = -width / 2 + center_x
    x2 = width / 2 + center_x
    y1 = -height / 2 + center_y
    y2 = height / 2 + center_y

    p1 = x1, y1
    p2 = x2, y1
    p3 = x2, y2
    p4 = x1, y2

    if angle:
        p1 = rotate_point(p1[0], p1[1], center_x, center_y, angle)
        p2 = rotate_point(p2[0], p2[1], center_x, center_y, angle)
        p3 = rotate_point(p3[0], p3[1], center_x, center_y, angle)
        p4 = rotate_point(p4[0], p4[1], center_x, center_y, angle)

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture.texture_id)
    gl.glBegin(gl.GL_POLYGON)
    gl.glNormal3f(0.0, 0.0, 1.0)
    gl.glTexCoord2f(0, 0)
    gl.glVertex3f(p1[0], p1[1], z)
    gl.glTexCoord2f(repeat_count_x, 0)
    gl.glVertex3f(p2[0], p2[1], z)
    gl.glTexCoord2f(repeat_count_x, repeat_count_y)
    gl.glVertex3f(p3[0], p3[1], z)
    gl.glTexCoord2f(0, repeat_count_y)
    gl.glVertex3f(p4[0], p4[1], z)
    gl.glEnd()
    gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 21
0
def on_draw():
    window.clear()

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_LINE_SMOOTH)

    width, height = window.get_size()
    gl.glViewport(0, 0, width, height)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluPerspective(60, width / float(height), 0.01, 20)

    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    # texcoords are [0..1] and relative to top-left pixel corner, add 0.5 to center
    gl.glTranslatef(0.5 / image_data.width, 0.5 / image_data.height, 0)
    # texture size may be increased by pyglet to a power of 2
    tw, th = image_data.texture.owner.width, image_data.texture.owner.height
    gl.glScalef(image_data.width / float(tw), image_data.height / float(th), 1)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.gluLookAt(0, 0, 0, 0, 0, 1, 0, -1, 0)

    gl.glTranslatef(0, 0, state.distance)
    gl.glRotated(state.pitch, 1, 0, 0)
    gl.glRotated(state.yaw, 0, 1, 0)

    if any(state.mouse_btns):
        axes(0.1, 4)

    gl.glTranslatef(0, 0, -state.distance)
    gl.glTranslatef(*state.translation)

    gl.glColor3f(0.5, 0.5, 0.5)
    gl.glPushMatrix()
    gl.glTranslatef(0, 0.5, 0.5)
    grid()
    gl.glPopMatrix()

    psz = max(window.get_size()) / float(max(w, h)) if state.scale else 1
    gl.glPointSize(psz)
    distance = (0, 0, 1) if state.attenuation else (1, 0, 0)
    gl.glPointParameterfv(gl.GL_POINT_DISTANCE_ATTENUATION,
                          (gl.GLfloat * 3)(*distance))

    if state.lighting:
        ldir = [0.5, 0.5, 0.5]  # world-space lighting
        ldir = np.dot(state.rotation, (0, 0, 1))  # MeshLab style lighting
        ldir = list(ldir) + [0]  # w=0, directional light
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (gl.GLfloat * 4)(*ldir))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, (gl.GLfloat * 3)(1.0, 1.0,
                                                                   1.0))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, (gl.GLfloat * 3)(0.75, 0.75,
                                                                   0.75))
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_NORMALIZE)
        gl.glEnable(gl.GL_LIGHTING)

    #gl.glColor3f(1, 1, 1)

    # 球を表示
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glBindTexture(gl.GL_TEXTURE_2D, textureIDs[0])
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                       gl.GL_LINEAR)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_LINEAR)

    gl.glBegin(gl.GL_TRIANGLE_STRIP)
    for i in range(vertices_count):
        gl.glTexCoord2f(1 - vertices[i][U], vertices[i][V])
        gl.glVertex3f(vertices[i][X], vertices[i][Y], -vertices[i][Z])
    for i in range(vertices_count):
        gl.glTexCoord2f(1 - vertices[i][U], -vertices[i][V])
        gl.glVertex3f(vertices[i][X], vertices[i][Y], vertices[i][Z])
    gl.glEnd()
    gl.glDisable(gl.GL_TEXTURE_2D)

    # 点群表示
    texture = image_data.get_texture()
    gl.glEnable(texture.target)
    gl.glBindTexture(texture.target, texture.id)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_NEAREST)

    # comment this to get round points with MSAA on
    gl.glEnable(gl.GL_POINT_SPRITE)

    if not state.scale and not state.attenuation:
        gl.glDisable(gl.GL_MULTISAMPLE)  # for true 1px points with MSAA on
    vertex_list.draw(gl.GL_POINTS)
    gl.glDisable(texture.target)
    if not state.scale and not state.attenuation:
        gl.glEnable(gl.GL_MULTISAMPLE)

    gl.glDisable(gl.GL_LIGHTING)

    gl.glColor3f(0.25, 0.25, 0.25)
    frustum(depth_intrinsics)
    axes()

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.glOrtho(0, width, 0, height, -1, 1)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glMatrixMode(gl.GL_TEXTURE)
    gl.glLoadIdentity()
    gl.glDisable(gl.GL_DEPTH_TEST)

    fps_display.draw()
Exemplo n.º 22
0
def draw_texture_rectangle(center_x, center_y, width, height, texture,
                           angle=0, alpha=1, transparent=True):
    """
    Draw a textured rectangle on-screen.

    Args:
        :center_x: x coordinate of rectangle center.
        :center_y: y coordinate of rectangle center.
        :width: width of the rectangle.
        :height: height of the rectangle.
        :texture: identifier of texture returned from load_texture() call
        :angle: rotation of the rectangle. Defaults to zero.
        :alpha: Transparency of image.
    Returns:
        None
    Raises:
        None

    :Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12)
    >>> name = "examples/images/playerShip1_orange.png"
    >>> texture = arcade.load_texture(name)
    >>> scale = .6
    >>> arcade.draw_texture_rectangle(540, 120, scale * texture.width, \
scale * texture.height, texture, 0)
    >>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, \
scale * texture.height, texture, 90)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    if transparent:
        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    else:
        GL.glDisable(GL.GL_BLEND)

    GL.glEnable(GL.GL_TEXTURE_2D)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()
    GL.glTranslatef(center_x, center_y, 0)
    if angle != 0:
        GL.glRotatef(angle, 0, 0, 1)

    GL.glColor4f(1, 1, 1, alpha)
    z = 0.5

    GL.glBindTexture(GL.GL_TEXTURE_2D, texture.texture_id)
    GL.glBegin(GL.GL_POLYGON)
    GL.glNormal3f(0.0, 0.0, 1.0)
    GL.glTexCoord2f(0, 0)
    GL.glVertex3f(-width/2, -height/2, z)
    GL.glTexCoord2f(1, 0)
    GL.glVertex3f(width/2, -height/2, z)
    GL.glTexCoord2f(1, 1)
    GL.glVertex3f(width/2, height/2, z)
    GL.glTexCoord2f(0, 1)
    GL.glVertex3f(-width/2, height/2, z)
    GL.glEnd()