gamnit :: RootTexture :: defaultinit
gamnit :: RootTexture :: deleted=
Has this resource been deleted?gamnit :: RootTexture :: gl_texture=
gamnit :: RootTexture :: loaded=
Has this texture been loaded yet?gamnit :: RootTexture :: premultiply_alpha
Should the pixels RGB values be premultiplied by their alpha value at loading?gamnit :: RootTexture :: premultiply_alpha=
Should the pixels RGB values be premultiplied by their alpha value at loading?gamnit $ RootTexture :: SELF
Type of this instance, automatically specialized in every classgamnit $ RootTexture :: init
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
gamnit :: Texture :: defaultinit
core :: Object :: defaultinit
gamnit :: RootTexture :: defaultinit
gamnit :: RootTexture :: deleted=
Has this resource been deleted?gamnit :: RootTexture :: gl_texture=
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
gamnit :: RootTexture :: loaded=
Has this texture been loaded yet?gamnit :: Texture :: offset_bottom
Offset of the bottom border onroot
from 0.0 to 1.0
gamnit :: Texture :: offset_left
Offset of the left border onroot
from 0.0 to 1.0
gamnit :: Texture :: offset_right
Offset of the right border onroot
from 0.0 to 1.0
gamnit :: Texture :: offset_top
Offset of the top border onroot
from 0.0 to 1.0
core :: Object :: output_class_name
Display class name on stdout (debug only).gamnit :: Texture :: pixelated=
Should this texture be drawn pixelated when magnified? otherwise it is interpolatedgamnit :: RootTexture :: premultiply_alpha
Should the pixels RGB values be premultiplied by their alpha value at loading?gamnit :: RootTexture :: premultiply_alpha=
Should the pixels RGB values be premultiplied by their alpha value at loading?gamnit :: Texture :: subtexture
Prepare a subtexture from this texture, from the given pixel offsetsgamnit :: Texture :: to_animation
Convert to a sprite animation atfps
speed with x
or y
frames
# Texture with its own pixel data
class RootTexture
super Texture
redef fun root do return self
# Has this texture been loaded yet?
var loaded = false
redef var gl_texture = -1
init do all_root_textures.add self
# Should the pixels RGB values be premultiplied by their alpha value at loading?
#
# All gamnit textures must have premultiplied alpha, it provides a better
# alpha blending, avoids artifacts and allows for additive blending.
#
# When at `true`, the default, pixels RGB values are premultiplied
# at loading. Set to `false` if pixels RGB values are already
# premultiplied in the source data.
#
# This value must be set before calling `load`.
var premultiply_alpha = true is writable
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
private fun load_checker(size: Int)
do
var cpixels = new CByteArray(3*size*size)
var i = 0
for x in [0..size[ do
var quadrant_x = if x < size/2 then 0 else 1
for y in [0..size[ do
var quadrant_y = if y < size/2 then 0 else 1
var color = if quadrant_x == quadrant_y then
[0u8, 0u8, 0u8, 255u8]
else [255u8, 255u8, 255u8, 255u8]
for j in [0..3[ do cpixels[i+j] = color[j]
i += 3
end
end
width = size.to_f
height = size.to_f
load_from_pixels(cpixels.native_array, size, size, gl_RGB)
cpixels.destroy
end
# Has this resource been deleted?
var deleted = false
# Delete this texture and free all its resources
#
# Use caution with this service as the subtextures may rely on the deleted data.
fun delete
do
if deleted or not loaded then return
deleted = true
end
end
lib/gamnit/textures.nit:217,1--309,3