-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
raylib data structures
Ian Harris edited this page Jan 7, 2025
·
16 revisions
raylib provides a set of data structures to help with organizing game data. These structs are common to most engines, and will be familiar to anyone who has authored video games before.
Struct name [32bit size] [64bit change] Description
-----------------------------------------------------------------------------------------------------------------------
// Basic data structures
struct Color; [ 4 bytes] - // RGBA values, 4 char, 32bit color
struct Rectangle; [16 bytes] - // 4 float values
struct Vector2; [ 8 bytes] - // 2 float values
struct Vector3; [12 bytes] - // 3 float values
struct Vector4; [16 bytes] - // 4 float values
struct Matrix; [64 bytes] - // 16 float values, right handed, column major
struct Quaternion; [16 bytes] - // Vector4 alias
// 2D data structures (pixels, font...)
struct Image; [20 bytes] [+4 bytes] // Image data pointer (RAM) and 4 data parameters
struct Texture; [20 bytes] - // OpenGL texture id (VRAM) and basic info
struct Texture2D; [20 bytes] - // Texture alias
struct TextureCubemap; [20 bytes] - // OpenGL cubemap, texture alias
struct RenderTexture; [44 bytes] - // OpenGL framebuffer id and color + depth textures
struct RenderTexture2D; [44 bytes] - // RenderTexture alias
struct NPatchInfo [36 bytes] - // Source rectangle and border offsets
struct GlyphInfo; [32 bytes] [+4 bytes] // One glyph character metrics and image
struct Font; [40 bytes] [+12 bytes] // Texture atlas and recs+chars data array pointers
// Screen view structures
struct Camera2D; [24 bytes] - // 2D camera offset, target, rotation and zoom
struct Camera3D; [44 bytes] - // 3D camera position, target, up vectors and parameters
struct Camera; [44 bytes] - // Camera3D alias
struct VrDeviceInfo; [64 bytes] - // Head-Mounted-Display device configuration parameters
struct VrStereoConfig; [304 bytes] - // VR stereo rendering configuration for simulator
// 3D data structures (vertex, material properties...)
// NOTE: Those structures are more complex so they use some internal pointers to data
struct Mesh; [60 bytes] [+52 bytes] // Vertex data, OpenGL buffers ids, animation data (skeleton bones and pose)
struct Shader; [ 8 bytes] [+8 bytes] // OpenGL program id, locations array pointer
struct Material; [16 bytes] [+16 bytes] // Shader and maps array pointer
struct MaterialMap [28 bytes] - // Texture, color and value
struct Model; [96 bytes] [+24 bytes] // Meshes+materials array pointers, transform matrix (64 bytes)
struct ModelAnimation; [48 bytes] [+8 bytes] // Skeletal bones data and frames transformation
struct BoneInfo; [36 bytes] - // Bone name (32 bytes) and parent id
struct Transform; [40 bytes] - // Vertex transformation: translation, rotation, scale
struct Ray; [24 bytes] - // Ray-casting position+direction vectors
struct RayCollision; [32 bytes] - // Ray collision information
struct BoundingBox; [12 bytes] - // Defined by min and max vertex
// Audio related data
struct Wave; [20 bytes] [+4 bytes] // Wave data pointer (RAM) and data parameters
struct AudioStream; [20 bytes] [+12 bytes] // Audio buffer pointer (private) and parameters
struct Sound; [24 bytes] [+16 bytes] // Audio stream and samples count
struct Music; [36 bytes] [+20 bytes] // Audio stream and music data pointer for streaming
raylib slightly abuses the ability to pass-by-value. In fact, only around 10% of its functions need to deal with data pointers. With this in mind, data structures are kept as small as possible (usually under 64 bytes), and internal pointers are used with functions that need to modify the data (usually Load, Update and Unload functions).
// camera.h
void UpdateCamera(Camera *camera); // Update camera position for selected
void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, float zoom); // Update camera movement/rotation
// textures.c
void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture
void SetPixelColor(void *dstPtr, Color color, int format); // Set color formatted into destination pixel pointer
void ImageFormat(Image *image, int newFormat); // Convert image data to desired format
void ImageToPOT(Image *image, Color fill); // Convert image to POT (power-of-two)
void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle
void ImageAlphaCrop(Image *image, float threshold); // Crop image depending on alpha value
void ImageAlphaClear(Image *image, Color color, float threshold); // Clear alpha channel to desired color
void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel
void ImageBlurGaussian(Image *image, int blurSize); // Apply Gaussian blur using a box blur approximation
void ImageKernelConvolution(Image *image, const float *kernel, int kernelSize); // Apply custom square convolution kernel to image
void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (Bicubic scaling algorithm)
void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm)
void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill); // Resize canvas and fill with color
void ImageMipmaps(Image *image); // Compute all mipmap levels for a provided image
void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
void ImageFlipVertical(Image *image); // Flip image vertically
void ImageFlipHorizontal(Image *image); // Flip image horizontally
void ImageRotate(Image *image, int degrees); // Rotate image by input angle in degrees (-359 to 359)
void ImageRotateCW(Image *image); // Rotate image clockwise 90deg
void ImageRotateCCW(Image *image); // Rotate image counter-clockwise 90deg
void ImageColorTint(Image *image, Color color); // Modify image color: tint
void ImageColorInvert(Image *image); // Modify image color: invert
void ImageColorGrayscale(Image *image); // Modify image color: grayscale
void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100)
void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255)
void ImageColorReplace(Image *image, Color color, Color replace); // Modify image color: replace color
void ImageClearBackground(Image *dst, Color color); // Clear image background with given color
void ImageDrawPixel(Image *dst, int posX, int posY, Color color); // Draw pixel within an image
void ImageDrawPixelV(Image *dst, Vector2 position, Color color); // Draw pixel within an image (Vector version)
void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw line within an image
void ImageDrawLineV(Image *dst, Vector2 start, Vector2 end, Color color); // Draw line within an image (Vector version)
void ImageDrawLineEx(Image *dst, Vector2 start, Vector2 end, int thick, Color color); // Draw a line defining thickness within an image
void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Color color); // Draw a filled circle within an image
void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color); // Draw a filled circle within an image (Vector version)
void ImageDrawCircleLines(Image *dst, int centerX, int centerY, int radius, Color color); // Draw circle outline within an image
void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color); // Draw circle outline within an image (Vector version)
void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color); // Draw rectangle within an image
void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color); // Draw rectangle within an image (Vector version)
void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color); // Draw rectangle within an image
void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color); // Draw rectangle lines within an image
void ImageDrawTriangle(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle within an image
void ImageDrawTriangleEx(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color c1, Color c2, Color c3); // Draw triangle with interpolated colors within an image
void ImageDrawTriangleLines(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline within an image
void ImageDrawTriangleFan(Image *dst, Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points within an image (first vertex is the center)
void ImageDrawTriangleStrip(Image *dst, Vector2 *points, int pointCount, Color color); // Draw a triangle strip defined by points within an image
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source)
void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination)
void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text (custom sprite font) within an image (destination)
// text.c
Image GenImageFontAtlas(const CharInfo *chars, Rectangle **recs, int charsCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info
const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings
void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor!
int GetCodepoint(const char *text, int *codepointSize); // Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
int GetCodepointNext(const char *text, int *codepointSize); // Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
int GetCodepointPrevious(const char *text, int *codepointSize); // Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
const char *CodepointToUTF8(int codepoint, int *utf8Size); // Encode one codepoint into UTF-8 byte array (array length returned as parameter)
// models.c
void UploadMesh(Mesh *mesh, bool dynamic); // Upload mesh vertex data in GPU and provide VAO/VBO ids
void SetMaterialTexture(Material *material, int mapType, Texture2D texture); // Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
void SetModelMeshMaterial(Model *model, int meshId, int materialId); // Set material for a mesh
ModelAnimation *LoadModelAnimations(const char *fileName, int *animsCount); // Load model animations from file
void GenMeshTangents(Mesh *mesh); // Compute mesh tangents
// audio.c
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range
www.raylib.com | itch.io | GitHub | Discord | YouTube
- Architecture
- Syntax analysis
- Data structures
- Enumerated types
- External dependencies
- GLFW dependency
- libc dependency
- Platforms and graphics
- Input system
- Default shader
- Custom shaders
- Coding conventions
- Integration with other libs
- Working on Windows
- Working on macOS
- Working on GNU Linux
- Working on Chrome OS
- Working on FreeBSD
- Working on Raspberry Pi
- Working for Android
- Working for Web (HTML5)
- Working on exaequOS Web Computer
- Creating Discord Activities
- Working anywhere with CMake
- CMake Build Options
- raylib templates: Get started easily
- How To: Quick C/C++ Setup in Visual Studio 2022, GCC or MinGW
- How To: C# Visual Studio Setup
- How To: VSCode
- How To: Eclipse
- How To: Sublime Text
- How To: Code::Blocks