Usually, you should create Texture2D
from an Image
and then use the texture to draw on the screen.
Here are the steps you should follow:
- Call
LoadIamge
to load a image from file - Optional to call
ImageResize
if want particular size rather than the original image size - call
LoadTextureFromImage
to createTexture2D
instance - Call
UnloadImage
as you don’t need theImage
instance anymore - Call
DrawTexturePro
to draw the texture to screen - Finally, call
UnloadTexture
before program closes
src/tutorial_examples/how-to-draw-images-and-textures.zig
You can create an empty Image
or load from a file and then apply the custom editing to that Image
instance, here are the related APIs:
// NOTE: Image software-rendering functions (CPU)
// Clear image background with given color
void ImageClearBackground(Image *dst, Color color);
// Draw pixel within an image
void ImageDrawPixel(Image *dst, int posX, int posY, Color color);
// Draw pixel within an image (Vector version)
void ImageDrawPixelV(Image *dst, Vector2 position, Color color);
// Draw line within an image
void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color);
// Draw line within an image (Vector version)
void ImageDrawLineV(Image *dst, Vector2 start, Vector2 end, Color color);
// Draw a filled circle within an image
void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Color color);
// Draw a filled circle within an image (Vector version)
void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color);
// Draw circle outline within an image
void ImageDrawCircleLines(Image *dst, int centerX, int centerY, int radius, Color color);
// Draw circle outline within an image (Vector version)
void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color);
// Draw rectangle within an image
void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color);
// Draw rectangle within an image (Vector version)
void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color);
// Draw rectangle within an image
void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color);
// Draw rectangle lines within an image
void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color);
// Draw a source image within a destination image (tint applied to source)
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint);
// Draw text (using default font) within an image (destination)
void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color);
// Draw text (custom sprite font) within an image (destination)
void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint);