gamnit :: TextureAsset :: _path
Path to this texture within theassets
folder
gamnit :: TextureAsset :: defaultinit
gamnit :: TextureAsset :: glkit_load
Load image atpath
with GLKit services
gamnit :: TextureAsset :: load_bitmap
gamnit :: TextureAsset :: load_from_platform
Partially load this texture from platform-specific featuresgamnit :: TextureAsset :: path=
Path to this texture within theassets
folder
gamnit $ TextureAsset :: SELF
Type of this instance, automatically specialized in every classgamnit $ TextureAsset :: load
Load this texture, force reloading it ifforce
gamnit :: android19 $ TextureAsset :: load_bitmap
gamnit :: display_linux $ TextureAsset :: load_from_platform
Partially load this texture from platform-specific featuresgamnit :: display_ios $ TextureAsset :: load_from_platform
Partially load this texture from platform-specific featuresgamnit :: display_android $ TextureAsset :: load_from_platform
Partially load this texture from platform-specific featuresgamnit :: RootTexture :: _gl_texture
gamnit :: TextureAsset :: _path
Path to this texture within theassets
folder
gamnit :: RootTexture :: _premultiply_alpha
Should the pixels RGB values be premultiplied by their alpha value at loading?gamnit :: Texture :: _texture_coords
Coordinates of this texture on theroot
texture, in [0..1.0]
gamnit :: Texture :: _texture_coords_invert_x
Coordinates of this texture on theroot
texture, inverting the X axis
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
gamnit :: Texture :: defaultinit
core :: Object :: defaultinit
gamnit :: RootTexture :: defaultinit
gamnit :: TextureAsset :: defaultinit
gamnit :: RootTexture :: deleted=
Has this resource been deleted?gamnit :: RootTexture :: gl_texture=
gamnit :: TextureAsset :: glkit_load
Load image atpath
with GLKit services
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 :: TextureAsset :: load_bitmap
gamnit :: RootTexture :: load_checker
gamnit :: TextureAsset :: load_from_platform
Partially load this texture from platform-specific featuresgamnit :: RootTexture :: loaded=
Has this texture been loaded yet?core :: Object :: native_class_name
The class name of the object in CString format.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 :: TextureAsset :: path=
Path to this texture within theassets
folder
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 :: texture_coords
Coordinates of this texture on theroot
texture, in [0..1.0]
gamnit :: Texture :: texture_coords=
Coordinates of this texture on theroot
texture, in [0..1.0]
gamnit :: Texture :: texture_coords_invert_x
Coordinates of this texture on theroot
texture, inverting the X axis
gamnit :: Texture :: texture_coords_invert_x=
Coordinates of this texture on theroot
texture, inverting the X axis
gamnit :: Texture :: to_animation
Convert to a sprite animation atfps
speed with x
or y
frames
# Texture loaded from the assets folder
class TextureAsset
super RootTexture
# Path to this texture within the `assets` folder
var path: String
redef fun load(force)
do
if loaded and force != true then return
load_from_platform
# If no pixel data was loaded, load the pixel default texture
if gl_texture == -1 then load_checker 32
loaded = true
end
# Partially load this texture from platform-specific features
#
# This method should fill `width`, `height` and `pixels`.
private fun load_from_platform is abstract
redef fun to_s do return "<{class_name} path:{path}>"
end
lib/gamnit/textures.nit:311,1--336,3
redef class TextureAsset
redef fun load_from_platform
do
var path = "assets" / path
var surface = new SDLSurface.load(path.to_cstring)
if surface.address_is_null then
error = new Error("Failed to load texture at '{path}'")
return
end
self.width = surface.w.to_f
self.height = surface.h.to_f
var format = if surface.format.amask > 0u32 then gl_RGBA else gl_RGB
var pixels = surface.pixels
load_from_pixels(pixels, surface.w, surface.h, format)
surface.free
end
end
lib/gamnit/display_linux.nit:124,1--145,3
redef class TextureAsset
redef fun load_from_platform
do
var error = glGetError
assert error == gl_NO_ERROR else print_error error
# Find file
var ns_path = ("assets"/path).to_nsstring
var path_in_bundle = asset_path(ns_path)
if path_in_bundle.address_is_null then
self.error = new Error("Texture at '{path}' not found")
return
end
# Load texture
var glk_texture = glkit_load(path_in_bundle, premultiply_alpha)
if glk_texture.address_is_null then
self.error = new Error("Failed to load texture at '{self.path}'")
return
end
gl_texture = glk_texture.name
width = glk_texture.width.to_f
height = glk_texture.height.to_f
loaded = true
error = glGetError
assert error == gl_NO_ERROR
end
# Load image at `path` with GLKit services
private fun glkit_load(path: NSString, premultiply: Bool): GLKTextureInfo
in "ObjC" `{
// The premultiplication flag has been inverted between iOS 9 and 10
NSNumber *premultiply_opt;
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"10.0.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending) {
// >= 10
premultiply_opt = premultiply? @NO: @YES;
} else {
// < 10
premultiply_opt = premultiply? @YES: @NO;
}
NSDictionary *options = @{GLKTextureLoaderApplyPremultiplication: premultiply_opt};
NSError *error;
GLKTextureInfo *spriteTexture = [GLKTextureLoader textureWithContentsOfFile: path options: options error: &error];
if (error != nil) NSLog(@"Failed to load texture: %@", [error localizedDescription]); // TODO return details to Nit
return spriteTexture;
`}
end
lib/gamnit/display_ios.nit:51,1--103,3
redef class TextureAsset
private fun load_bitmap(asset_manager: AssetManager, path: String): NativeBitmap
do
return asset_manager.bitmap(path)
end
redef fun load_from_platform
do
jni_env.push_local_frame 4
var asset_manager = app.asset_manager
var bmp = load_bitmap(asset_manager, path)
if bmp.is_java_null then
error = new Error("Failed to load texture at '{path}'")
jni_env.pop_local_frame
return
end
var buf = bmp.copy_pixels(unmultiply=not premultiply_alpha)
loaded = true
width = bmp.width.to_f
height = bmp.height.to_f
var pixels = buf.native_array
load_from_pixels(pixels, bmp.width, bmp.height, gl_RGBA)
buf.destroy
bmp.recycle
jni_env.pop_local_frame
end
end
lib/gamnit/display_android.nit:54,1--85,3
redef class TextureAsset
redef fun load_bitmap(asset_manager, path)
do
var stream = asset_manager.native_assets_manager.open(path.to_java_string)
return new NativeBitmap.from_stream_ex(stream, premultiply_alpha)
end
end
lib/gamnit/android19.nit:33,1--40,3