-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
raylib data structures
Ray edited this page Aug 11, 2021
·
15 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; [16 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; [16 bytes] [+8 bytes] // Audio buffer pointer (private) and parameters
struct Sound; [20 bytes] [+12 bytes] // Audio stream and samples count
struct Music; [32 bytes] [+16 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).
// core.c
char **GetDirectoryFiles(const char *dirPath, int *count); // Get filenames in a directory path (memory should be freed)
char **GetDroppedFiles(int *count); // Get dropped files names (memory should be freed)
// camera.h
void UpdateCamera(Camera *camera); // Update camera position for selected mode
// textures.c
// NOTE: By design, MOST of the [Image*()] functions require passing an [Image *image] for modification
void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture
// 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
int *GetCodepoints(const char *text, int *count); // Get all codepoints in a string, codepoints count returned by parameters
int GetNextCodepoint(const char *text, int *bytesProcessed); // Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure
const char *CodepointToUtf8(int codepoint, int *byteLength); // Encode codepoint into utf8 text (char array length returned as parameter)
// models.c
Mesh *LoadMeshes(const char *fileName, int *meshCount); // Load meshes from model file
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
void GenMeshBinormals(Mesh *mesh); // Compute mesh binormals
bool CheckCollisionRaySphereEx(Ray ray, Vector3 center, float radius, Vector3 *collisionPoint); // Detect collision between ray and sphere, returns collision point
void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
// 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