Skip to content

Latest commit

 

History

History
72 lines (49 loc) · 3.12 KB

d-how-to-draw-image-and-textures.org

File metadata and controls

72 lines (49 loc) · 3.12 KB

How to draw images and textures

Regular steps to load and draw image (as texture)

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 create Texture2D instance
  • Call UnloadImage as you don’t need the Image instance anymore
  • Call DrawTexturePro to draw the texture to screen
  • Finally, call UnloadTexture before program closes

Example

src/tutorial_examples/how-to-draw-images-and-textures.zig

What if you want to create a custom image or edit the existing image

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);