ft_rgb - 1Fr3aK2/Cub3d GitHub Wiki
📝 ft_rgb
Combines three 8-bit color components (red, green, blue) into a single 32-bit RGB color value.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
r |
uint8_t |
The red color component (0–255). |
g |
uint8_t |
The green color component (0–255). |
b |
uint8_t |
The blue color component (0–255). |
🔁 Returns
| Return value | Description |
|---|---|
uint32_t |
A 32-bit integer representing the combined RGB color in the format 0xRRGGBB. |
📖 Description
The ft_rgb function takes three 8-bit color values representing red, green, and blue components and merges them into a single 32-bit integer using bit shifting and bitwise OR operations.
- The red component
ris shifted left by 16 bits. - The green component
gis shifted left by 8 bits. - The blue component
bremains in the lower 8 bits.
This produces a color value commonly used in graphics applications, where the result is formatted as 0xRRGGBB.
💡 Example Usage
uint32_t color;
// Create a bright yellow color (255, 255, 0)
color = ft_rgb(255, 255, 0);
printf("RGB color value: 0x%06X\n", color); // Output: RGB color value: 0xFFFF00