private fun load_from_pixels(pixels: Pointer, width, height: Int, format: GLPixelFormat)
do
var max_texture_size = glGetIntegerv(gl_MAX_TEXTURE_SIZE, 0)
if width > max_texture_size then
error = new Error("Texture width larger than gl_MAX_TEXTURE_SIZE ({max_texture_size}) in {self} at {width}")
return
else if height > max_texture_size then
error = new Error("Texture height larger than gl_MAX_TEXTURE_SIZE ({max_texture_size}) in {self} at {height}")
return
end
# Premultiply alpha?
if premultiply_alpha and format == gl_RGBA then
pixels.premultiply_alpha(width, height)
end
glPixelStorei(gl_UNPACK_ALIGNEMENT, 1)
var tex = glGenTextures(1)[0]
gl_texture = tex
glBindTexture(gl_TEXTURE_2D, tex)
glTexImage2D(gl_TEXTURE_2D, 0, format, width, height, 0, format, gl_UNSIGNED_BYTE, pixels)
glHint(gl_GENERATE_MIPMAP_HINT, gl_NICEST)
glGenerateMipmap(gl_TEXTURE_2D)
glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, gl_LINEAR_MIPMAP_LINEAR)
glBindTexture(gl_TEXTURE_2D, 0)
end
lib/gamnit/textures.nit:242,2--270,4