Пример #1
0
def load_text(text, font_size=16, font_name=None, color=None, antialias=True):
    color = color or batma.display.default_color

    font_obj = pygame.font.SysFont(font_name, font_size)
    image = font_obj.render(text, antialias, color.to_pygame())
    height = image.get_height()
    width = image.get_width()

    h = int(2**math.ceil(math.log(height, 2)))
    w = int(2**math.ceil(math.log(width, 2)))

    texture = gl.glGenTextures(1) 
    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
    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)
    
    empty_list = "\x00" * w*h*4
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, w, h, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, empty_list)
    
    texture_data = pygame.image.tostring(image, "RGBA", 1)
    gl.glTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, image.get_width(), image.get_height(), gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, texture_data)

    image = Image(texture, w, h)
    image.width = width
    image.height = height

    return image
Пример #2
0
def load_text(text, font_size=16, font_name=None, color=None, antialias=True):
    color = color or batma.display.default_color

    font_obj = pygame.font.SysFont(font_name, font_size)
    image = font_obj.render(text, antialias, color.to_pygame())
    height = image.get_height()
    width = image.get_width()

    h = int(2**math.ceil(math.log(height, 2)))
    w = int(2**math.ceil(math.log(width, 2)))

    texture = gl.glGenTextures(1)
    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
    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)

    empty_list = "\x00" * w * h * 4
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, w, h, 0, gl.GL_RGBA,
                    gl.GL_UNSIGNED_BYTE, empty_list)

    texture_data = pygame.image.tostring(image, "RGBA", 1)
    gl.glTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, image.get_width(),
                       image.get_height(), gl.GL_RGBA, gl.GL_UNSIGNED_BYTE,
                       texture_data)

    image = Image(texture, w, h)
    image.width = width
    image.height = height

    return image
Пример #3
0
def load_image(filename):
    texture_surface = pygame.image.load(filename)
    texture_data = pygame.image.tostring(texture_surface, 'RGBA', 1)

    width = texture_surface.get_width()
    height = texture_surface.get_height()
    # texture = gl.glGenTextures(1)
    texture = [int(t) for t in gl.glGenTextures(1)] 

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, width, height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, texture_data)

    return Image(texture, width, height)
Пример #4
0
def load_image(filename):
    texture_surface = pygame.image.load(filename)
    texture_data = pygame.image.tostring(texture_surface, 'RGBA', 1)

    width = texture_surface.get_width()
    height = texture_surface.get_height()
    # texture = gl.glGenTextures(1)
    texture = [int(t) for t in gl.glGenTextures(1)]

    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_LINEAR)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                       gl.GL_LINEAR)
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, width, height, 0,
                    gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, texture_data)

    return Image(texture, width, height)