Skip to main content

Overview

Texture functions handle loading, unloading, and drawing textures and images. Textures are GPU-resident images optimized for rendering.

Texture Loading

loadTexture

Loads texture from file into GPU memory (VRAM).
fileName
String
required
Path to image file (supports .png, .jpg, .bmp, .tga, .gif, etc.)
Returns: Texture2D - Loaded texture
import "raylib" for Raylib, Texture2D, Color

Raylib.initWindow(800, 450, "Texture Example")

var texture = Texture2D.loadTexture("resources/player.png")

while (!Raylib.windowShouldClose()) {
  Raylib.beginDrawing()
  Raylib.clearBackground(Color.RayWhite)
  
  Raylib.drawTexture(texture, 100, 100, Color.White)
  
  Raylib.endDrawing()
}

texture.unloadTexture()
Raylib.closeWindow()

loadTextureFromImage

Loads texture from image data.
image
Image
required
Image to convert to texture
Returns: Texture2D - Loaded texture
var image = Raylib.loadImage("player.png")
// Modify image here if needed
var texture = Raylib.loadTextureFromImage(image)
Raylib.unloadImage(image)

isTextureValid

Checks if a texture is valid.
texture
Texture2D
required
Texture to check
Returns: Boolean - True if texture is valid
if (Raylib.isTextureValid(texture)) {
  Raylib.drawTexture(texture, 0, 0, Color.White)
}

unloadTexture

Unloads texture from GPU memory.
texture
Texture2D
required
Texture to unload
texture.unloadTexture()
// or
Raylib.unloadTexture(texture)

Render Textures

loadRenderTexture

Loads a render texture for off-screen rendering.
width
Number
required
Render texture width
height
Number
required
Render texture height
Returns: RenderTexture2D - Render texture
var renderTexture = Raylib.loadRenderTexture(800, 450)

// Draw to render texture
Raylib.beginTextureMode(renderTexture)
Raylib.clearBackground(Color.RayWhite)
Raylib.drawCircle(400, 225, 100, Color.Red)
Raylib.endTextureMode()

// Use render texture
Raylib.beginDrawing()
Raylib.clearBackground(Color.Black)
Raylib.drawTexture(renderTexture.texture, 0, 0, Color.White)
Raylib.endDrawing()

Raylib.unloadRenderTexture(renderTexture)

isRenderTextureValid

Checks if a render texture is valid.
target
RenderTexture2D
required
Render texture to check
Returns: Boolean - True if valid

unloadRenderTexture

Unloads render texture from GPU memory.
target
RenderTexture2D
required
Render texture to unload
Raylib.unloadRenderTexture(renderTexture)

Texture Drawing

drawTexture

Draws a texture at specified position.
texture
Texture2D
required
Texture to draw
posX
Number
required
X position
posY
Number
required
Y position
tint
Color
required
Tint color (use Color.White for no tint)
Raylib.drawTexture(texture, 100, 100, Color.White)

// Draw with red tint
Raylib.drawTexture(texture, 200, 100, Color.Red)

drawTextureV

Draws a texture with position defined by a Vector2.
texture
Texture2D
required
Texture to draw
position
Vector2
required
Position vector
tint
Color
required
Tint color
var position = Vector2.new(100, 100)
Raylib.drawTextureV(texture, position, Color.White)

drawTextureEx

Draws a texture with extended parameters.
texture
Texture2D
required
Texture to draw
position
Vector2
required
Position vector
rotation
Number
required
Rotation in degrees
scale
Number
required
Scale factor
tint
Color
required
Tint color
var rotation = 45.0  // degrees
var scale = 2.0      // 2x size
Raylib.drawTextureEx(texture, Vector2.new(400, 300), rotation, scale, Color.White)

drawTextureRec

Draws a part of a texture (source rectangle).
texture
Texture2D
required
Texture to draw
source
Rectangle
required
Source rectangle within texture
position
Vector2
required
Position to draw at
tint
Color
required
Tint color
// Draw sprite from sprite sheet
var spriteSize = 32
var frameX = 0
var frameY = 0
var sourceRec = Rectangle.new(frameX * spriteSize, frameY * spriteSize, spriteSize, spriteSize)
var position = Vector2.new(100, 100)

Raylib.drawTextureRec(spriteSheet, sourceRec, position, Color.White)

drawTexturePro

Draws a texture with pro parameters (source, dest, origin, rotation).
texture
Texture2D
required
Texture to draw
source
Rectangle
required
Source rectangle
dest
Rectangle
required
Destination rectangle
origin
Vector2
required
Rotation origin point
rotation
Number
required
Rotation in degrees
tint
Color
required
Tint color
var source = Rectangle.new(0, 0, texture.width, texture.height)
var dest = Rectangle.new(400, 300, texture.width * 2, texture.height * 2)
var origin = Vector2.new(texture.width, texture.height)  // Rotate around center
var rotation = 45.0

Raylib.drawTexturePro(texture, source, dest, origin, rotation, Color.White)

Texture Configuration

updateTexture

Updates GPU texture with new data.
texture
Texture2D
required
Texture to update
pixels
Data
required
Pixel data

genTextureMipmaps

Generates GPU mipmaps for a texture.
texture
Texture2D
required
Texture to generate mipmaps for
Raylib.genTextureMipmaps(texture)

setTextureFilter

Sets texture scaling filter mode.
texture
Texture2D
required
Texture to configure
filter
Number
required
Filter mode (0=POINT, 1=BILINEAR, 2=TRILINEAR, 3=ANISOTROPIC_4X, 4=ANISOTROPIC_8X, 5=ANISOTROPIC_16X)
// Use point filtering for pixel-perfect rendering
Raylib.setTextureFilter(texture, 0)  // TEXTURE_FILTER_POINT

// Use bilinear filtering for smooth scaling
Raylib.setTextureFilter(texture, 1)  // TEXTURE_FILTER_BILINEAR

setTextureWrap

Sets texture wrapping mode.
texture
Texture2D
required
Texture to configure
wrap
Number
required
Wrap mode (0=REPEAT, 1=CLAMP, 2=MIRROR_REPEAT, 3=MIRROR_CLAMP)
Raylib.setTextureWrap(texture, 0)  // TEXTURE_WRAP_REPEAT

Image Loading (CPU)

loadImage

Loads image from file into CPU memory (can be manipulated).
fileName
String
required
Path to image file
Returns: Image - Loaded image
var image = Raylib.loadImage("player.png")
// Modify image on CPU
Raylib.imageColorTint(image, Color.Red)
// Convert to texture for rendering
var texture = Raylib.loadTextureFromImage(image)
Raylib.unloadImage(image)

isImageValid

Checks if an image is valid.
image
Image
required
Image to check
Returns: Boolean - True if valid

unloadImage

Unloads image from CPU memory.
image
Image
required
Image to unload
Raylib.unloadImage(image)

Texture Properties

Texture2D.width

Gets the width of a texture. Returns: Number - Texture width in pixels
var width = texture.width

Texture2D.height

Gets the height of a texture. Returns: Number - Texture height in pixels
var height = texture.height
var centerX = width / 2
var centerY = height / 2

Best Practices

Load textures once during initialization and reuse them. Texture loading is expensive!
Always unload textures when done to free GPU memory:
texture.unloadTexture()
Images are CPU-resident, textures are GPU-resident. Convert images to textures for rendering:
var image = Raylib.loadImage("sprite.png")
var texture = Raylib.loadTextureFromImage(image)
Raylib.unloadImage(image)  // Free CPU memory
For pixel art games, use point filtering to maintain sharp edges:
Raylib.setTextureFilter(texture, 0)  // TEXTURE_FILTER_POINT

Build docs developers (and LLMs) love