# Path: batma/gl.py

# 
# Path: batma/maths/mathematic.py
# def inversesqrt(value):
# def mod(a, b):
# def sign(value):
# def step(value, threshold):
# def clamp(value, min_value, max_value):
# def wrap_angle(angle):
# def distance(value1, value2):


import pygame
import batma
from batma import gl
from batma.maths import mathematic as math
'''Resource handlers'''



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)


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)))

# Path: batma/gl.py

# 
# Path: batma/maths/mathematic.py
# def inversesqrt(value):
# def mod(a, b):
# def sign(value):
# def step(value, threshold):
# def clamp(value, min_value, max_value):
# def wrap_angle(angle):
# def distance(value1, value2):


# Path: batma/resource.py
import pygame
import batma
from batma import gl
from batma.maths import mathematic as math

'''Resource handlers'''



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)


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)))