ImageTexture

package
v0.0.0-...-e10d1cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

A Texture2D based on an Image. For an image to be displayed, an ImageTexture has to be created from it using the CreateFromImage method:

package main

import (
	"graphics.gd/classdb/Image"
	"graphics.gd/classdb/ImageTexture"
	"graphics.gd/classdb/Sprite2D"
)

func ExampleImageTexture(sprite Sprite2D.Instance) {
	var image = Image.LoadFromFile("res://icon.svg")
	var texture = ImageTexture.CreateFromImage(image)
	sprite.SetTexture(texture.AsTexture2D())
}

This way, textures can be created at run-time by loading images both from within the editor and externally.

Warning: Prefer to load imported textures with @GDScript.Load over loading them from within the filesystem dynamically with Image.Load, as it may not work in exported projects:

package main

import (
	"graphics.gd/classdb/Resource"
	"graphics.gd/classdb/Sprite2D"
	"graphics.gd/classdb/Texture2D"
)

func ExampleLoadImageTexture(sprite Sprite2D.Instance) {
	var texture = Resource.Load[Texture2D.Instance]("res://icon.svg")
	sprite.SetTexture(texture.AsTexture2D())
}

This is because images have to be imported as a CompressedTexture2D first to be loaded with @GDScript.Load. If you'd still like to load an image file just like any other Resource, import it as an Image resource instead, and then load it normally using the @GDScript.Load method.

Note: The image can be retrieved from an imported texture using the Texture2D.GetImage method, which returns a copy of the image:

package main

import (
	"graphics.gd/classdb/Resource"
	"graphics.gd/classdb/Sprite2D"
	"graphics.gd/classdb/Texture2D"
)

func ExampleLoadImage(sprite Sprite2D.Instance) {
	var texture = Resource.Load[Texture2D.Instance]("res://icon.svg")
	var image = texture.GetImage()
	_ = image
}

An ImageTexture is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new EditorImportPlugin.

Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsImageTexture() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsImageTexture

func (self *Extension[T]) AsImageTexture() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

func (*Extension[T]) AsTexture

func (self *Extension[T]) AsTexture() Texture.Instance

func (*Extension[T]) AsTexture2D

func (self *Extension[T]) AsTexture2D() Texture2D.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.ImageTexture

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func CreateFromImage

func CreateFromImage(image Image.Instance) Instance

Creates a new ImageTexture and initializes it by allocating and setting the data from an Image.

func New

func New() Instance

func (Instance) AsImageTexture

func (self Instance) AsImageTexture() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) AsTexture

func (self Instance) AsTexture() Texture.Instance

func (Instance) AsTexture2D

func (self Instance) AsTexture2D() Texture2D.Instance

func (Instance) GetFormat

func (self Instance) GetFormat() Image.Format

Returns the format of the texture.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) SetImage

func (self Instance) SetImage(image Image.Instance)

Replaces the texture's data with a new Image. This will re-allocate new memory for the texture.

If you want to update the image, but don't need to change its parameters (format, size), use Update instead for better performance.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetSizeOverride

func (self Instance) SetSizeOverride(size Vector2i.XY)

Resizes the texture to the specified dimensions.

func (Instance) Update

func (self Instance) Update(image Image.Instance)

Replaces the texture's data with a new Image.

Note: The texture has to be created using CreateFromImage or initialized first with the SetImage method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration.

Use this method over SetImage if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL