7 Commits

Author SHA1 Message Date
Ray
1825891abc REVIEWED: Variables naming for consistency
- `Image im*`
 - `Texture2D tex*`
 - `RenderTexture2D rt*` or `RenderTexture2D target`
 - `Mesh mesh*`
 - `Model model*`
 - `Sound fx*` or `Sound sound`
 - `Music music`
2026-11-11 11:59:11 +01:00
Ray
847804b0cf REVIEWED: Variables naming for consistency 2026-11-11 11:53:31 +01:00
Ray
87e78f78ec Merge branch 'master' of https://github.com/raysan5/raylib 2026-11-11 09:52:52 +01:00
Ray
e482ef1efe Fix #6403 2026-11-11 09:52:31 +01:00
fbcb6836cd [rtext] Fix TextToFloat() rounding and add exponent support (#6313)
* [rtext] Fix `TextToFloat()` rounding and add exponent support

* [rtext] Use only floats in `TextToFloat()`

* [rtext] Remove static array from `TextToFloat()`
2026-11-11 09:45:43 +01:00
Ray
1de8a875a8 Update textures_srcrec_dstrec.c 2026-11-11 09:41:13 +01:00
d670416c68 Clarify srcrec_dstrec examples (#6401)
It wasn't obvious why scarfy width was divided by 6 @ line 34
In addition, it is confusing to use the unscaled texture
to get it's center point when it's supposed to be relative
to the destination rectangle, so I changed it to use the
destination rectangle members instead
2026-11-11 09:34:11 +01:00
52 changed files with 749 additions and 704 deletions

View File

@ -18,8 +18,6 @@
#include "raylib.h" #include "raylib.h"
#define MAX_SOUNDS 10 #define MAX_SOUNDS 10
Sound soundArray[MAX_SOUNDS] = { 0 };
int currentSound;
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
@ -34,15 +32,15 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound multi"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound multi");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
Sound sounds[MAX_SOUNDS] = { 0 };
int currentSound = 0;
// Load audio file into the first slot as the 'source' sound, // Load audio file into the first slot as the 'source' sound
// this sound owns the sample data sounds[0] = LoadSound("resources/sound.wav");
soundArray[0] = LoadSound("resources/sound.wav");
// Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played // Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played
for (int i = 1; i < MAX_SOUNDS; i++) soundArray[i] = LoadSoundAlias(soundArray[0]); for (int i = 1; i < MAX_SOUNDS; i++) sounds[i] = LoadSoundAlias(sounds[0]);
currentSound = 0; // Set the sound list to the start
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -54,7 +52,7 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) if (IsKeyPressed(KEY_SPACE))
{ {
PlaySound(soundArray[currentSound]); // Play the next open sound slot PlaySound(sounds[currentSound]); // Play the next open sound slot
currentSound++; // Increment the sound slot currentSound++; // Increment the sound slot
// If the sound slot is out of bounds, go back to 0 // If the sound slot is out of bounds, go back to 0
@ -79,8 +77,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
for (int i = 1; i < MAX_SOUNDS; i++) UnloadSoundAlias(soundArray[i]); // Unload sound aliases for (int i = 1; i < MAX_SOUNDS; i++) UnloadSoundAlias(sounds[i]); // Unload sound aliases
UnloadSound(soundArray[0]); // Unload source sound data UnloadSound(sounds[0]); // Unload source sound data
CloseAudioDevice(); // Close audio device CloseAudioDevice(); // Close audio device

View File

@ -80,9 +80,9 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spectrum visualizer"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - spectrum visualizer");
Image fftImage = GenImageColor(BUFFER_SIZE, TEXTURE_HEIGHT, WHITE); Image imFFT = GenImageColor(BUFFER_SIZE, TEXTURE_HEIGHT, WHITE);
Texture2D fftTexture = LoadTextureFromImage(fftImage); Texture2D texFFT = LoadTextureFromImage(imFFT);
RenderTexture2D bufferA = LoadRenderTexture(screenWidth, screenHeight); RenderTexture2D rtBufferA = LoadRenderTexture(screenWidth, screenHeight);
Vector2 iResolution = { (float)screenWidth, (float)screenHeight }; Vector2 iResolution = { (float)screenWidth, (float)screenHeight };
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/fft.fs", GLSL_VERSION)); Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/fft.fs", GLSL_VERSION));
@ -90,14 +90,14 @@ int main(void)
int iResolutionLocation = GetShaderLocation(shader, "iResolution"); int iResolutionLocation = GetShaderLocation(shader, "iResolution");
int iChannel0Location = GetShaderLocation(shader, "iChannel0"); int iChannel0Location = GetShaderLocation(shader, "iChannel0");
SetShaderValue(shader, iResolutionLocation, &iResolution, SHADER_UNIFORM_VEC2); SetShaderValue(shader, iResolutionLocation, &iResolution, SHADER_UNIFORM_VEC2);
SetShaderValueTexture(shader, iChannel0Location, fftTexture); SetShaderValueTexture(shader, iChannel0Location, texFFT);
InitAudioDevice(); InitAudioDevice();
SetAudioStreamBufferSizeDefault(AUDIO_STREAM_RING_BUFFER_SIZE); SetAudioStreamBufferSizeDefault(AUDIO_STREAM_RING_BUFFER_SIZE);
// WARNING: Memory out-of-bounds on PLATFORM_WEB // WARNING: Memory out-of-bounds on PLATFORM_WEB
Wave wav = LoadWave("resources/country.mp3"); Wave wave = LoadWave("resources/country.mp3");
WaveFormat(&wav, SAMPLE_RATE, PER_SAMPLE_BIT_DEPTH, MONO); WaveFormat(&wave, SAMPLE_RATE, PER_SAMPLE_BIT_DEPTH, MONO);
AudioStream audioStream = LoadAudioStream(SAMPLE_RATE, PER_SAMPLE_BIT_DEPTH, MONO); AudioStream audioStream = LoadAudioStream(SAMPLE_RATE, PER_SAMPLE_BIT_DEPTH, MONO);
PlayAudioStream(audioStream); PlayAudioStream(audioStream);
@ -116,7 +116,7 @@ int main(void)
}; };
unsigned int wavCursor = 0; unsigned int wavCursor = 0;
const short *wavPCM16 = wav.data; const short *wavPCM16 = wave.data;
short chunkSamples[AUDIO_STREAM_RING_BUFFER_SIZE] = { 0 }; short chunkSamples[AUDIO_STREAM_RING_BUFFER_SIZE] = { 0 };
float audioSamples[FFT_WINDOW_SIZE] = { 0 }; float audioSamples[FFT_WINDOW_SIZE] = { 0 };
@ -133,11 +133,11 @@ int main(void)
{ {
for (int i = 0; i < AUDIO_STREAM_RING_BUFFER_SIZE; i++) for (int i = 0; i < AUDIO_STREAM_RING_BUFFER_SIZE; i++)
{ {
int left = (wav.channels == 2)? wavPCM16[wavCursor*2 + 0] : wavPCM16[wavCursor]; int left = (wave.channels == 2)? wavPCM16[wavCursor*2 + 0] : wavPCM16[wavCursor];
int right = (wav.channels == 2)? wavPCM16[wavCursor*2 + 1] : left; int right = (wave.channels == 2)? wavPCM16[wavCursor*2 + 1] : left;
chunkSamples[i] = (short)((left + right)/2); chunkSamples[i] = (short)((left + right)/2);
if (++wavCursor >= wav.frameCount) wavCursor = 0; if (++wavCursor >= wave.frameCount) wavCursor = 0;
} }
UpdateAudioStream(audioStream, chunkSamples, AUDIO_STREAM_RING_BUFFER_SIZE); UpdateAudioStream(audioStream, chunkSamples, AUDIO_STREAM_RING_BUFFER_SIZE);
@ -146,8 +146,8 @@ int main(void)
} }
CaptureFrame(&fft, audioSamples); CaptureFrame(&fft, audioSamples);
RenderFrame(&fft, &fftImage); RenderFrame(&fft, &imFFT);
UpdateTexture(fftTexture, fftImage.data); UpdateTexture(texFFT, imFFT.data);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -157,8 +157,8 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginShaderMode(shader); BeginShaderMode(shader);
SetShaderValueTexture(shader, iChannel0Location, fftTexture); SetShaderValueTexture(shader, iChannel0Location, texFFT);
DrawTextureRec(bufferA.texture, DrawTextureRec(rtBufferA.texture,
(Rectangle){ 0, 0, (float)screenWidth, (float)-screenHeight }, (Rectangle){ 0, 0, (float)screenWidth, (float)-screenHeight },
(Vector2){ 0, 0 }, WHITE); (Vector2){ 0, 0 }, WHITE);
EndShaderMode(); EndShaderMode();
@ -170,11 +170,11 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); UnloadShader(shader);
UnloadRenderTexture(bufferA); UnloadRenderTexture(rtBufferA);
UnloadTexture(fftTexture); UnloadTexture(texFFT);
UnloadImage(fftImage); UnloadImage(imFFT);
UnloadAudioStream(audioStream); UnloadAudioStream(audioStream);
UnloadWave(wav); UnloadWave(wave);
CloseAudioDevice(); CloseAudioDevice();
RL_FREE(fft.spectrum); RL_FREE(fft.spectrum);

View File

@ -49,11 +49,11 @@ int main(void)
camera2.rotation = 0.0f; camera2.rotation = 0.0f;
camera2.zoom = 1.0f; camera2.zoom = 1.0f;
RenderTexture screenCamera1 = LoadRenderTexture(screenWidth/2, screenHeight); RenderTexture2D rtScreenCamera1 = LoadRenderTexture(screenWidth/2, screenHeight);
RenderTexture screenCamera2 = LoadRenderTexture(screenWidth/2, screenHeight); RenderTexture2D rtScreenCamera2 = LoadRenderTexture(screenWidth/2, screenHeight);
// Build a flipped rectangle the size of the split view to use for drawing later // Build a flipped rectangle the size of the split view to use for drawing later
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenCamera1.texture.width, (float)-screenCamera1.texture.height }; Rectangle recSplitScreen = { 0.0f, 0.0f, (float)rtScreenCamera1.texture.width, (float)-rtScreenCamera1.texture.height };
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -79,7 +79,7 @@ int main(void)
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginTextureMode(screenCamera1); BeginTextureMode(rtScreenCamera1);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode2D(camera1); BeginMode2D(camera1);
@ -112,7 +112,7 @@ int main(void)
EndTextureMode(); EndTextureMode();
BeginTextureMode(screenCamera2); BeginTextureMode(rtScreenCamera2);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode2D(camera2); BeginMode2D(camera2);
@ -150,8 +150,8 @@ int main(void)
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawTextureRec(screenCamera1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE); DrawTextureRec(rtScreenCamera1.texture, recSplitScreen, (Vector2){ 0, 0 }, WHITE);
DrawTextureRec(screenCamera2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE); DrawTextureRec(rtScreenCamera2.texture, recSplitScreen, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY); DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
EndDrawing(); EndDrawing();
@ -159,8 +159,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadRenderTexture(screenCamera1); // Unload render texture UnloadRenderTexture(rtScreenCamera1); // Unload render texture
UnloadRenderTexture(screenCamera2); // Unload render texture UnloadRenderTexture(rtScreenCamera2); // Unload render texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -37,7 +37,7 @@ int main(void)
cameraPlayer1.position.z = -3.0f; cameraPlayer1.position.z = -3.0f;
cameraPlayer1.position.y = 1.0f; cameraPlayer1.position.y = 1.0f;
RenderTexture screenPlayer1 = LoadRenderTexture(screenWidth/2, screenHeight); RenderTexture2D rtScreenPlayer1 = LoadRenderTexture(screenWidth/2, screenHeight);
// Setup player two camera and screen // Setup player two camera and screen
Camera cameraPlayer2 = { 0 }; Camera cameraPlayer2 = { 0 };
@ -47,10 +47,10 @@ int main(void)
cameraPlayer2.position.x = -3.0f; cameraPlayer2.position.x = -3.0f;
cameraPlayer2.position.y = 3.0f; cameraPlayer2.position.y = 3.0f;
RenderTexture screenPlayer2 = LoadRenderTexture(screenWidth/2, screenHeight); RenderTexture2D rtScreenPlayer2 = LoadRenderTexture(screenWidth/2, screenHeight);
// Build a flipped rectangle the size of the split view to use for drawing later // Build a flipped rectangle the size of the split view to use for drawing later
Rectangle splitScreenRect = { 0.0f, 0.0f, (float)screenPlayer1.texture.width, (float)-screenPlayer1.texture.height }; Rectangle recSplitScreen = { 0.0f, 0.0f, (float)rtScreenPlayer1.texture.width, (float)-rtScreenPlayer1.texture.height };
// Grid data // Grid data
int count = 5; int count = 5;
@ -96,7 +96,7 @@ int main(void)
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw Player1 view to the render texture // Draw Player1 view to the render texture
BeginTextureMode(screenPlayer1); BeginTextureMode(rtScreenPlayer1);
ClearBackground(SKYBLUE); ClearBackground(SKYBLUE);
BeginMode3D(cameraPlayer1); BeginMode3D(cameraPlayer1);
@ -125,7 +125,7 @@ int main(void)
EndTextureMode(); EndTextureMode();
// Draw Player2 view to the render texture // Draw Player2 view to the render texture
BeginTextureMode(screenPlayer2); BeginTextureMode(rtScreenPlayer2);
ClearBackground(SKYBLUE); ClearBackground(SKYBLUE);
BeginMode3D(cameraPlayer2); BeginMode3D(cameraPlayer2);
@ -157,8 +157,8 @@ int main(void)
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawTextureRec(screenPlayer1.texture, splitScreenRect, (Vector2){ 0, 0 }, WHITE); DrawTextureRec(rtScreenPlayer1.texture, recSplitScreen, (Vector2){ 0, 0 }, WHITE);
DrawTextureRec(screenPlayer2.texture, splitScreenRect, (Vector2){ screenWidth/2.0f, 0 }, WHITE); DrawTextureRec(rtScreenPlayer2.texture, recSplitScreen, (Vector2){ screenWidth/2.0f, 0 }, WHITE);
DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY); DrawRectangle(GetScreenWidth()/2 - 2, 0, 4, GetScreenHeight(), LIGHTGRAY);
EndDrawing(); EndDrawing();
@ -166,8 +166,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadRenderTexture(screenPlayer1); // Unload render texture UnloadRenderTexture(rtScreenPlayer1); // Unload render texture
UnloadRenderTexture(screenPlayer2); // Unload render texture UnloadRenderTexture(rtScreenPlayer2); // Unload render texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -44,9 +44,9 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
// Create a cube model // Create a cube model
Mesh cubeMesh = GenMeshCube(1.0f, 1.0f, 1.0f); // Create a unit cube mesh Mesh meshCube = GenMeshCube(1.0f, 1.0f, 1.0f); // Create a unit cube mesh
Model cubeModel = LoadModelFromMesh(cubeMesh); // Convert mesh to a model Model modelCube = LoadModelFromMesh(meshCube); // Convert mesh to a model
cubeModel.materials[0].maps[MATERIAL_MAP_DIFFUSE].color = BEIGE; modelCube.materials[0].maps[MATERIAL_MAP_DIFFUSE].color = BEIGE;
// Initialize voxel world - fill with voxels // Initialize voxel world - fill with voxels
bool voxels[WORLD_SIZE][WORLD_SIZE][WORLD_SIZE] = { false }; bool voxels[WORLD_SIZE][WORLD_SIZE][WORLD_SIZE] = { false };
@ -140,7 +140,7 @@ int main(void)
if (!voxels[x][y][z]) continue; if (!voxels[x][y][z]) continue;
Vector3 position = { (float)x, (float)y, (float)z }; Vector3 position = { (float)x, (float)y, (float)z };
DrawModel(cubeModel, position, 1.0f, BEIGE); DrawModel(modelCube, position, 1.0f, BEIGE);
DrawCubeWires(position, 1.0f, 1.0f, 1.0f, BLACK); DrawCubeWires(position, 1.0f, 1.0f, 1.0f, BLACK);
} }
} }
@ -160,7 +160,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadModel(cubeModel); UnloadModel(modelCube);
CloseWindow(); CloseWindow();
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -36,12 +36,12 @@ int main(void)
camera.fovy = 45.0f; // Camera field-of-view Y camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Texture2D bill = LoadTexture("resources/billboard.png"); // Our billboard texture Texture2D texBillboard = LoadTexture("resources/billboard.png"); // Our billboard texture
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
// Entire billboard texture, source is used to take a segment from a larger texture // Entire billboard texture, source is used to take a segment from a larger texture
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height }; Rectangle source = { 0.0f, 0.0f, (float)texBillboard.width, (float)texBillboard.height };
// NOTE: Billboard locked on axis-Y // NOTE: Billboard locked on axis-Y
Vector3 billUp = { 0.0f, 1.0f, 0.0f }; Vector3 billUp = { 0.0f, 1.0f, 0.0f };
@ -87,13 +87,13 @@ int main(void)
// Draw order matters! // Draw order matters!
if (distanceStatic > distanceRotating) if (distanceStatic > distanceRotating)
{ {
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE); DrawBillboard(camera, texBillboard, billPositionStatic, 2.0f, WHITE);
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE); DrawBillboardPro(camera, texBillboard, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
} }
else else
{ {
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE); DrawBillboardPro(camera, texBillboard, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE); DrawBillboard(camera, texBillboard, billPositionStatic, 2.0f, WHITE);
} }
EndMode3D(); EndMode3D();
@ -106,7 +106,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(bill); // Unload texture UnloadTexture(texBillboard); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -35,19 +35,19 @@ int main(void)
camera.fovy = 45.0f; // Camera field-of-view Y camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Image imCubicmap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) Texture2D texCubicmap = LoadTextureFromImage(imCubicmap); // Convert image to texture to display (VRAM)
Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f }); Mesh mesh = GenMeshCubicmap(imCubicmap, (Vector3){ 1.0f, 1.0f, 1.0f });
Model model = LoadModelFromMesh(mesh); Model model = LoadModelFromMesh(mesh);
// NOTE: By default each cube is mapped to one part of texture atlas // NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture Texture2D texAtlas = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texAtlas; // Set map diffuse texture
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM UnloadImage(imCubicmap); // Unload cubesmap image from RAM, already uploaded to VRAM
bool pause = false; // Pause camera orbital rotation (and zoom) bool pause = false; // Pause camera orbital rotation (and zoom)
@ -76,8 +76,8 @@ int main(void)
EndMode3D(); EndMode3D();
DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4.0f - 20, 20.0f }, 0.0f, 4.0f, WHITE); DrawTextureEx(texCubicmap, (Vector2){ screenWidth - texCubicmap.width*4.0f - 20, 20.0f }, 0.0f, 4.0f, WHITE);
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN); DrawRectangleLines(screenWidth - texCubicmap.width*4 - 20, 20, texCubicmap.width*4, texCubicmap.height*4, GREEN);
DrawText("cubicmap image used to", 658, 90, 10, GRAY); DrawText("cubicmap image used to", 658, 90, 10, GRAY);
DrawText("generate map 3d model", 658, 104, 10, GRAY); DrawText("generate map 3d model", 658, 104, 10, GRAY);
@ -90,8 +90,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(texCubicmap); // Unload cubicmap texture
UnloadTexture(texture); // Unload map texture UnloadTexture(texAtlas); // Unload map texture
UnloadModel(model); // Unload map model UnloadModel(model); // Unload map model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context

View File

@ -73,9 +73,9 @@ int main(void)
Model model = LoadModel("resources/models/obj/character.obj"); Model model = LoadModel("resources/models/obj/character.obj");
// Apply character skin // Apply character skin
Texture2D modelTexture = LoadTexture("resources/models/obj/character_diffuse.png"); Texture2D texture = LoadTexture("resources/models/obj/character_diffuse.png");
SetTextureFilter(modelTexture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(texture, TEXTURE_FILTER_BILINEAR);
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = modelTexture; model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
BoundingBox modelBBox = GetMeshBoundingBox(model.meshes[0]); // Get mesh bounding box BoundingBox modelBBox = GetMeshBoundingBox(model.meshes[0]); // Get mesh bounding box
@ -92,20 +92,20 @@ int main(void)
float decalSize = modelSize*0.25f; float decalSize = modelSize*0.25f;
float decalOffset = 0.01f; float decalOffset = 0.01f;
Model placementCube = LoadModelFromMesh(GenMeshCube(decalSize, decalSize, decalSize)); Model modelCube = LoadModelFromMesh(GenMeshCube(decalSize, decalSize, decalSize));
placementCube.materials[0].maps[0].color = LIME; modelCube.materials[0].maps[0].color = LIME;
Material decalMaterial = LoadMaterialDefault(); Material matDecal = LoadMaterialDefault();
decalMaterial.maps[0].color = YELLOW; matDecal.maps[0].color = YELLOW;
Image decalImage = LoadImage("resources/raylib_logo.png"); Image imDecal = LoadImage("resources/raylib_logo.png");
ImageResizeNN(&decalImage, decalImage.width/4, decalImage.height/4); ImageResizeNN(&imDecal, imDecal.width/4, imDecal.height/4);
Texture decalTexture = LoadTextureFromImage(decalImage); Texture2D texDecal = LoadTextureFromImage(imDecal);
UnloadImage(decalImage); UnloadImage(imDecal);
SetTextureFilter(decalTexture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(texDecal, TEXTURE_FILTER_BILINEAR);
decalMaterial.maps[MATERIAL_MAP_DIFFUSE].texture = decalTexture; matDecal.maps[MATERIAL_MAP_DIFFUSE].texture = texDecal;
decalMaterial.maps[MATERIAL_MAP_DIFFUSE].color = RAYWHITE; matDecal.maps[MATERIAL_MAP_DIFFUSE].color = RAYWHITE;
bool showModel = true; bool showModel = true;
static Model decalModels[MAX_DECALS] = { 0 }; static Model decalModels[MAX_DECALS] = { 0 };
@ -168,7 +168,7 @@ int main(void)
{ {
int decalIndex = decalCount++; int decalIndex = decalCount++;
decalModels[decalIndex] = LoadModelFromMesh(decalMesh); decalModels[decalIndex] = LoadModelFromMesh(decalMesh);
decalModels[decalIndex].materials[0].maps[0] = decalMaterial.maps[0]; decalModels[decalIndex].materials[0].maps[0] = matDecal.maps[0];
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -190,8 +190,8 @@ int main(void)
{ {
Vector3 origin = Vector3Add(collision.point, Vector3Scale(collision.normal, 1.0f)); Vector3 origin = Vector3Add(collision.point, Vector3Scale(collision.normal, 1.0f));
Matrix splat = MatrixLookAt(collision.point, origin, (Vector3){0,1,0}); Matrix splat = MatrixLookAt(collision.point, origin, (Vector3){0,1,0});
placementCube.transform = MatrixInvert(splat); modelCube.transform = MatrixInvert(splat);
DrawModel(placementCube, (Vector3){ 0 }, 1.0f, Fade(WHITE, 0.5f)); DrawModel(modelCube, (Vector3){ 0 }, 1.0f, Fade(WHITE, 0.5f));
} }
DrawGrid(10, 10.0f); DrawGrid(10, 10.0f);
@ -267,13 +267,13 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadModel(model); UnloadModel(model);
UnloadModel(placementCube); UnloadModel(modelCube);
UnloadTexture(modelTexture); UnloadTexture(texture);
// Unload decal models // Unload decal models
for (int i = 0; i < decalCount; i++) UnloadModel(decalModels[i]); for (int i = 0; i < decalCount; i++) UnloadModel(decalModels[i]);
UnloadTexture(decalTexture); UnloadTexture(texDecal);
FreeDecalMeshData(); // Free the data for decal generation FreeDecalMeshData(); // Free the data for decal generation

View File

@ -43,12 +43,10 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; // Projection type (Standard 3D perspective) camera.projection = CAMERA_PERSPECTIVE; // Projection type (Standard 3D perspective)
// Load billboard texture // Load billboard texture
Texture skillbot = LoadTexture("resources/skillbot.png"); Texture2D texSkillbot = LoadTexture("resources/skillbot.png");
// Timer to update animation float deltaTime = 0.0f; // Timer to update animation
float anim_timer = 0.0f; unsigned int anim = 0; // Animation frame
// Animation frame
unsigned int anim = 0;
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -61,12 +59,12 @@ int main(void)
UpdateCamera(&camera, CAMERA_ORBITAL); UpdateCamera(&camera, CAMERA_ORBITAL);
// Update timer with delta time // Update timer with delta time
anim_timer += GetFrameTime(); deltaTime += GetFrameTime();
// Update frame index after a certain amount of time (half a second) // Update frame index after a certain amount of time (half a second)
if (anim_timer > 0.5f) if (deltaTime > 0.5f)
{ {
anim_timer = 0.0f; deltaTime = 0.0f;
anim += 1; anim += 1;
} }
@ -74,33 +72,31 @@ int main(void)
if (anim >= 4) anim = 0; if (anim >= 4) anim = 0;
// Find the current direction frame based on the camera position to the billboard object // Find the current direction frame based on the camera position to the billboard object
float dir = (float)floor(((Vector2Angle((Vector2){ 2.0f, 0.0f }, (Vector2){ camera.position.x, camera.position.z })/PI)*4.0f) + 0.25f); float direction = (float)floor(((Vector2Angle((Vector2){ 2.0f, 0.0f },
(Vector2){ camera.position.x, camera.position.z })/PI)*4.0f) + 0.25f);
// Correct frame index if angle is negative // Correct frame index if angle is negative
if (dir < 0.0f) if (direction < 0.0f) direction = 8.0f - (float)abs((int)direction);
{
dir = 8.0f - (float)abs((int)dir);
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera); BeginMode3D(camera);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
// Draw billboard pointing straight up to the sky, rotated relative to the camera and offset from the bottom // Draw billboard pointing straight up to the sky, rotated relative to the camera and offset from the bottom
DrawBillboardPro(camera, skillbot, (Rectangle){ 0.0f + (anim*24.0f), 0.0f + (dir*24.0f), 24.0f, 24.0f }, Vector3Zero(), (Vector3){ 0.0f, 1.0f, 0.0f }, Vector2One(), (Vector2){ 0.5f, 0.0f }, 0, WHITE); DrawBillboardPro(camera, texSkillbot, (Rectangle){ 0.0f + (anim*24.0f), 0.0f + (direction*24.0f), 24.0f, 24.0f }, Vector3Zero(), (Vector3){ 0.0f, 1.0f, 0.0f }, Vector2One(), (Vector2){ 0.5f, 0.0f }, 0, WHITE);
EndMode3D(); EndMode3D();
// Render various variables for reference // Render various variables for reference
DrawText(TextFormat("animation: %d", anim), 10, 10, 20, DARKGRAY); DrawText(TextFormat("animation: %d", anim), 10, 10, 20, DARKGRAY);
DrawText(TextFormat("direction frame: %.0f", dir), 10, 40, 20, DARKGRAY); DrawText(TextFormat("direction frame: %.0f", direction), 10, 40, 20, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -109,7 +105,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Unload billboard texture // Unload billboard texture
UnloadTexture(skillbot); UnloadTexture(texSkillbot);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -37,18 +37,18 @@ int main(void)
camera.fovy = 45.0f; // Camera field-of-view Y camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Image imMap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Image imCubicmap = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(imMap); // Convert image to texture to display (VRAM) Texture2D texCubicmap = LoadTextureFromImage(imCubicmap); // Convert image to texture to display (VRAM)
Mesh mesh = GenMeshCubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f }); Mesh mesh = GenMeshCubicmap(imCubicmap, (Vector3){ 1.0f, 1.0f, 1.0f });
Model model = LoadModelFromMesh(mesh); Model model = LoadModelFromMesh(mesh);
// NOTE: By default each cube is mapped to one part of texture atlas // NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture Texture2D texAtlas = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texAtlas; // Set map diffuse texture
// Get map image data to be used for collision detection // Get map image data to be used for collision detection
Color *mapPixels = LoadImageColors(imMap); Color *mapPixels = LoadImageColors(imCubicmap);
UnloadImage(imMap); // Unload image from RAM UnloadImage(imCubicmap); // Unload image from RAM
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
@ -75,22 +75,22 @@ int main(void)
// Out-of-limits security check // Out-of-limits security check
if (playerCellX < 0) playerCellX = 0; if (playerCellX < 0) playerCellX = 0;
else if (playerCellX >= cubicmap.width) playerCellX = cubicmap.width - 1; else if (playerCellX >= texCubicmap.width) playerCellX = texCubicmap.width - 1;
if (playerCellY < 0) playerCellY = 0; if (playerCellY < 0) playerCellY = 0;
else if (playerCellY >= cubicmap.height) playerCellY = cubicmap.height - 1; else if (playerCellY >= texCubicmap.height) playerCellY = texCubicmap.height - 1;
// Check map collisions using image data and player position against surrounding cells only // Check map collisions using image data and player position against surrounding cells only
for (int y = playerCellY - 1; y <= playerCellY + 1; y++) for (int y = playerCellY - 1; y <= playerCellY + 1; y++)
{ {
// Avoid map accessing out of bounds // Avoid map accessing out of bounds
if ((y >= 0) && (y < cubicmap.height)) if ((y >= 0) && (y < texCubicmap.height))
{ {
for (int x = playerCellX - 1; x <= playerCellX + 1; x++) for (int x = playerCellX - 1; x <= playerCellX + 1; x++)
{ {
// NOTE: Collision: Only checking R channel for white pixel // NOTE: Collision: Only checking R channel for white pixel
if (((x >= 0) && (x < cubicmap.width)) && if (((x >= 0) && (x < texCubicmap.width)) &&
(mapPixels[y*cubicmap.width + x].r == 255) && (mapPixels[y*texCubicmap.width + x].r == 255) &&
(CheckCollisionCircleRec(playerPos, playerRadius, (CheckCollisionCircleRec(playerPos, playerRadius,
(Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f }))) (Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f })))
{ {
@ -112,11 +112,11 @@ int main(void)
DrawModel(model, mapPosition, 1.0f, WHITE); // Draw maze map DrawModel(model, mapPosition, 1.0f, WHITE); // Draw maze map
EndMode3D(); EndMode3D();
DrawTextureEx(cubicmap, (Vector2){ GetScreenWidth() - cubicmap.width*4.0f - 20, 20.0f }, 0.0f, 4.0f, WHITE); DrawTextureEx(texCubicmap, (Vector2){ GetScreenWidth() - texCubicmap.width*4.0f - 20, 20.0f }, 0.0f, 4.0f, WHITE);
DrawRectangleLines(GetScreenWidth() - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN); DrawRectangleLines(GetScreenWidth() - texCubicmap.width*4 - 20, 20, texCubicmap.width*4, texCubicmap.height*4, GREEN);
// Draw player position radar // Draw player position radar
DrawRectangle(GetScreenWidth() - cubicmap.width*4 - 20 + playerCellX*4, 20 + playerCellY*4, 4, 4, RED); DrawRectangle(GetScreenWidth() - texCubicmap.width*4 - 20 + playerCellX*4, 20 + playerCellY*4, 4, 4, RED);
DrawFPS(10, 10); DrawFPS(10, 10);
@ -128,8 +128,8 @@ int main(void)
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadImageColors(mapPixels); // Unload color array UnloadImageColors(mapPixels); // Unload color array
UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(texCubicmap); // Unload cubicmap texture
UnloadTexture(texture); // Unload map texture UnloadTexture(texAtlas); // Unload map texture
UnloadModel(model); // Unload map model UnloadModel(model); // Unload map model
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context

View File

@ -67,14 +67,14 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; camera.projection = CAMERA_PERSPECTIVE;
// CPU-side canvas plus the GPU texture it gets pushed to after every stroke // CPU-side canvas plus the GPU texture it gets pushed to after every stroke
Image canvasImage = GenImageColor(CANVAS_SIZE, CANVAS_SIZE, RAYWHITE); Image imCanvas = GenImageColor(CANVAS_SIZE, CANVAS_SIZE, RAYWHITE);
Texture2D canvasTexture = LoadTextureFromImage(canvasImage); Texture2D texCanvas = LoadTextureFromImage(imCanvas);
SetTextureFilter(canvasTexture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(texCanvas, TEXTURE_FILTER_BILINEAR);
Model model = { 0 }; Model model = { 0 };
BoundingBox modelBBox = { 0 }; BoundingBox modelBBox = { 0 };
ShapeType currentShape = SHAPE_SPHERE; ShapeType currentShape = SHAPE_SPHERE;
ChangeShape(&model, &modelBBox, &currentShape, SHAPE_SPHERE, canvasTexture); ChangeShape(&model, &modelBBox, &currentShape, SHAPE_SPHERE, texCanvas);
ToolMode currentTool = TOOL_PAINT; ToolMode currentTool = TOOL_PAINT;
Color activeColor = RED; Color activeColor = RED;
@ -121,19 +121,19 @@ int main(void)
for (int i = 0; i <= steps; i++) for (int i = 0; i <= steps; i++)
{ {
float t = (float)i / (float)steps; float t = (float)i / (float)steps;
ImageDrawCircle(&canvasImage, (int)Lerp((float)lastPx, (float)px, t), ImageDrawCircle(&imCanvas, (int)Lerp((float)lastPx, (float)px, t),
(int)Lerp((float)lastPy, (float)py, t), brushRadius, activeColor); (int)Lerp((float)lastPy, (float)py, t), brushRadius, activeColor);
} }
} }
else ImageDrawCircle(&canvasImage, px, py, brushRadius, activeColor); else ImageDrawCircle(&imCanvas, px, py, brushRadius, activeColor);
UpdateTexture(canvasTexture, canvasImage.data); UpdateTexture(texCanvas, imCanvas.data);
lastHitUV = hitUV; lastHitUV = hitUV;
hasLastHit = true; hasLastHit = true;
} }
else else
{ {
activeColor = GetImageColor(canvasImage, px, py); activeColor = GetImageColor(imCanvas, px, py);
currentTool = TOOL_PAINT; currentTool = TOOL_PAINT;
hasLastHit = false; hasLastHit = false;
} }
@ -173,13 +173,13 @@ int main(void)
bool torusActive = (currentShape == SHAPE_TORUS); bool torusActive = (currentShape == SHAPE_TORUS);
if (GuiToggle((Rectangle){ 25, 120, 95, 28 }, "SPHERE", &sphereActive)) if (GuiToggle((Rectangle){ 25, 120, 95, 28 }, "SPHERE", &sphereActive))
ChangeShape(&model, &modelBBox, &currentShape, SHAPE_SPHERE, canvasTexture); ChangeShape(&model, &modelBBox, &currentShape, SHAPE_SPHERE, texCanvas);
if (GuiToggle((Rectangle){ 125, 120, 95, 28 }, "CUBE", &cubeActive)) if (GuiToggle((Rectangle){ 125, 120, 95, 28 }, "CUBE", &cubeActive))
ChangeShape(&model, &modelBBox, &currentShape, SHAPE_CUBE, canvasTexture); ChangeShape(&model, &modelBBox, &currentShape, SHAPE_CUBE, texCanvas);
if (GuiToggle((Rectangle){ 25, 153, 95, 28 }, "CYLINDER", &cylinderActive)) if (GuiToggle((Rectangle){ 25, 153, 95, 28 }, "CYLINDER", &cylinderActive))
ChangeShape(&model, &modelBBox, &currentShape, SHAPE_CYLINDER, canvasTexture); ChangeShape(&model, &modelBBox, &currentShape, SHAPE_CYLINDER, texCanvas);
if (GuiToggle((Rectangle){ 125, 153, 95, 28 }, "TORUS", &torusActive)) if (GuiToggle((Rectangle){ 125, 153, 95, 28 }, "TORUS", &torusActive))
ChangeShape(&model, &modelBBox, &currentShape, SHAPE_TORUS, canvasTexture); ChangeShape(&model, &modelBBox, &currentShape, SHAPE_TORUS, texCanvas);
// Color display // Color display
DrawText("Active Color:", 25, 195, 10, LIGHTGRAY); DrawText("Active Color:", 25, 195, 10, LIGHTGRAY);
@ -204,13 +204,13 @@ int main(void)
// Canvas action buttons // Canvas action buttons
if (GuiButton((Rectangle){ 25, 410, 95, 30 }, "CLEAR")) if (GuiButton((Rectangle){ 25, 410, 95, 30 }, "CLEAR"))
{ {
ImageClearBackground(&canvasImage, RAYWHITE); ImageClearBackground(&imCanvas, RAYWHITE);
UpdateTexture(canvasTexture, canvasImage.data); UpdateTexture(texCanvas, imCanvas.data);
} }
if (GuiButton((Rectangle){ 125, 410, 95, 30 }, "FILL")) if (GuiButton((Rectangle){ 125, 410, 95, 30 }, "FILL"))
{ {
ImageClearBackground(&canvasImage, activeColor); ImageClearBackground(&imCanvas, activeColor);
UpdateTexture(canvasTexture, canvasImage.data); UpdateTexture(texCanvas, imCanvas.data);
} }
DrawText("Left click: paint / pick color | Right drag: orbit camera", 260, screenHeight - 25, 10, RAYWHITE); DrawText("Left click: paint / pick color | Right drag: orbit camera", 260, screenHeight - 25, 10, RAYWHITE);
@ -223,8 +223,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadModel(model); UnloadModel(model);
UnloadImage(canvasImage); UnloadImage(imCanvas);
UnloadTexture(canvasTexture); UnloadTexture(texCanvas);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -24,8 +24,10 @@
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#define RAYGUI_IMPLEMENTATION #define RAYGUI_IMPLEMENTATION
#include "raygui.h" #include "raygui.h"
#include "raymath.h" #include "raymath.h"
#include <stddef.h> // Required for: NULL #include <stddef.h> // Required for: NULL
@ -81,11 +83,11 @@ int main(void)
// Target model: a procedurally generated knot with a checkerboard skin // Target model: a procedurally generated knot with a checkerboard skin
Model model = LoadModelFromMesh(GenMeshTorus(0.8f, 1.8f, 32, 64)); Model model = LoadModelFromMesh(GenMeshTorus(0.8f, 1.8f, 32, 64));
Image checkerImage = GenImageChecked(512, 512, 32, 32, LIGHTGRAY, GRAY); Image imChecker = GenImageChecked(512, 512, 32, 32, LIGHTGRAY, GRAY);
Texture2D modelTexture = LoadTextureFromImage(checkerImage); Texture2D texChecker = LoadTextureFromImage(imChecker);
UnloadImage(checkerImage); UnloadImage(imChecker);
SetTextureFilter(modelTexture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(texChecker, TEXTURE_FILTER_BILINEAR);
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = modelTexture; model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texChecker;
BoundingBox modelBBox = GetMeshBoundingBox(model.meshes[0]); BoundingBox modelBBox = GetMeshBoundingBox(model.meshes[0]);
camera.target = Vector3Lerp(modelBBox.min, modelBBox.max, 0.5f); camera.target = Vector3Lerp(modelBBox.min, modelBBox.max, 0.5f);
@ -97,26 +99,26 @@ int main(void)
float decalOffset = 0.01f; float decalOffset = 0.01f;
// Translucent cube previewing where the next decal will land // Translucent cube previewing where the next decal will land
Model placementCube = LoadModelFromMesh(GenMeshCube(decalSize, decalSize, decalSize)); Model modelPlacementCube = LoadModelFromMesh(GenMeshCube(decalSize, decalSize, decalSize));
placementCube.materials[0].maps[0].color = LIME; modelPlacementCube.materials[0].maps[0].color = LIME;
// Decal texture: a procedurally drawn target/bullseye, no image file needed // Decal texture: a procedurally drawn target/bullseye, no image file needed
Image decalImage = GenImageColor(128, 128, BLANK); Image imDecal = GenImageColor(128, 128, BLANK);
ImageDrawCircle(&decalImage, 64, 64, 60, RED); ImageDrawCircle(&imDecal, 64, 64, 60, RED);
ImageDrawCircle(&decalImage, 64, 64, 45, WHITE); ImageDrawCircle(&imDecal, 64, 64, 45, WHITE);
ImageDrawCircle(&decalImage, 64, 64, 30, RED); ImageDrawCircle(&imDecal, 64, 64, 30, RED);
ImageDrawCircle(&decalImage, 64, 64, 15, YELLOW); ImageDrawCircle(&imDecal, 64, 64, 15, YELLOW);
Texture2D decalTexture = LoadTextureFromImage(decalImage); Texture2D texDecal = LoadTextureFromImage(imDecal);
UnloadImage(decalImage); UnloadImage(imDecal);
SetTextureFilter(decalTexture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(texDecal, TEXTURE_FILTER_BILINEAR);
Material decalMaterial = LoadMaterialDefault(); Material matDecal = LoadMaterialDefault();
decalMaterial.maps[MATERIAL_MAP_DIFFUSE].texture = decalTexture; matDecal.maps[MATERIAL_MAP_DIFFUSE].texture = texDecal;
decalMaterial.maps[MATERIAL_MAP_DIFFUSE].color = RAYWHITE; matDecal.maps[MATERIAL_MAP_DIFFUSE].color = RAYWHITE;
bool showModel = true; bool showModel = true;
Model decals[MAX_DECALS] = { 0 }; Model modelDecals[MAX_DECALS] = { 0 };
int decalCount = 0; int decalCount = 0;
SetTargetFPS(60); SetTargetFPS(60);
@ -149,12 +151,12 @@ int main(void)
Matrix splat = MatrixLookAt(collision.point, lookTarget, (Vector3){ 0.0f, 1.0f, 0.0f }); Matrix splat = MatrixLookAt(collision.point, lookTarget, (Vector3){ 0.0f, 1.0f, 0.0f });
splat = MatrixMultiply(splat, MatrixRotateZ(DEG2RAD*(float)GetRandomValue(-180, 180))); splat = MatrixMultiply(splat, MatrixRotateZ(DEG2RAD*(float)GetRandomValue(-180, 180)));
Mesh decalMesh = GenMeshDecal(model, splat, decalSize, decalOffset); Mesh meshDecal = GenMeshDecal(model, splat, decalSize, decalOffset);
if (decalMesh.vertexCount > 0) if (meshDecal.vertexCount > 0)
{ {
decals[decalCount] = LoadModelFromMesh(decalMesh); modelDecals[decalCount] = LoadModelFromMesh(meshDecal);
decals[decalCount].materials[0].maps[0] = decalMaterial.maps[0]; modelDecals[decalCount].materials[0].maps[0] = matDecal.maps[0];
decalCount++; decalCount++;
} }
} }
@ -170,15 +172,15 @@ int main(void)
if (showModel) DrawModel(model, Vector3Zero(), 1.0f, WHITE); if (showModel) DrawModel(model, Vector3Zero(), 1.0f, WHITE);
for (int i = 0; i < decalCount; i++) DrawModel(decals[i], Vector3Zero(), 1.0f, WHITE); for (int i = 0; i < decalCount; i++) DrawModel(modelDecals[i], Vector3Zero(), 1.0f, WHITE);
// Preview cube at the surface point currently under the mouse // Preview cube at the surface point currently under the mouse
if (collision.hit) if (collision.hit)
{ {
Vector3 lookTarget = Vector3Add(collision.point, collision.normal); Vector3 lookTarget = Vector3Add(collision.point, collision.normal);
Matrix splat = MatrixLookAt(collision.point, lookTarget, (Vector3){ 0.0f, 1.0f, 0.0f }); Matrix splat = MatrixLookAt(collision.point, lookTarget, (Vector3){ 0.0f, 1.0f, 0.0f });
placementCube.transform = MatrixInvert(splat); modelPlacementCube.transform = MatrixInvert(splat);
DrawModel(placementCube, Vector3Zero(), 1.0f, Fade(WHITE, 0.5f)); DrawModel(modelPlacementCube, Vector3Zero(), 1.0f, Fade(WHITE, 0.5f));
} }
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
@ -196,8 +198,8 @@ int main(void)
int totalVertices = baseVertices, totalTriangles = baseTriangles; int totalVertices = baseVertices, totalTriangles = baseTriangles;
for (int i = 0; i < decalCount; i++) for (int i = 0; i < decalCount; i++)
{ {
totalVertices += decals[i].meshes[0].vertexCount; totalVertices += modelDecals[i].meshes[0].vertexCount;
totalTriangles += decals[i].meshes[0].triangleCount; totalTriangles += modelDecals[i].meshes[0].triangleCount;
} }
int statX = screenWidth - 280; int statX = screenWidth - 280;
@ -215,7 +217,7 @@ int main(void)
if (GuiButton((Rectangle){ 120, screenHeight - 80.0f, 100, 40 }, "Clear Decals")) if (GuiButton((Rectangle){ 120, screenHeight - 80.0f, 100, 40 }, "Clear Decals"))
{ {
for (int i = 0; i < decalCount; i++) UnloadModel(decals[i]); for (int i = 0; i < decalCount; i++) UnloadModel(modelDecals[i]);
decalCount = 0; decalCount = 0;
} }
@ -228,11 +230,11 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
for (int i = 0; i < decalCount; i++) UnloadModel(decals[i]); for (int i = 0; i < decalCount; i++) UnloadModel(modelDecals[i]);
UnloadModel(placementCube); UnloadModel(modelPlacementCube);
UnloadTexture(decalTexture); UnloadTexture(texDecal);
UnloadTexture(modelTexture); UnloadTexture(texChecker);
UnloadModel(model); UnloadModel(model);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context

View File

@ -51,8 +51,8 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
// Load skybox model // Load skybox model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); Mesh mesh = GenMeshCube(1.0f, 1.0f, 1.0f);
Model skybox = LoadModelFromMesh(cube); Model modelSkybox = LoadModelFromMesh(mesh);
// Set this to true to use an HDR Texture // Set this to true to use an HDR Texture
// NOTE: raylib must be built with HDR Support for this to work: SUPPORT_FILEFORMAT_HDR // NOTE: raylib must be built with HDR Support for this to work: SUPPORT_FILEFORMAT_HDR
@ -60,12 +60,12 @@ int main(void)
// Load skybox shader and set required locations // Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading // NOTE: Some locations are automatically set at shader loading
skybox.materials[0].shader = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION), modelSkybox.materials[0].shader = LoadShader(TextFormat("resources/shaders/glsl%i/skybox.vs", GLSL_VERSION),
TextFormat("resources/shaders/glsl%i/skybox.fs", GLSL_VERSION)); TextFormat("resources/shaders/glsl%i/skybox.fs", GLSL_VERSION));
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "environmentMap"), (int[1]){ MATERIAL_MAP_CUBEMAP }, SHADER_UNIFORM_INT); SetShaderValue(modelSkybox.materials[0].shader, GetShaderLocation(modelSkybox.materials[0].shader, "environmentMap"), (int[1]){ MATERIAL_MAP_CUBEMAP }, SHADER_UNIFORM_INT);
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "doGamma"), (int[1]){ useHDR? 1 : 0 }, SHADER_UNIFORM_INT); SetShaderValue(modelSkybox.materials[0].shader, GetShaderLocation(modelSkybox.materials[0].shader, "doGamma"), (int[1]){ useHDR? 1 : 0 }, SHADER_UNIFORM_INT);
SetShaderValue(skybox.materials[0].shader, GetShaderLocation(skybox.materials[0].shader, "vflipped"), (int[1]){ useHDR? 1 : 0 }, SHADER_UNIFORM_INT); SetShaderValue(modelSkybox.materials[0].shader, GetShaderLocation(modelSkybox.materials[0].shader, "vflipped"), (int[1]){ useHDR? 1 : 0 }, SHADER_UNIFORM_INT);
// Load cubemap shader and setup required shader locations // Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION), Shader shdrCubemap = LoadShader(TextFormat("resources/shaders/glsl%i/cubemap.vs", GLSL_VERSION),
@ -80,23 +80,23 @@ int main(void)
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr"); TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
// Load HDR panorama (sphere) texture // Load HDR panorama (sphere) texture
Texture2D panorama = LoadTexture(skyboxFileName); Texture2D texPanorama = LoadTexture(skyboxFileName);
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
// NOTE 1: New texture is generated rendering to texture, shader calculates the sphere->cube coordinates mapping // NOTE 1: New texture is generated rendering to texture, shader calculates the sphere->cube coordinates mapping
// NOTE 2: It seems on some Android devices WebGL, fbo does not properly support a FLOAT-based attachment, // NOTE 2: It seems on some Android devices WebGL, fbo does not properly support a FLOAT-based attachment,
// despite texture can be successfully created.. so using PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 instead of PIXELFORMAT_UNCOMPRESSED_R32G32B32A32 // despite texture can be successfully created.. so using PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 instead of PIXELFORMAT_UNCOMPRESSED_R32G32B32A32
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); modelSkybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texPanorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated UnloadTexture(texPanorama); // Texture not required anymore, cubemap already generated
} }
else else
{ {
// TODO: WARNING: On PLATFORM_WEB it requires a big amount of memory to process input image // TODO: WARNING: On PLATFORM_WEB it requires a big amount of memory to process input image
// and generate the required cubemap image to be passed to rlLoadTextureCubemap() // and generate the required cubemap image to be passed to rlLoadTextureCubemap()
Image image = LoadImage("resources/skybox.png"); Image imSkybox = LoadImage("resources/skybox.png");
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(image, CUBEMAP_LAYOUT_AUTO_DETECT); modelSkybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(imSkybox, CUBEMAP_LAYOUT_AUTO_DETECT);
UnloadImage(image); UnloadImage(imSkybox);
} }
DisableCursor(); // Limit cursor to relative movement inside the window DisableCursor(); // Limit cursor to relative movement inside the window
@ -121,7 +121,7 @@ int main(void)
if (IsFileExtension(droppedFiles.paths[0], ".png;.jpg;.hdr;.bmp;.tga")) if (IsFileExtension(droppedFiles.paths[0], ".png;.jpg;.hdr;.bmp;.tga"))
{ {
// Unload current cubemap texture to load new one // Unload current cubemap texture to load new one
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture); UnloadTexture(modelSkybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
if (useHDR) if (useHDR)
{ {
@ -129,14 +129,14 @@ int main(void)
Texture2D panorama = LoadTexture(droppedFiles.paths[0]); Texture2D panorama = LoadTexture(droppedFiles.paths[0]);
// Generate cubemap from panorama texture // Generate cubemap from panorama texture
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); modelSkybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
} }
else else
{ {
Image image = LoadImage(droppedFiles.paths[0]); Image image = LoadImage(droppedFiles.paths[0]);
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(image, CUBEMAP_LAYOUT_AUTO_DETECT); modelSkybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(image, CUBEMAP_LAYOUT_AUTO_DETECT);
UnloadImage(image); UnloadImage(image);
} }
@ -159,7 +159,7 @@ int main(void)
// We are inside the cube, we need to disable backface culling! // We are inside the cube, we need to disable backface culling!
rlDisableBackfaceCulling(); rlDisableBackfaceCulling();
rlDisableDepthMask(); rlDisableDepthMask();
DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); DrawModel(modelSkybox, (Vector3){0, 0, 0}, 1.0f, WHITE);
rlEnableBackfaceCulling(); rlEnableBackfaceCulling();
rlEnableDepthMask(); rlEnableDepthMask();
@ -178,9 +178,9 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(skybox.materials[0].shader); UnloadShader(modelSkybox.materials[0].shader);
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture); UnloadTexture(modelSkybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
UnloadModel(skybox); // Unload skybox model UnloadModel(modelSkybox); // Unload skybox model
UnloadShader(shdrCubemap); UnloadShader(shdrCubemap);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context

View File

@ -35,10 +35,9 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - ascii rendering"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - ascii rendering");
// Texture to test static drawing // Load required textures
Texture2D fudesumi = LoadTexture("resources/fudesumi.png"); Texture2D texFudesumi = LoadTexture("resources/fudesumi.png");
// Texture to test moving drawing Texture2D texRaysan = LoadTexture("resources/raysan.png");
Texture2D raysan = LoadTexture("resources/raysan.png");
// Load shader to be used on postprocessing // Load shader to be used on postprocessing
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/ascii.fs", GLSL_VERSION)); Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/ascii.fs", GLSL_VERSION));
@ -84,8 +83,8 @@ int main(void)
ClearBackground(WHITE); ClearBackground(WHITE);
// Draw scene in our render texture // Draw scene in our render texture
DrawTexture(fudesumi, 500, -30, WHITE); DrawTexture(texFudesumi, 500, -30, WHITE);
DrawTextureV(raysan, circlePos, WHITE); DrawTextureV(texRaysan, circlePos, WHITE);
EndTextureMode(); EndTextureMode();
BeginDrawing(); BeginDrawing();
@ -111,8 +110,8 @@ int main(void)
UnloadRenderTexture(target); // Unload render texture UnloadRenderTexture(target); // Unload render texture
UnloadShader(shader); // Unload shader UnloadShader(shader); // Unload shader
UnloadTexture(fudesumi); // Unload texture UnloadTexture(texFudesumi); // Unload texture
UnloadTexture(raysan); // Unload texture UnloadTexture(texRaysan); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -43,7 +43,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color correction"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color correction");
Texture2D texture[MAX_TEXTURES] = { Texture2D textures[MAX_TEXTURES] = {
LoadTexture("resources/parrots.png"), LoadTexture("resources/parrots.png"),
LoadTexture("resources/cat.png"), LoadTexture("resources/cat.png"),
LoadTexture("resources/mandrill.png"), LoadTexture("resources/mandrill.png"),
@ -105,7 +105,7 @@ int main(void)
BeginShaderMode(shdrColorCorrection); BeginShaderMode(shdrColorCorrection);
DrawTexture(texture[imageIndex], 580/2 - texture[imageIndex].width/2, GetScreenHeight()/2 - texture[imageIndex].height/2, WHITE); DrawTexture(textures[imageIndex], 580/2 - textures[imageIndex].width/2, GetScreenHeight()/2 - textures[imageIndex].height/2, WHITE);
EndShaderMode(); EndShaderMode();
@ -138,7 +138,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
for (int i = 0; i < MAX_TEXTURES; i++) UnloadTexture(texture[i]); for (int i = 0; i < MAX_TEXTURES; i++) UnloadTexture(textures[i]);
UnloadShader(shdrColorCorrection); UnloadShader(shdrColorCorrection);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context

View File

@ -58,7 +58,7 @@ int main(void)
Model modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32)); Model modelA = LoadModelFromMesh(GenMeshTorus(0.4f, 1.0f, 16, 32));
Model modelB = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f)); Model modelB = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
Model modelC = LoadModelFromMesh(GenMeshSphere(0.5f, 32, 32)); Model modelC = LoadModelFromMesh(GenMeshSphere(0.5f, 32, 32));
Texture texture = LoadTexture("resources/texel_checker.png"); Texture2D texture = LoadTexture("resources/texel_checker.png");
// Assign texture to default model material // Assign texture to default model material
modelA.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; modelA.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;

View File

@ -106,22 +106,22 @@ int main(void)
SetShaderValue(shdrGameOfLife, resolutionLoc, resolution, SHADER_UNIFORM_VEC2); SetShaderValue(shdrGameOfLife, resolutionLoc, resolution, SHADER_UNIFORM_VEC2);
// Define two textures: the current world and the previous world // Define two textures: the current world and the previous world
RenderTexture2D world1 = LoadRenderTexture(worldWidth, worldHeight); RenderTexture2D rtWorld1 = LoadRenderTexture(worldWidth, worldHeight);
RenderTexture2D world2 = LoadRenderTexture(worldWidth, worldHeight); RenderTexture2D rtWorld2 = LoadRenderTexture(worldWidth, worldHeight);
BeginTextureMode(world2); BeginTextureMode(rtWorld2);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
EndTextureMode(); EndTextureMode();
Image startPattern = LoadImage("resources/game_of_life/r_pentomino.png"); Image imPentomino = LoadImage("resources/game_of_life/r_pentomino.png");
UpdateTextureRec(world2.texture, (Rectangle){ worldWidth/2.0f, worldHeight/2.0f, (float)(startPattern.width), (float)(startPattern.height) }, startPattern.data); UpdateTextureRec(rtWorld2.texture, (Rectangle){ worldWidth/2.0f, worldHeight/2.0f, (float)(imPentomino.width), (float)(imPentomino.height) }, imPentomino.data);
UnloadImage(startPattern); UnloadImage(imPentomino);
// Pointers to the two textures, to be swapped // Pointers to the two textures, to be swapped
RenderTexture2D *currentWorld = &world2; RenderTexture2D *rtWorldCurrentPtr = &rtWorld2;
RenderTexture2D *previousWorld = &world1; RenderTexture2D *rtWorldPreviousPtr = &rtWorld1;
// Image to be used in DRAW mode, to be changed with mouse input // Image to be used in DRAW mode, to be changed with mouse input
Image *imageToDraw = NULL; Image *imToDrawPtr = NULL;
SetTargetFPS(60); // Set at 60 frames-per-second SetTargetFPS(60); // Set at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -137,7 +137,7 @@ int main(void)
float mouseWheelMove = GetMouseWheelMove(); float mouseWheelMove = GetMouseWheelMove();
if (buttonZoomIn || (buttonZomOut && (zoom > 1)) || (mouseWheelMove != 0.0f)) if (buttonZoomIn || (buttonZomOut && (zoom > 1)) || (mouseWheelMove != 0.0f))
{ {
FreeImageToDraw(&imageToDraw); // Zoom change: free the image to draw to be recreated again FreeImageToDraw(&imToDrawPtr); // Zoom change: free the image to draw to be recreated again
const float centerX = offsetX + (windowWidth/2.0f)/zoom; const float centerX = offsetX + (windowWidth/2.0f)/zoom;
const float centerY = offsetY + (windowHeight/2.0f)/zoom; const float centerY = offsetY + (windowHeight/2.0f)/zoom;
@ -154,7 +154,7 @@ int main(void)
// Mouse management // Mouse management
if ((mode == MODE_RUN) || (mode == MODE_PAUSE)) if ((mode == MODE_RUN) || (mode == MODE_PAUSE))
{ {
FreeImageToDraw(&imageToDraw); // Free the image to draw: no longer needed in these modes FreeImageToDraw(&imToDrawPtr); // Free the image to draw: no longer needed in these modes
// Pan with mouse left button // Pan with mouse left button
static Vector2 previousMousePosition = { 0.0f, 0.0f }; static Vector2 previousMousePosition = { 0.0f, 0.0f };
@ -176,15 +176,15 @@ int main(void)
if (offsetY + sizeInWorldY >= worldHeight) sizeInWorldY = worldHeight - (int)floorf(offsetY); if (offsetY + sizeInWorldY >= worldHeight) sizeInWorldY = worldHeight - (int)floorf(offsetY);
// Create image to draw if not created yet // Create image to draw if not created yet
if (imageToDraw == NULL) if (imToDrawPtr == NULL)
{ {
RenderTexture2D worldOnScreen = LoadRenderTexture(sizeInWorldX, sizeInWorldY); RenderTexture2D worldOnScreen = LoadRenderTexture(sizeInWorldX, sizeInWorldY);
BeginTextureMode(worldOnScreen); BeginTextureMode(worldOnScreen);
DrawTexturePro(currentWorld->texture, (Rectangle) { floorf(offsetX), floorf(offsetY), (float)(sizeInWorldX), -(float)(sizeInWorldY) }, DrawTexturePro(rtWorldCurrentPtr->texture, (Rectangle) { floorf(offsetX), floorf(offsetY), (float)(sizeInWorldX), -(float)(sizeInWorldY) },
(Rectangle) { 0, 0, (float)(sizeInWorldX), (float)(sizeInWorldY) }, (Vector2) { 0, 0 }, 0.0f, WHITE); (Rectangle) { 0, 0, (float)(sizeInWorldX), (float)(sizeInWorldY) }, (Vector2) { 0, 0 }, 0.0f, WHITE);
EndTextureMode(); EndTextureMode();
imageToDraw = (Image*)RL_MALLOC(sizeof(Image)); imToDrawPtr = (Image*)RL_MALLOC(sizeof(Image));
*imageToDraw = LoadImageFromTexture(worldOnScreen.texture); *imToDrawPtr = LoadImageFromTexture(worldOnScreen.texture);
UnloadRenderTexture(worldOnScreen); UnloadRenderTexture(worldOnScreen);
} }
@ -197,12 +197,12 @@ int main(void)
int mouseY = (int)(mousePosition.y + offsetDecimalY*zoom)/zoom; int mouseY = (int)(mousePosition.y + offsetDecimalY*zoom)/zoom;
if (mouseX >= sizeInWorldX) mouseX = sizeInWorldX - 1; if (mouseX >= sizeInWorldX) mouseX = sizeInWorldX - 1;
if (mouseY >= sizeInWorldY) mouseY = sizeInWorldY - 1; if (mouseY >= sizeInWorldY) mouseY = sizeInWorldY - 1;
if (firstColor == -1) firstColor = (GetImageColor(*imageToDraw, mouseX, mouseY).r < 5)? 0 : 1; if (firstColor == -1) firstColor = (GetImageColor(*imToDrawPtr, mouseX, mouseY).r < 5)? 0 : 1;
const int prevColor = (GetImageColor(*imageToDraw, mouseX, mouseY).r < 5)? 0 : 1; const int prevColor = (GetImageColor(*imToDrawPtr, mouseX, mouseY).r < 5)? 0 : 1;
ImageDrawPixel(imageToDraw, mouseX, mouseY, (firstColor) ? BLACK : RAYWHITE); ImageDrawPixel(imToDrawPtr, mouseX, mouseY, (firstColor) ? BLACK : RAYWHITE);
if (prevColor != firstColor) UpdateTextureRec(currentWorld->texture, (Rectangle){ floorf(offsetX), floorf(offsetY), (float)(sizeInWorldX), (float)(sizeInWorldY) }, imageToDraw->data); if (prevColor != firstColor) UpdateTextureRec(rtWorldCurrentPtr->texture, (Rectangle){ floorf(offsetX), floorf(offsetY), (float)(sizeInWorldX), (float)(sizeInWorldY) }, imToDrawPtr->data);
} }
else firstColor = -1; else firstColor = -1;
} }
@ -225,11 +225,11 @@ int main(void)
case 7: pattern = LoadImage("resources/game_of_life/glider_gun.png"); break; case 7: pattern = LoadImage("resources/game_of_life/glider_gun.png"); break;
case 8: pattern = LoadImage("resources/game_of_life/breeder.png"); break; case 8: pattern = LoadImage("resources/game_of_life/breeder.png"); break;
} }
BeginTextureMode(*currentWorld); BeginTextureMode(*rtWorldCurrentPtr);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
EndTextureMode(); EndTextureMode();
UpdateTextureRec(currentWorld->texture, (Rectangle){ worldWidth*presetPatterns[preset].position.x - pattern.width/2.0f, UpdateTextureRec(rtWorldCurrentPtr->texture, (Rectangle){ worldWidth*presetPatterns[preset].position.x - pattern.width/2.0f,
worldHeight*presetPatterns[preset].position.y - pattern.height/2.0f, worldHeight*presetPatterns[preset].position.y - pattern.height/2.0f,
(float)(pattern.width), (float)(pattern.height) }, pattern.data); (float)(pattern.width), (float)(pattern.height) }, pattern.data);
} }
@ -248,7 +248,7 @@ int main(void)
if (GetRandomValue(0, 100) < 15) ImageDrawPixel(&pattern, x, y, BLACK); if (GetRandomValue(0, 100) < 15) ImageDrawPixel(&pattern, x, y, BLACK);
} }
} }
UpdateTextureRec(currentWorld->texture, UpdateTextureRec(rtWorldCurrentPtr->texture,
(Rectangle){ (float)(pattern.width*i), (float)(pattern.height*j), (Rectangle){ (float)(pattern.width*i), (float)(pattern.height*j),
(float)(pattern.width), (float)(pattern.height) }, pattern.data); (float)(pattern.width), (float)(pattern.height) }, pattern.data);
} }
@ -277,14 +277,14 @@ int main(void)
if ((mode == MODE_RUN) && ((frame%framesPerStep) == 0)) if ((mode == MODE_RUN) && ((frame%framesPerStep) == 0))
{ {
// Swap worlds // Swap worlds
RenderTexture2D *tempWorld = currentWorld; RenderTexture2D *tempWorld = rtWorldCurrentPtr;
currentWorld = previousWorld; rtWorldCurrentPtr = rtWorldPreviousPtr;
previousWorld = tempWorld; rtWorldPreviousPtr = tempWorld;
// Draw to texture // Draw to texture
BeginTextureMode(*currentWorld); BeginTextureMode(*rtWorldCurrentPtr);
BeginShaderMode(shdrGameOfLife); BeginShaderMode(shdrGameOfLife);
DrawTexturePro(previousWorld->texture, worldRectSource, worldRectDest, (Vector2){ 0, 0 }, 0.0f, RAYWHITE); DrawTexturePro(rtWorldPreviousPtr->texture, worldRectSource, worldRectDest, (Vector2){ 0, 0 }, 0.0f, RAYWHITE);
EndShaderMode(); EndShaderMode();
EndTextureMode(); EndTextureMode();
} }
@ -294,7 +294,7 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
DrawTexturePro(currentWorld->texture, textureSourceToScreen, textureOnScreen, (Vector2){ 0, 0 }, 0.0f, WHITE); DrawTexturePro(rtWorldCurrentPtr->texture, textureSourceToScreen, textureOnScreen, (Vector2){ 0, 0 }, 0.0f, WHITE);
DrawLine(windowWidth, 0, windowWidth, screenHeight, (Color){ 218, 218, 218, 255 }); DrawLine(windowWidth, 0, windowWidth, screenHeight, (Color){ 218, 218, 218, 255 });
DrawRectangle(windowWidth, 0, screenWidth - windowWidth, screenHeight, (Color){ 232, 232, 232, 255 }); DrawRectangle(windowWidth, 0, screenWidth - windowWidth, screenHeight, (Color){ 232, 232, 232, 255 });
@ -328,10 +328,10 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shdrGameOfLife); UnloadShader(shdrGameOfLife);
UnloadRenderTexture(world1); UnloadRenderTexture(rtWorld1);
UnloadRenderTexture(world2); UnloadRenderTexture(rtWorld2);
FreeImageToDraw(&imageToDraw); FreeImageToDraw(&imToDrawPtr);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -80,43 +80,43 @@ int main(void)
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/lightmap.vs", GLSL_VERSION), Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/lightmap.vs", GLSL_VERSION),
TextFormat("resources/shaders/glsl%i/lightmap.fs", GLSL_VERSION)); TextFormat("resources/shaders/glsl%i/lightmap.fs", GLSL_VERSION));
Texture texture = LoadTexture("resources/cubicmap_atlas.png"); Texture2D texCubicmap = LoadTexture("resources/cubicmap_atlas.png");
Texture light = LoadTexture("resources/spark_flame.png"); Texture2D texLight = LoadTexture("resources/spark_flame.png");
GenTextureMipmaps(&texture); GenTextureMipmaps(&texCubicmap);
SetTextureFilter(texture, TEXTURE_FILTER_TRILINEAR); SetTextureFilter(texCubicmap, TEXTURE_FILTER_TRILINEAR);
RenderTexture lightmap = LoadRenderTexture(MAP_SIZE, MAP_SIZE); RenderTexture2D rtLightmap = LoadRenderTexture(MAP_SIZE, MAP_SIZE);
Material material = LoadMaterialDefault(); Material material = LoadMaterialDefault();
material.shader = shader; material.shader = shader;
material.maps[MATERIAL_MAP_ALBEDO].texture = texture; material.maps[MATERIAL_MAP_ALBEDO].texture = texCubicmap;
material.maps[MATERIAL_MAP_METALNESS].texture = lightmap.texture; material.maps[MATERIAL_MAP_METALNESS].texture = rtLightmap.texture;
// Drawing to lightmap // Drawing to lightmap
BeginTextureMode(lightmap); BeginTextureMode(rtLightmap);
ClearBackground(BLACK); ClearBackground(BLACK);
BeginBlendMode(BLEND_ADDITIVE); BeginBlendMode(BLEND_ADDITIVE);
DrawTexturePro( DrawTexturePro(
light, texLight,
(Rectangle){ 0, 0, (float)light.width, (float)light.height }, (Rectangle){ 0, 0, (float)texLight.width, (float)texLight.height },
(Rectangle){ 0, 0, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE }, (Rectangle){ 0, 0, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE },
(Vector2){ (float)MAP_SIZE, (float)MAP_SIZE }, (Vector2){ (float)MAP_SIZE, (float)MAP_SIZE },
0.0, 0.0,
RED RED
); );
DrawTexturePro( DrawTexturePro(
light, texLight,
(Rectangle){ 0, 0, (float)light.width, (float)light.height }, (Rectangle){ 0, 0, (float)texLight.width, (float)texLight.height },
(Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE/2.0f, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE }, (Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE/2.0f, 2.0f*MAP_SIZE, 2.0f*MAP_SIZE },
(Vector2){ (float)MAP_SIZE, (float)MAP_SIZE }, (Vector2){ (float)MAP_SIZE, (float)MAP_SIZE },
0.0, 0.0,
BLUE BLUE
); );
DrawTexturePro( DrawTexturePro(
light, texLight,
(Rectangle){ 0, 0, (float)light.width, (float)light.height }, (Rectangle){ 0, 0, (float)texLight.width, (float)texLight.height },
(Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE*0.8f, (float)MAP_SIZE, (float)MAP_SIZE }, (Rectangle){ (float)MAP_SIZE*0.8f, (float)MAP_SIZE*0.8f, (float)MAP_SIZE, (float)MAP_SIZE },
(Vector2){ (float)MAP_SIZE/2.0f, (float)MAP_SIZE/2.0f }, (Vector2){ (float)MAP_SIZE/2.0f, (float)MAP_SIZE/2.0f },
0.0, 0.0,
@ -126,8 +126,8 @@ int main(void)
EndTextureMode(); EndTextureMode();
// NOTE: To enable trilinear filtering we need mipmaps available for texture // NOTE: To enable trilinear filtering we need mipmaps available for texture
GenTextureMipmaps(&lightmap.texture); GenTextureMipmaps(&rtLightmap.texture);
SetTextureFilter(lightmap.texture, TEXTURE_FILTER_TRILINEAR); SetTextureFilter(rtLightmap.texture, TEXTURE_FILTER_TRILINEAR);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -150,7 +150,7 @@ int main(void)
DrawMesh(mesh, material, MatrixIdentity()); DrawMesh(mesh, material, MatrixIdentity());
EndMode3D(); EndMode3D();
DrawTexturePro(lightmap.texture, (Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE }, DrawTexturePro(rtLightmap.texture, (Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE },
(Rectangle){ (float)GetRenderWidth() - MAP_SIZE*8 - 10, 10, (float)MAP_SIZE*8, (float)MAP_SIZE*8 }, (Rectangle){ (float)GetRenderWidth() - MAP_SIZE*8 - 10, 10, (float)MAP_SIZE*8, (float)MAP_SIZE*8 },
(Vector2){ 0.0, 0.0 }, 0.0, WHITE); (Vector2){ 0.0, 0.0 }, 0.0, WHITE);
@ -166,9 +166,9 @@ int main(void)
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadMesh(mesh); // Unload the mesh UnloadMesh(mesh); // Unload the mesh
UnloadShader(shader); // Unload shader UnloadShader(shader); // Unload shader
UnloadTexture(texture); // Unload texture UnloadTexture(texCubicmap); // Unload texture
UnloadTexture(light); // Unload texture UnloadTexture(texLight); // Unload texture
UnloadRenderTexture(lightmap); // Unload lightmap render texture UnloadRenderTexture(rtLightmap); // Unload lightmap render texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -52,7 +52,7 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
// Define mesh to be instanced // Define mesh to be instanced
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); Mesh mesh = GenMeshCube(1.0f, 1.0f, 1.0f);
// Define transforms to be uploaded to GPU for instances // Define transforms to be uploaded to GPU for instances
Matrix *transforms = (Matrix *)RL_CALLOC(MAX_INSTANCES, sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl Matrix *transforms = (Matrix *)RL_CALLOC(MAX_INSTANCES, sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl
@ -118,15 +118,15 @@ int main(void)
BeginMode3D(camera); BeginMode3D(camera);
// Draw cube mesh with default material (BLUE) // Draw cube mesh with default material (BLUE)
DrawMesh(cube, matDefault, MatrixTranslate(-10.0f, 0.0f, 0.0f)); DrawMesh(mesh, matDefault, MatrixTranslate(-10.0f, 0.0f, 0.0f));
// Draw meshes instanced using material containing instancing shader (RED + lighting), // Draw meshes instanced using material containing instancing shader (RED + lighting),
// transforms[] for the instances should be provided, they are dynamically // transforms[] for the instances should be provided, they are dynamically
// updated in GPU every frame, so we can animate the different mesh instances // updated in GPU every frame, so we can animate the different mesh instances
DrawMeshInstanced(cube, matInstances, transforms, MAX_INSTANCES); DrawMeshInstanced(mesh, matInstances, transforms, MAX_INSTANCES);
// Draw cube mesh with default material (BLUE) // Draw cube mesh with default material (BLUE)
DrawMesh(cube, matDefault, MatrixTranslate(10.0f, 0.0f, 0.0f)); DrawMesh(mesh, matDefault, MatrixTranslate(10.0f, 0.0f, 0.0f));
EndMode3D(); EndMode3D();
@ -141,7 +141,7 @@ int main(void)
RL_FREE(transforms); // Free transforms RL_FREE(transforms); // Free transforms
UnloadMaterial(matInstances); // Also unloads the instancing shader UnloadMaterial(matInstances); // Also unloads the instancing shader
UnloadMaterial(matDefault); // Unload default material UnloadMaterial(matDefault); // Unload default material
UnloadMesh(cube); // Unload cube mesh UnloadMesh(mesh); // Unload cube mesh
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -41,11 +41,11 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - multi sample2d"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - multi sample2d");
Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 }); Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 });
Texture texRed = LoadTextureFromImage(imRed); Texture2D texRed = LoadTextureFromImage(imRed);
UnloadImage(imRed); UnloadImage(imRed);
Image imBlue = GenImageColor(800, 450, (Color){ 0, 0, 255, 255 }); Image imBlue = GenImageColor(800, 450, (Color){ 0, 0, 255, 255 });
Texture texBlue = LoadTextureFromImage(imBlue); Texture2D texBlue = LoadTextureFromImage(imBlue);
UnloadImage(imBlue); UnloadImage(imBlue);
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/color_mix.fs", GLSL_VERSION)); Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/color_mix.fs", GLSL_VERSION));

View File

@ -88,9 +88,9 @@ int main(void)
// Create a white texture of the size of the window to update // Create a white texture of the size of the window to update
// each pixel of the window using the fragment shader: golRenderShader // each pixel of the window using the fragment shader: golRenderShader
Image whiteImage = GenImageColor(GOL_WIDTH, GOL_WIDTH, WHITE); Image imCanvas = GenImageColor(GOL_WIDTH, GOL_WIDTH, WHITE);
Texture whiteTex = LoadTextureFromImage(whiteImage); Texture2D texCanvas = LoadTextureFromImage(imCanvas);
UnloadImage(whiteImage); UnloadImage(imCanvas);
SetTargetFPS(0); // Set our game to run with an uncapped framerate SetTargetFPS(0); // Set our game to run with an uncapped framerate
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -152,7 +152,7 @@ int main(void)
ClearBackground(BLANK); ClearBackground(BLANK);
BeginShaderMode(golRenderShader); BeginShaderMode(golRenderShader);
DrawTexture(whiteTex, 0, 0, WHITE); DrawTexture(texCanvas, 0, 0, WHITE);
EndShaderMode(); EndShaderMode();
DrawRectangleLines(GetMouseX() - brushSize/2, GetMouseY() - brushSize/2, brushSize, brushSize, RED); DrawRectangleLines(GetMouseX() - brushSize/2, GetMouseY() - brushSize/2, brushSize, brushSize, RED);
@ -177,7 +177,7 @@ int main(void)
rlUnloadShaderProgram(golTransfertProgram); rlUnloadShaderProgram(golTransfertProgram);
rlUnloadShaderProgram(golLogicProgram); rlUnloadShaderProgram(golLogicProgram);
UnloadTexture(whiteTex); // Unload white texture UnloadTexture(texCanvas); // Unload white texture
UnloadShader(golRenderShader); // Unload rendering fragment shader UnloadShader(golRenderShader); // Unload rendering fragment shader
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context

View File

@ -40,7 +40,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes textures"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes textures");
Texture2D fudesumi = LoadTexture("resources/fudesumi.png"); Texture2D texture = LoadTexture("resources/fudesumi.png");
// Load shader to be used on some parts drawing // Load shader to be used on some parts drawing
// NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
@ -100,7 +100,7 @@ int main(void)
// Activate our custom shader to be applied on next shapes/textures drawings // Activate our custom shader to be applied on next shapes/textures drawings
BeginShaderMode(shader); BeginShaderMode(shader);
DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader DrawTexture(texture, 500, -30, WHITE); // Using custom shader
// Activate our default shader for next drawings // Activate our default shader for next drawings
EndShaderMode(); EndShaderMode();
@ -114,7 +114,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader UnloadShader(shader); // Unload shader
UnloadTexture(fudesumi); // Unload texture UnloadTexture(texture); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -52,37 +52,37 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
// Define our three models to show the shader on // Define our three models to show the shader on
Mesh torus = GenMeshTorus(0.3f, 1, 16, 32); Mesh meshTorus = GenMeshTorus(0.3f, 1, 16, 32);
Model model1 = LoadModelFromMesh(torus); Model modelTorus = LoadModelFromMesh(meshTorus);
Mesh cube = GenMeshCube(0.8f,0.8f,0.8f); Mesh meshCube = GenMeshCube(0.8f,0.8f,0.8f);
Model model2 = LoadModelFromMesh(cube); Model modelCube = LoadModelFromMesh(meshCube);
// Generate model to be shaded just to see the gaps in the other two // Generate model to be shaded just to see the gaps in the other two
Mesh sphere = GenMeshSphere(1, 16, 16); Mesh meshSphere = GenMeshSphere(1, 16, 16);
Model model3 = LoadModelFromMesh(sphere); Model modelSphere = LoadModelFromMesh(meshSphere);
// Load the shader // Load the shader
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/mask.fs", GLSL_VERSION)); Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/mask.fs", GLSL_VERSION));
// Load and apply the diffuse texture (colour map) // Load and apply the diffuse texture (colour map)
Texture texDiffuse = LoadTexture("resources/plasma.png"); Texture2D texDiffuse = LoadTexture("resources/plasma.png");
model1.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texDiffuse; modelTorus.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texDiffuse;
model2.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texDiffuse; modelCube.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texDiffuse;
// Using MATERIAL_MAP_EMISSION as a spare slot to use for 2nd texture // Using MATERIAL_MAP_EMISSION as a spare slot to use for 2nd texture
// NOTE: Don't use MATERIAL_MAP_IRRADIANCE, MATERIAL_MAP_PREFILTER or MATERIAL_MAP_CUBEMAP as they are bound as cube maps // NOTE: Don't use MATERIAL_MAP_IRRADIANCE, MATERIAL_MAP_PREFILTER or MATERIAL_MAP_CUBEMAP as they are bound as cube maps
Texture texMask = LoadTexture("resources/mask.png"); Texture2D texMask = LoadTexture("resources/mask.png");
model1.materials[0].maps[MATERIAL_MAP_EMISSION].texture = texMask; modelTorus.materials[0].maps[MATERIAL_MAP_EMISSION].texture = texMask;
model2.materials[0].maps[MATERIAL_MAP_EMISSION].texture = texMask; modelCube.materials[0].maps[MATERIAL_MAP_EMISSION].texture = texMask;
shader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(shader, "mask"); shader.locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(shader, "mask");
// Frame is incremented each frame to animate the shader // Frame is incremented each frame to animate the shader
int shaderFrame = GetShaderLocation(shader, "frame"); int shaderFrame = GetShaderLocation(shader, "frame");
// Apply the shader to the two models // Apply the shader to the two models
model1.materials[0].shader = shader; modelTorus.materials[0].shader = shader;
model2.materials[0].shader = shader; modelCube.materials[0].shader = shader;
int framesCounter = 0; int framesCounter = 0;
Vector3 rotation = { 0 }; // Model rotation angles Vector3 rotation = { 0 }; // Model rotation angles
@ -107,7 +107,7 @@ int main(void)
SetShaderValue(shader, shaderFrame, &framesCounter, SHADER_UNIFORM_INT); SetShaderValue(shader, shaderFrame, &framesCounter, SHADER_UNIFORM_INT);
// Rotate one of the models // Rotate one of the models
model1.transform = MatrixRotateXYZ(rotation); modelTorus.transform = MatrixRotateXYZ(rotation);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -118,9 +118,9 @@ int main(void)
BeginMode3D(camera); BeginMode3D(camera);
DrawModel(model1, (Vector3){ 0.5f, 0.0f, 0.0f }, 1, WHITE); DrawModel(modelTorus, (Vector3){ 0.5f, 0.0f, 0.0f }, 1, WHITE);
DrawModelEx(model2, (Vector3){ -0.5f, 0.0f, 0.0f }, (Vector3){ 1.0f, 1.0f, 0.0f }, 50, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE); DrawModelEx(modelCube, (Vector3){ -0.5f, 0.0f, 0.0f }, (Vector3){ 1.0f, 1.0f, 0.0f }, 50, (Vector3){ 1.0f, 1.0f, 1.0f }, WHITE);
DrawModel(model3,(Vector3){ 0.0f, 0.0f, -1.5f }, 1, WHITE); DrawModel(modelSphere,(Vector3){ 0.0f, 0.0f, -1.5f }, 1, WHITE);
DrawGrid(10, 1.0f); // Draw a grid DrawGrid(10, 1.0f); // Draw a grid
EndMode3D(); EndMode3D();
@ -136,9 +136,9 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadModel(model1); UnloadModel(modelTorus);
UnloadModel(model2); UnloadModel(modelCube);
UnloadModel(model3); UnloadModel(modelSphere);
UnloadTexture(texDiffuse); // Unload default diffuse texture UnloadTexture(texDiffuse); // Unload default diffuse texture
UnloadTexture(texMask); // Unload texture mask UnloadTexture(texMask); // Unload texture mask

View File

@ -84,7 +84,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - spotlight rendering"); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - spotlight rendering");
HideCursor(); HideCursor();
Texture texRay = LoadTexture("resources/raysan.png"); Texture2D texRay = LoadTexture("resources/raysan.png");
Star stars[MAX_STARS] = { 0 }; Star stars[MAX_STARS] = { 0 };

View File

@ -46,8 +46,8 @@ int main(void)
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
// Load a cube model // Load a cube model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); Mesh mesh = GenMeshCube(1.0f, 1.0f, 1.0f);
Model model = LoadModelFromMesh(cube); Model model = LoadModelFromMesh(mesh);
// Load a texture and assign to cube model // Load a texture and assign to cube model
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");

View File

@ -54,22 +54,22 @@ int main(void)
TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION)); TextFormat("resources/shaders/glsl%i/vertex_displacement.fs", GLSL_VERSION));
// Load perlin noise texture // Load perlin noise texture
Image perlinNoiseImage = GenImagePerlinNoise(512, 512, 0, 0, 1.0f); Image imPerlinNoise = GenImagePerlinNoise(512, 512, 0, 0, 1.0f);
Texture perlinNoiseMap = LoadTextureFromImage(perlinNoiseImage); Texture2D texPerlinNoise = LoadTextureFromImage(imPerlinNoise);
UnloadImage(perlinNoiseImage); UnloadImage(imPerlinNoise);
// Set shader uniform location // Set shader uniform location
int perlinNoiseMapLoc = GetShaderLocation(shader, "perlinNoiseMap"); int perlinNoiseMapLoc = GetShaderLocation(shader, "perlinNoiseMap");
rlEnableShader(shader.id); rlEnableShader(shader.id);
rlActiveTextureSlot(1); rlActiveTextureSlot(1);
rlEnableTexture(perlinNoiseMap.id); rlEnableTexture(texPerlinNoise.id);
rlSetUniformSampler(perlinNoiseMapLoc, 1); rlSetUniformSampler(perlinNoiseMapLoc, 1);
// Create a plane mesh and model // Create a plane mesh and model
Mesh planeMesh = GenMeshPlane(50, 50, 50, 50); Mesh meshPlane = GenMeshPlane(50, 50, 50, 50);
Model planeModel = LoadModelFromMesh(planeMesh); Model modelPlane = LoadModelFromMesh(meshPlane);
// Set plane model material // Set plane model material
planeModel.materials[0].shader = shader; modelPlane.materials[0].shader = shader;
float time = 0.0f; float time = 0.0f;
@ -96,7 +96,7 @@ int main(void)
BeginShaderMode(shader); BeginShaderMode(shader);
// Draw plane model // Draw plane model
DrawModel(planeModel, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, (Color) {255, 255, 255, 255}); DrawModel(modelPlane, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, (Color) {255, 255, 255, 255});
EndShaderMode(); EndShaderMode();
EndMode3D(); EndMode3D();
@ -111,8 +111,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); UnloadShader(shader);
UnloadModel(planeModel); UnloadModel(modelPlane);
UnloadTexture(perlinNoiseMap); UnloadTexture(texPerlinNoise);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -63,11 +63,11 @@ int main(void)
float magicCircleRotation = 0; float magicCircleRotation = 0;
// Used on performance drawing // Used on performance drawing
RenderTexture bulletTexture = LoadRenderTexture(24, 24); RenderTexture2D rtBullet = LoadRenderTexture(24, 24);
// Draw circle to bullet texture, then draw bullet using DrawTexture() // Draw circle to bullet texture, then draw bullet using DrawTexture()
// NOTE: This is done to improve the performance, since DrawCircle() is very slow // NOTE: This is done to improve the performance, since DrawCircle() is very slow
BeginTextureMode(bulletTexture); BeginTextureMode(rtBullet);
DrawCircle(12, 12, (float)bulletRadius, WHITE); DrawCircle(12, 12, (float)bulletRadius, WHITE);
DrawCircleLines(12, 12, (float)bulletRadius, BLACK); DrawCircleLines(12, 12, (float)bulletRadius, BLACK);
EndTextureMode(); EndTextureMode();
@ -191,9 +191,9 @@ int main(void)
// Do not draw disabled bullets (out of screen) // Do not draw disabled bullets (out of screen)
if (!bullets[i].disabled) if (!bullets[i].disabled)
{ {
DrawTexture(bulletTexture.texture, DrawTexture(rtBullet.texture,
(int)(bullets[i].position.x - bulletTexture.texture.width*0.5f), (int)(bullets[i].position.x - rtBullet.texture.width*0.5f),
(int)(bullets[i].position.y - bulletTexture.texture.height*0.5f), (int)(bullets[i].position.y - rtBullet.texture.height*0.5f),
bullets[i].color); bullets[i].color);
} }
} }
@ -237,7 +237,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadRenderTexture(bulletTexture); // Unload bullet texture UnloadRenderTexture(rtBullet); // Unload bullet texture
RL_FREE(bullets); // Free bullets array data RL_FREE(bullets); // Free bullets array data

View File

@ -38,7 +38,7 @@ int main(void)
Vector2 mousePositionPrevious = GetMousePosition(); Vector2 mousePositionPrevious = GetMousePosition();
// The canvas to draw lines on // The canvas to draw lines on
RenderTexture canvas = LoadRenderTexture(screenWidth, screenHeight); RenderTexture2D canvas = LoadRenderTexture(screenWidth, screenHeight);
// The line's thickness // The line's thickness
float lineThickness = 8.0f; float lineThickness = 8.0f;

View File

@ -90,12 +90,12 @@ int main(void)
SetupBoxes(boxes, &boxCount); SetupBoxes(boxes, &boxCount);
// Create a checkerboard ground texture // Create a checkerboard ground texture
Image img = GenImageChecked(64, 64, 32, 32, DARKBROWN, DARKGRAY); Image imChecked = GenImageChecked(64, 64, 32, 32, DARKBROWN, DARKGRAY);
Texture2D backgroundTexture = LoadTextureFromImage(img); Texture2D texBackground = LoadTextureFromImage(imChecked);
UnloadImage(img); UnloadImage(imChecked);
// Create a global light mask to hold all the blended lights // Create a global light mask to hold all the blended lights
RenderTexture lightMask = LoadRenderTexture(GetScreenWidth(), GetScreenHeight()); RenderTexture2D rtLightMask = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
// Setup initial light // Setup initial light
SetupLight(0, 600, 400, 300); SetupLight(0, 600, 400, 300);
@ -135,7 +135,7 @@ int main(void)
if (dirtyLights) if (dirtyLights)
{ {
// Build up the light mask // Build up the light mask
BeginTextureMode(lightMask); BeginTextureMode(rtLightMask);
ClearBackground(BLACK); ClearBackground(BLACK);
@ -164,10 +164,10 @@ int main(void)
ClearBackground(BLACK); ClearBackground(BLACK);
// Draw the tile background // Draw the tile background
DrawTextureRec(backgroundTexture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2Zero(), WHITE); DrawTextureRec(texBackground, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2Zero(), WHITE);
// Overlay the shadows from all the lights // Overlay the shadows from all the lights
DrawTextureRec(lightMask.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight() }, Vector2Zero(), ColorAlpha(WHITE, showLines? 0.75f : 1.0f)); DrawTextureRec(rtLightMask.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight() }, Vector2Zero(), ColorAlpha(WHITE, showLines? 0.75f : 1.0f));
// Draw the lights // Draw the lights
for (int i = 0; i < MAX_LIGHTS; i++) for (int i = 0; i < MAX_LIGHTS; i++)
@ -206,8 +206,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(backgroundTexture); UnloadTexture(texBackground);
UnloadRenderTexture(lightMask); UnloadRenderTexture(rtLightMask);
for (int i = 0; i < MAX_LIGHTS; i++) for (int i = 0; i < MAX_LIGHTS; i++)
{ {
if (lights[i].active) UnloadRenderTexture(lights[i].mask); if (lights[i].active) UnloadRenderTexture(lights[i].mask);

View File

@ -29,13 +29,13 @@ int main(void)
// NOTE: Be careful, background width must be equal or bigger than screen width // NOTE: Be careful, background width must be equal or bigger than screen width
// if not, texture should be draw more than two times for scrolling effect // if not, texture should be draw more than two times for scrolling effect
Texture2D background = LoadTexture("resources/cyberpunk_street_background.png"); Texture2D texBackground = LoadTexture("resources/cyberpunk_street_background.png");
Texture2D midground = LoadTexture("resources/cyberpunk_street_midground.png"); Texture2D texMidground = LoadTexture("resources/cyberpunk_street_midground.png");
Texture2D foreground = LoadTexture("resources/cyberpunk_street_foreground.png"); Texture2D texForeground = LoadTexture("resources/cyberpunk_street_foreground.png");
float scrollingBack = 0.0f; float scrollingBackground = 0.0f;
float scrollingMid = 0.0f; float scrollingMidground = 0.0f;
float scrollingFore = 0.0f; float scrollingForeground = 0.0f;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -45,14 +45,14 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
scrollingBack -= 0.1f; scrollingBackground -= 0.1f;
scrollingMid -= 0.5f; scrollingMidground -= 0.5f;
scrollingFore -= 1.0f; scrollingForeground -= 1.0f;
// NOTE: Texture is scaled twice its size, so it sould be considered on scrolling // NOTE: Texture is scaled twice its size, so it sould be considered on scrolling
if (scrollingBack <= -background.width*2) scrollingBack = 0; if (scrollingBackground <= -texBackground.width*2) scrollingBackground = 0;
if (scrollingMid <= -midground.width*2) scrollingMid = 0; if (scrollingMidground <= -texMidground.width*2) scrollingMidground = 0;
if (scrollingFore <= -foreground.width*2) scrollingFore = 0; if (scrollingForeground <= -texForeground.width*2) scrollingForeground = 0;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -63,16 +63,16 @@ int main(void)
// Draw background image twice // Draw background image twice
// NOTE: Texture is scaled twice its size // NOTE: Texture is scaled twice its size
DrawTextureEx(background, (Vector2){ scrollingBack, 20 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texBackground, (Vector2){ scrollingBackground, 20 }, 0.0f, 2.0f, WHITE);
DrawTextureEx(background, (Vector2){ background.width*2 + scrollingBack, 20 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texBackground, (Vector2){ texBackground.width*2 + scrollingBackground, 20 }, 0.0f, 2.0f, WHITE);
// Draw midground image twice // Draw midground image twice
DrawTextureEx(midground, (Vector2){ scrollingMid, 20 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texMidground, (Vector2){ scrollingMidground, 20 }, 0.0f, 2.0f, WHITE);
DrawTextureEx(midground, (Vector2){ midground.width*2 + scrollingMid, 20 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texMidground, (Vector2){ texMidground.width*2 + scrollingMidground, 20 }, 0.0f, 2.0f, WHITE);
// Draw foreground image twice // Draw foreground image twice
DrawTextureEx(foreground, (Vector2){ scrollingFore, 70 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texForeground, (Vector2){ scrollingForeground, 70 }, 0.0f, 2.0f, WHITE);
DrawTextureEx(foreground, (Vector2){ foreground.width*2 + scrollingFore, 70 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texForeground, (Vector2){ texForeground.width*2 + scrollingForeground, 70 }, 0.0f, 2.0f, WHITE);
DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, RED); DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, RED);
DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, RAYWHITE); DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, RAYWHITE);
@ -83,9 +83,9 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(background); // Unload background texture UnloadTexture(texBackground); // Unload background texture
UnloadTexture(midground); // Unload midground texture UnloadTexture(texMidground); // Unload midground texture
UnloadTexture(foreground); // Unload foreground texture UnloadTexture(texForeground); // Unload foreground texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -32,15 +32,15 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - blend modes"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - blend modes");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image bgImage = LoadImage("resources/cyberpunk_street_background.png"); // Loaded in CPU memory (RAM) Image imBackground = LoadImage("resources/cyberpunk_street_background.png"); // Loaded in CPU memory (RAM)
Texture2D bgTexture = LoadTextureFromImage(bgImage); // Image converted to texture, GPU memory (VRAM) Texture2D texBackground = LoadTextureFromImage(imBackground); // Image converted to texture, GPU memory (VRAM)
Image fgImage = LoadImage("resources/cyberpunk_street_foreground.png"); // Loaded in CPU memory (RAM) Image imForeground = LoadImage("resources/cyberpunk_street_foreground.png"); // Loaded in CPU memory (RAM)
Texture2D fgTexture = LoadTextureFromImage(fgImage); // Image converted to texture, GPU memory (VRAM) Texture2D texForeground = LoadTextureFromImage(imForeground); // Image converted to texture, GPU memory (VRAM)
// Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
UnloadImage(bgImage); UnloadImage(imBackground);
UnloadImage(fgImage); UnloadImage(imForeground);
const int blendCountMax = 4; const int blendCountMax = 4;
BlendMode blendMode = 0; BlendMode blendMode = 0;
@ -66,11 +66,11 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(bgTexture, screenWidth/2 - bgTexture.width/2, screenHeight/2 - bgTexture.height/2, WHITE); DrawTexture(texBackground, screenWidth/2 - texBackground.width/2, screenHeight/2 - texBackground.height/2, WHITE);
// Apply the blend mode and then draw the foreground texture // Apply the blend mode and then draw the foreground texture
BeginBlendMode(blendMode); BeginBlendMode(blendMode);
DrawTexture(fgTexture, screenWidth/2 - fgTexture.width/2, screenHeight/2 - fgTexture.height/2, WHITE); DrawTexture(texForeground, screenWidth/2 - texForeground.width/2, screenHeight/2 - texForeground.height/2, WHITE);
EndBlendMode(); EndBlendMode();
// Draw the texts // Draw the texts
@ -93,8 +93,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(fgTexture); // Unload foreground texture UnloadTexture(texForeground); // Unload foreground texture
UnloadTexture(bgTexture); // Unload background texture UnloadTexture(texBackground); // Unload background texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -66,9 +66,9 @@ int main(void)
// Render texture to render fog of war // Render texture to render fog of war
// NOTE: To get an automatic smooth-fog effect we use a render texture to render fog // NOTE: To get an automatic smooth-fog effect we use a render texture to render fog
// at a smaller size (one pixel per tile) and scale it on drawing with bilinear filtering // at a smaller size (one pixel per tile) and scale it on drawing with bilinear filtering
RenderTexture2D fogOfWar = LoadRenderTexture(map.tilesX, map.tilesY); RenderTexture2D rtFogOfWar = LoadRenderTexture(map.tilesX, map.tilesY);
SetTextureFilter(fogOfWar.texture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(rtFogOfWar.texture, TEXTURE_FILTER_BILINEAR);
SetTextureWrap(fogOfWar.texture, TEXTURE_WRAP_CLAMP); SetTextureWrap(rtFogOfWar.texture, TEXTURE_WRAP_CLAMP);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -107,7 +107,7 @@ int main(void)
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw fog of war to a small render texture for automatic smoothing on scaling // Draw fog of war to a small render texture for automatic smoothing on scaling
BeginTextureMode(fogOfWar); BeginTextureMode(rtFogOfWar);
ClearBackground(BLANK); ClearBackground(BLANK);
for (unsigned int y = 0; y < map.tilesY; y++) for (unsigned int y = 0; y < map.tilesY; y++)
for (unsigned int x = 0; x < map.tilesX; x++) for (unsigned int x = 0; x < map.tilesX; x++)
@ -135,7 +135,7 @@ int main(void)
// Draw fog of war (scaled to full map, bilinear filtering) // Draw fog of war (scaled to full map, bilinear filtering)
DrawTexturePro(fogOfWar.texture, (Rectangle){ 0, 0, (float)fogOfWar.texture.width, (float)-fogOfWar.texture.height }, DrawTexturePro(rtFogOfWar.texture, (Rectangle){ 0, 0, (float)rtFogOfWar.texture.width, (float)-rtFogOfWar.texture.height },
(Rectangle){ 0, 0, (float)map.tilesX*MAP_TILE_SIZE, (float)map.tilesY*MAP_TILE_SIZE }, (Rectangle){ 0, 0, (float)map.tilesX*MAP_TILE_SIZE, (float)map.tilesY*MAP_TILE_SIZE },
(Vector2){ 0, 0 }, 0.0f, WHITE); (Vector2){ 0, 0 }, 0.0f, WHITE);
@ -152,7 +152,7 @@ int main(void)
RL_FREE(map.tileIds); // Free allocated map tile ids RL_FREE(map.tileIds); // Free allocated map tile ids
RL_FREE(map.tileFog); // Free allocated map tile fog state RL_FREE(map.tileFog); // Free allocated map tile fog state
UnloadRenderTexture(fogOfWar); // Unload render texture UnloadRenderTexture(rtFogOfWar); // Unload render texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -53,18 +53,18 @@ int main(void)
observerCamera.projection = CAMERA_PERSPECTIVE; observerCamera.projection = CAMERA_PERSPECTIVE;
// Set up render textures // Set up render textures
RenderTexture2D observerTarget = LoadRenderTexture(splitWidth, screenHeight); RenderTexture2D rtObserver = LoadRenderTexture(splitWidth, screenHeight);
Rectangle observerSource = { 0.0f, 0.0f, (float)observerTarget.texture.width, -(float)observerTarget.texture.height }; Rectangle observerSource = { 0.0f, 0.0f, (float)rtObserver.texture.width, -(float)rtObserver.texture.height };
Rectangle observerDest = { 0.0f, 0.0f, (float)splitWidth, (float)screenHeight }; Rectangle observerDest = { 0.0f, 0.0f, (float)splitWidth, (float)screenHeight };
RenderTexture2D subjectTarget = LoadRenderTexture(splitWidth, screenHeight); RenderTexture2D rtSubject = LoadRenderTexture(splitWidth, screenHeight);
Rectangle subjectSource = { 0.0f, 0.0f, (float)subjectTarget.texture.width, -(float)subjectTarget.texture.height }; Rectangle subjectSource = { 0.0f, 0.0f, (float)rtSubject.texture.width, -(float)rtSubject.texture.height };
Rectangle subjectDest = { (float)splitWidth, 0.0f, (float)splitWidth, (float)screenHeight }; Rectangle subjectDest = { (float)splitWidth, 0.0f, (float)splitWidth, (float)screenHeight };
const float textureAspectRatio = (float)subjectTarget.texture.width/(float)subjectTarget.texture.height; const float textureAspectRatio = (float)rtSubject.texture.width/(float)rtSubject.texture.height;
// Rectangles for cropping render texture // Rectangles for cropping render texture
const float captureSize = 128.0f; const float captureSize = 128.0f;
Rectangle cropSource = { (subjectTarget.texture.width - captureSize)/2.0f, (subjectTarget.texture.height - captureSize)/2.0f, captureSize, -captureSize }; Rectangle cropSource = { (rtSubject.texture.width - captureSize)/2.0f, (rtSubject.texture.height - captureSize)/2.0f, captureSize, -captureSize };
Rectangle cropDest = { splitWidth + 20.0f, 20.0f, captureSize, captureSize}; Rectangle cropDest = { splitWidth + 20.0f, 20.0f, captureSize, captureSize};
SetTargetFPS(60); SetTargetFPS(60);
@ -82,7 +82,7 @@ int main(void)
if (IsKeyPressed(KEY_R)) observerCamera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; if (IsKeyPressed(KEY_R)) observerCamera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
// Build LHS observer view texture // Build LHS observer view texture
BeginTextureMode(observerTarget); BeginTextureMode(rtObserver);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
@ -95,7 +95,7 @@ int main(void)
EndMode3D(); EndMode3D();
DrawText("Observer View", 10, observerTarget.texture.height - 30, 20, BLACK); DrawText("Observer View", 10, rtObserver.texture.height - 30, 20, BLACK);
DrawText("WASD + Mouse to Move", 10, 10, 20, DARKGRAY); DrawText("WASD + Mouse to Move", 10, 10, 20, DARKGRAY);
DrawText("Scroll to Zoom", 10, 30, 20, DARKGRAY); DrawText("Scroll to Zoom", 10, 30, 20, DARKGRAY);
DrawText("R to Reset Observer Target", 10, 50, 20, DARKGRAY); DrawText("R to Reset Observer Target", 10, 50, 20, DARKGRAY);
@ -103,7 +103,7 @@ int main(void)
EndTextureMode(); EndTextureMode();
// Build RHS subject view texture // Build RHS subject view texture
BeginTextureMode(subjectTarget); BeginTextureMode(rtSubject);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
@ -115,8 +115,8 @@ int main(void)
EndMode3D(); EndMode3D();
DrawRectangleLines((int)((subjectTarget.texture.width - captureSize)/2.0f), (int)((subjectTarget.texture.height - captureSize)/2.0f), (int)captureSize, (int)captureSize, GREEN); DrawRectangleLines((int)((rtSubject.texture.width - captureSize)/2.0f), (int)((rtSubject.texture.height - captureSize)/2.0f), (int)captureSize, (int)captureSize, GREEN);
DrawText("Subject View", 10, subjectTarget.texture.height - 30, 20, BLACK); DrawText("Subject View", 10, rtSubject.texture.height - 30, 20, BLACK);
EndTextureMode(); EndTextureMode();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -128,13 +128,13 @@ int main(void)
ClearBackground(BLACK); ClearBackground(BLACK);
// Draw observer texture LHS // Draw observer texture LHS
DrawTexturePro(observerTarget.texture, observerSource, observerDest, (Vector2){0.0f, 0.0f }, 0.0f, WHITE); DrawTexturePro(rtObserver.texture, observerSource, observerDest, (Vector2){0.0f, 0.0f }, 0.0f, WHITE);
// Draw subject texture RHS // Draw subject texture RHS
DrawTexturePro(subjectTarget.texture, subjectSource, subjectDest, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE); DrawTexturePro(rtSubject.texture, subjectSource, subjectDest, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE);
// Draw the small crop overlay on top // Draw the small crop overlay on top
DrawTexturePro(subjectTarget.texture, cropSource, cropDest, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE); DrawTexturePro(rtSubject.texture, cropSource, cropDest, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE);
DrawRectangleLinesEx(cropDest, 2, BLACK); DrawRectangleLinesEx(cropDest, 2, BLACK);
// Draw split screen divider line // Draw split screen divider line
@ -146,8 +146,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadRenderTexture(observerTarget); UnloadRenderTexture(rtObserver);
UnloadRenderTexture(subjectTarget); UnloadRenderTexture(rtSubject);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -31,39 +31,39 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image channel"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - image channel");
Image fudesumiImage = LoadImage("resources/fudesumi.png"); Image imFudesumi = LoadImage("resources/fudesumi.png");
Image imageAlpha = ImageFromChannel(fudesumiImage, 3); Image imFudesumiAlpha = ImageFromChannel(imFudesumi, 3);
ImageAlphaMask(&imageAlpha, imageAlpha); ImageAlphaMask(&imFudesumiAlpha, imFudesumiAlpha);
Image imageRed = ImageFromChannel(fudesumiImage, 0); Image imFudesumiRed = ImageFromChannel(imFudesumi, 0);
ImageAlphaMask(&imageRed, imageAlpha); ImageAlphaMask(&imFudesumiRed, imFudesumiAlpha);
Image imageGreen = ImageFromChannel(fudesumiImage, 1); Image imFudesumiGreen = ImageFromChannel(imFudesumi, 1);
ImageAlphaMask(&imageGreen, imageAlpha); ImageAlphaMask(&imFudesumiGreen, imFudesumiAlpha);
Image imageBlue = ImageFromChannel(fudesumiImage, 2); Image imFudesumiBlue = ImageFromChannel(imFudesumi, 2);
ImageAlphaMask(&imageBlue, imageAlpha); ImageAlphaMask(&imFudesumiBlue, imFudesumiAlpha);
Image backgroundImage = GenImageChecked(screenWidth, screenHeight, screenWidth/20, screenHeight/20, ORANGE, YELLOW); Image imBackground = GenImageChecked(screenWidth, screenHeight, screenWidth/20, screenHeight/20, ORANGE, YELLOW);
Texture2D fudesumiTexture = LoadTextureFromImage(fudesumiImage); Texture2D texFudesumi = LoadTextureFromImage(imFudesumi);
Texture2D textureAlpha = LoadTextureFromImage(imageAlpha); Texture2D texFudesumiAlpha = LoadTextureFromImage(imFudesumiAlpha);
Texture2D textureRed = LoadTextureFromImage(imageRed); Texture2D texFudesumiRed = LoadTextureFromImage(imFudesumiRed);
Texture2D textureGreen = LoadTextureFromImage(imageGreen); Texture2D texFudesumiGreen = LoadTextureFromImage(imFudesumiGreen);
Texture2D textureBlue = LoadTextureFromImage(imageBlue); Texture2D texFudesumiBlue = LoadTextureFromImage(imFudesumiBlue);
Texture2D backgroundTexture = LoadTextureFromImage(backgroundImage); Texture2D texBackground = LoadTextureFromImage(imBackground);
UnloadImage(fudesumiImage); UnloadImage(imFudesumi);
UnloadImage(imageAlpha); UnloadImage(imFudesumiAlpha);
UnloadImage(imageRed); UnloadImage(imFudesumiRed);
UnloadImage(imageGreen); UnloadImage(imFudesumiGreen);
UnloadImage(imageBlue); UnloadImage(imFudesumiBlue);
UnloadImage(backgroundImage); UnloadImage(imBackground);
Rectangle fudesumiRec = {0, 0, (float)fudesumiImage.width, (float)fudesumiImage.height}; Rectangle fudesumiRec = {0, 0, (float)imFudesumi.width, (float)imFudesumi.height};
Rectangle fudesumiPos = {50, 10, fudesumiImage.width*0.8f, fudesumiImage.height*0.8f}; Rectangle fudesumiPos = {50, 10, imFudesumi.width*0.8f, imFudesumi.height*0.8f};
Rectangle redPos = { 410, 10, fudesumiPos.width/2.0f, fudesumiPos.height/2.0f }; Rectangle redPos = { 410, 10, fudesumiPos.width/2.0f, fudesumiPos.height/2.0f };
Rectangle greenPos = { 600, 10, fudesumiPos.width/2.0f, fudesumiPos.height/2.0f }; Rectangle greenPos = { 600, 10, fudesumiPos.width/2.0f, fudesumiPos.height/2.0f };
Rectangle bluePos = { 410, 230, fudesumiPos.width/2.0f, fudesumiPos.height/2.0f }; Rectangle bluePos = { 410, 230, fudesumiPos.width/2.0f, fudesumiPos.height/2.0f };
@ -84,13 +84,13 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
DrawTexture(backgroundTexture, 0, 0, WHITE); DrawTexture(texBackground, 0, 0, WHITE);
DrawTexturePro(fudesumiTexture, fudesumiRec, fudesumiPos, (Vector2) {0, 0}, 0, WHITE); DrawTexturePro(texFudesumi, fudesumiRec, fudesumiPos, (Vector2) {0, 0}, 0, WHITE);
DrawTexturePro(textureRed, fudesumiRec, redPos, (Vector2) {0, 0}, 0, RED); DrawTexturePro(texFudesumiRed, fudesumiRec, redPos, (Vector2) {0, 0}, 0, RED);
DrawTexturePro(textureGreen, fudesumiRec, greenPos, (Vector2) {0, 0}, 0, GREEN); DrawTexturePro(texFudesumiGreen, fudesumiRec, greenPos, (Vector2) {0, 0}, 0, GREEN);
DrawTexturePro(textureBlue, fudesumiRec, bluePos, (Vector2) {0, 0}, 0, BLUE); DrawTexturePro(texFudesumiBlue, fudesumiRec, bluePos, (Vector2) {0, 0}, 0, BLUE);
DrawTexturePro(textureAlpha, fudesumiRec, alphaPos, (Vector2) {0, 0}, 0, WHITE); DrawTexturePro(texFudesumiAlpha, fudesumiRec, alphaPos, (Vector2) {0, 0}, 0, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -98,12 +98,12 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(backgroundTexture); UnloadTexture(texBackground);
UnloadTexture(fudesumiTexture); UnloadTexture(texFudesumi);
UnloadTexture(textureRed); UnloadTexture(texFudesumiRed);
UnloadTexture(textureGreen); UnloadTexture(texFudesumiGreen);
UnloadTexture(textureBlue); UnloadTexture(texFudesumiBlue);
UnloadTexture(textureAlpha); UnloadTexture(texFudesumiAlpha);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -36,7 +36,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image kernel"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - image kernel");
Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM) Image imCat = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM)
float gaussiankernel[] = { float gaussiankernel[] = {
1.0f, 2.0f, 1.0f, 1.0f, 2.0f, 1.0f,
@ -60,36 +60,36 @@ int main(void)
NormalizeKernel(sharpenkernel, 9); NormalizeKernel(sharpenkernel, 9);
NormalizeKernel(sobelkernel, 9); NormalizeKernel(sobelkernel, 9);
Image catSharpend = ImageCopy(image); Image imCatSharpend = ImageCopy(imCat);
ImageKernelConvolution(&catSharpend, sharpenkernel, 9); ImageKernelConvolution(&imCatSharpend, sharpenkernel, 9);
Image catSobel = ImageCopy(image); Image imCatSobel = ImageCopy(imCat);
ImageKernelConvolution(&catSobel, sobelkernel, 9); ImageKernelConvolution(&imCatSobel, sobelkernel, 9);
Image catGaussian = ImageCopy(image); Image imCatGaussian = ImageCopy(imCat);
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
ImageKernelConvolution(&catGaussian, gaussiankernel, 9); ImageKernelConvolution(&imCatGaussian, gaussiankernel, 9);
} }
ImageCrop(&image, (Rectangle){ 0, 0, (float)200, (float)450 }); ImageCrop(&imCat, (Rectangle){ 0, 0, (float)200, (float)450 });
ImageCrop(&catGaussian, (Rectangle){ 0, 0, (float)200, (float)450 }); ImageCrop(&imCatGaussian, (Rectangle){ 0, 0, (float)200, (float)450 });
ImageCrop(&catSobel, (Rectangle){ 0, 0, (float)200, (float)450 }); ImageCrop(&imCatSobel, (Rectangle){ 0, 0, (float)200, (float)450 });
ImageCrop(&catSharpend, (Rectangle){ 0, 0, (float)200, (float)450 }); ImageCrop(&imCatSharpend, (Rectangle){ 0, 0, (float)200, (float)450 });
// Images converted to texture, GPU memory (VRAM) // Images converted to texture, GPU memory (VRAM)
Texture2D texture = LoadTextureFromImage(image); Texture2D texCat = LoadTextureFromImage(imCat);
Texture2D catSharpendTexture = LoadTextureFromImage(catSharpend); Texture2D texCatSharpend = LoadTextureFromImage(imCatSharpend);
Texture2D catSobelTexture = LoadTextureFromImage(catSobel); Texture2D texCatSobel = LoadTextureFromImage(imCatSobel);
Texture2D catGaussianTexture = LoadTextureFromImage(catGaussian); Texture2D texCatGaussian = LoadTextureFromImage(imCatGaussian);
// Once images have been converted to texture and uploaded to VRAM, // Once images have been converted to texture and uploaded to VRAM,
// they can be unloaded from RAM // they can be unloaded from RAM
UnloadImage(image); UnloadImage(imCat);
UnloadImage(catGaussian); UnloadImage(imCatGaussian);
UnloadImage(catSobel); UnloadImage(imCatSobel);
UnloadImage(catSharpend); UnloadImage(imCatSharpend);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
@ -108,10 +108,10 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(catSharpendTexture, 0, 0, WHITE); DrawTexture(texCatSharpend, 0, 0, WHITE);
DrawTexture(catSobelTexture, 200, 0, WHITE); DrawTexture(texCatSobel, 200, 0, WHITE);
DrawTexture(catGaussianTexture, 400, 0, WHITE); DrawTexture(texCatGaussian, 400, 0, WHITE);
DrawTexture(texture, 600, 0, WHITE); DrawTexture(texCat, 600, 0, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -119,10 +119,10 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); UnloadTexture(texCat);
UnloadTexture(catGaussianTexture); UnloadTexture(texCatGaussian);
UnloadTexture(catSobelTexture); UnloadTexture(texCatSobel);
UnloadTexture(catSharpendTexture); UnloadTexture(texCatSharpend);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -31,22 +31,20 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - magnifying glass"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - magnifying glass");
Texture2D bunny = LoadTexture("resources/raybunny.png"); Texture2D texBunny = LoadTexture("resources/raybunny.png");
Texture2D parrots = LoadTexture("resources/parrots.png"); Texture2D texParrots = LoadTexture("resources/parrots.png");
// Use image draw to generate a mask texture instead of loading it from a file. // Use image draw to generate a mask texture instead of loading it from a file.
Image circle = GenImageColor(256, 256, BLANK); Image imCircle = GenImageColor(256, 256, BLANK);
ImageDrawCircle(&circle, 128, 128, 128, WHITE); ImageDrawCircle(&imCircle, 128, 128, 128, WHITE);
Texture2D mask = LoadTextureFromImage(circle); // Copy the mask image from RAM to VRAM Texture2D texMask = LoadTextureFromImage(imCircle);
UnloadImage(circle); // Unload the image from RAM UnloadImage(imCircle);
RenderTexture2D magnifiedWorld = LoadRenderTexture(256, 256); RenderTexture2D rtMagnifiedWorld = LoadRenderTexture(256, 256);
Camera2D camera = { 0 }; Camera2D camera = { 0 };
// Set magnifying glass zoom camera.zoom = 2; // Set magnifying glass zoom
camera.zoom = 2; camera.offset = (Vector2){ 128, 128 }; // Offset by half the size of the magnifying glass
// Offset by half the size of the magnifying glass to counteract drawing the texture centered on the mouse position
camera.offset = (Vector2){ 128, 128 };
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -56,9 +54,8 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
Vector2 mPos = GetMousePosition(); Vector2 mousePosition = GetMousePosition();
camera.target = mPos; camera.target = mousePosition;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -68,25 +65,25 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Draw the normal version of the world // Draw the normal version of the world
DrawTexture(parrots, 144, 33, WHITE); DrawTexture(texParrots, 144, 33, WHITE);
DrawText("Use the magnifying glass to find hidden bunnies!", 154, 6, 20, BLACK); DrawText("Use the magnifying glass to find hidden bunnies!", 154, 6, 20, BLACK);
// Render to a the magnifying glass // Render to a the magnifying glass
BeginTextureMode(magnifiedWorld); BeginTextureMode(rtMagnifiedWorld);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode2D(camera); BeginMode2D(camera);
// Draw the same things in the magnified world as were in the normal version // Draw the same things in the magnified world as were in the normal version
DrawTexture(parrots, 144, 33, WHITE); DrawTexture(texParrots, 144, 33, WHITE);
DrawText("Use the magnifying glass to find hidden bunnies!", 154, 6, 20, BLACK); DrawText("Use the magnifying glass to find hidden bunnies!", 154, 6, 20, BLACK);
// Draw bunnies only in the magnified world. // Draw bunnies only in the magnified world.
// BLEND_MULTIPLIED lets them take on the color of the image below them. // BLEND_MULTIPLIED lets them take on the color of the image below them.
BeginBlendMode(BLEND_MULTIPLIED); BeginBlendMode(BLEND_MULTIPLIED);
DrawTexture(bunny, 250, 350, WHITE); DrawTexture(texBunny, 250, 350, WHITE);
DrawTexture(bunny, 500, 100, WHITE); DrawTexture(texBunny, 500, 100, WHITE);
DrawTexture(bunny, 420, 300, WHITE); DrawTexture(texBunny, 420, 300, WHITE);
DrawTexture(bunny, 650, 10, WHITE); DrawTexture(texBunny, 650, 10, WHITE);
EndBlendMode(); EndBlendMode();
EndMode2D(); EndMode2D();
@ -101,20 +98,20 @@ int main(void)
// glEqRGB: RL_FUNC_ADD - Cs(0) + Cd = Cd - destination color is unmodified // glEqRGB: RL_FUNC_ADD - Cs(0) + Cd = Cd - destination color is unmodified
// glEqAlpha: RL_FUNC_ADD - As + Ad(0) = As - destination alpha is set to source alpha // glEqAlpha: RL_FUNC_ADD - As + Ad(0) = As - destination alpha is set to source alpha
rlSetBlendFactorsSeparate(RL_ZERO, RL_ONE, RL_ONE, RL_ZERO, RL_FUNC_ADD, RL_FUNC_ADD); rlSetBlendFactorsSeparate(RL_ZERO, RL_ONE, RL_ONE, RL_ZERO, RL_FUNC_ADD, RL_FUNC_ADD);
DrawTexture(mask, 0, 0, WHITE); DrawTexture(texMask, 0, 0, WHITE);
EndBlendMode(); EndBlendMode();
EndTextureMode(); EndTextureMode();
// Draw magnifiedWorld to screen, centered on cursor // Draw magnifiedWorld to screen, centered on cursor
DrawTextureRec(magnifiedWorld.texture, (Rectangle){0, 0, 256, -256}, (Vector2){mPos.x - 128, mPos.y - 128}, WHITE); DrawTextureRec(rtMagnifiedWorld.texture, (Rectangle){0, 0, 256, -256}, (Vector2){mousePosition.x - 128, mousePosition.y - 128}, WHITE);
// Draw the outer ring of the magnifying glass // Draw the outer ring of the magnifying glass
DrawRing(mPos, 126, 130, 0, 360, 64, BLACK); DrawRing(mousePosition, 126, 130, 0, 360, 64, BLACK);
// Draw floating specular highlight on the glass // Draw floating specular highlight on the glass
float rx = mPos.x/800; float rx = mousePosition.x/800;
float ry = mPos.y/800; float ry = mousePosition.y/800;
DrawCircle((int)(mPos.x - 64*rx) - 32, (int)(mPos.y - 64*ry) - 32, 4, ColorAlpha(WHITE, 0.5)); DrawCircle((int)(mousePosition.x - 64*rx) - 32, (int)(mousePosition.y - 64*ry) - 32, 4, ColorAlpha(WHITE, 0.5));
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -122,10 +119,10 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(parrots); UnloadTexture(texParrots);
UnloadTexture(bunny); UnloadTexture(texBunny);
UnloadTexture(mask); UnloadTexture(texMask);
UnloadRenderTexture(magnifiedWorld); UnloadRenderTexture(rtMagnifiedWorld);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -32,7 +32,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - npatch drawing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - npatch drawing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png"); Texture2D texNPatch = LoadTexture("resources/ninepatch_button.png");
Vector2 mousePosition = { 0 }; Vector2 mousePosition = { 0 };
Vector2 origin = { 0.0f, 0.0f }; Vector2 origin = { 0.0f, 0.0f };
@ -89,14 +89,14 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Draw the n-patches // Draw the n-patches
DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE); DrawTextureNPatch(texNPatch, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE);
DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); DrawTextureNPatch(texNPatch, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE);
DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); DrawTextureNPatch(texNPatch, h3PatchInfo, dstRecH, origin, 0.0f, WHITE);
DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); DrawTextureNPatch(texNPatch, v3PatchInfo, dstRecV, origin, 0.0f, WHITE);
// Draw the source texture // Draw the source texture
DrawRectangleLines(5, 88, 74, 266, BLUE); DrawRectangleLines(5, 88, 74, 266, BLUE);
DrawTexture(nPatchTexture, 10, 93, WHITE); DrawTexture(texNPatch, 10, 93, WHITE);
DrawText("TEXTURE", 15, 360, 10, DARKGRAY); DrawText("TEXTURE", 15, 360, 10, DARKGRAY);
DrawText("Move the mouse to stretch or shrink the n-patches", 10, 20, 20, DARKGRAY); DrawText("Move the mouse to stretch or shrink the n-patches", 10, 20, 20, DARKGRAY);
@ -107,7 +107,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(nPatchTexture); // Texture unloading UnloadTexture(texNPatch); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -42,7 +42,10 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending");
// Particles pool, reuse them! // Load smoke particle
Texture2D texSmoke = LoadTexture("resources/spark_flame.png");
// Particles pool, reusing them
Particle mouseTail[MAX_PARTICLES] = { 0 }; Particle mouseTail[MAX_PARTICLES] = { 0 };
// Initialize particles // Initialize particles
@ -57,9 +60,6 @@ int main(void)
} }
float gravity = 3.0f; float gravity = 3.0f;
Texture2D smoke = LoadTexture("resources/spark_flame.png");
int blending = BLEND_ALPHA; int blending = BLEND_ALPHA;
SetTargetFPS(60); SetTargetFPS(60);
@ -70,7 +70,6 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Activate one particle every frame and Update active particles // Activate one particle every frame and Update active particles
// NOTE: Particles initial position should be mouse position when activated // NOTE: Particles initial position should be mouse position when activated
// NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0) // NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0)
@ -117,10 +116,11 @@ int main(void)
// Draw active particles // Draw active particles
for (int i = 0; i < MAX_PARTICLES; i++) for (int i = 0; i < MAX_PARTICLES; i++)
{ {
if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0.0f, 0.0f, (float)smoke.width, (float)smoke.height }, if (mouseTail[i].active)
(Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size }, DrawTexturePro(texSmoke, (Rectangle){ 0.0f, 0.0f, (float)texSmoke.width, (float)texSmoke.height },
(Vector2){ (float)(smoke.width*mouseTail[i].size/2.0f), (float)(smoke.height*mouseTail[i].size/2.0f) }, mouseTail[i].rotation, (Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, texSmoke.width*mouseTail[i].size, texSmoke.height*mouseTail[i].size },
Fade(mouseTail[i].color, mouseTail[i].alpha)); (Vector2){ (float)(texSmoke.width*mouseTail[i].size/2.0f), (float)(texSmoke.height*mouseTail[i].size/2.0f) }, mouseTail[i].rotation,
Fade(mouseTail[i].color, mouseTail[i].alpha));
} }
EndBlendMode(); EndBlendMode();
@ -136,7 +136,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(smoke); UnloadTexture(texSmoke);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -67,9 +67,9 @@ int main(void)
for (int i = 0; i < MAX_POINTS; i++) positions[i] = points[i]; for (int i = 0; i < MAX_POINTS; i++) positions[i] = points[i];
// Load texture to be mapped to poly // Load texture to be mapped to poly
Texture texture = LoadTexture("resources/cat.png"); Texture2D texture = LoadTexture("resources/cat.png");
float angle = 0.0f; // Rotation angle (in degrees) float angle = 0.0f; // Rotation angle (in degrees)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -65,9 +65,10 @@ int main(void)
// and window position, shifted by the offset between the two portals // and window position, shifted by the offset between the two portals
Vector3 portalA = { 0.0f, 0.0f, 0.0f }; Vector3 portalA = { 0.0f, 0.0f, 0.0f };
Vector3 portalB = { 0.0f, 0.0f, -60.0f }; Vector3 portalB = { 0.0f, 0.0f, -60.0f };
RenderTexture2D portalView = LoadRenderTexture(480, 640); RenderTexture2D rtPortalView = LoadRenderTexture(480, 640);
DisableCursor(); // Lock cursor for first-person free camera controls
DisableCursor(); // Lock cursor for first-person free camera controls
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -92,7 +93,7 @@ int main(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Render Dimension B into an offscreen texture, using an oblique projection so // Render Dimension B into an offscreen texture, using an oblique projection so
// its perspective lines up with the archway exactly as the real camera sees it // its perspective lines up with the archway exactly as the real camera sees it
BeginTextureMode(portalView); BeginTextureMode(rtPortalView);
ClearBackground((Color){ 10, 5, 20, 255 }); ClearBackground((Color){ 10, 5, 20, 255 });
@ -145,7 +146,7 @@ int main(void)
// The portal opening itself: a plain quad textured with the Dimension B // The portal opening itself: a plain quad textured with the Dimension B
// render, filling the archway exactly, so nothing "leaks" outside its shape // render, filling the archway exactly, so nothing "leaks" outside its shape
rlSetTexture(portalView.texture.id); rlSetTexture(rtPortalView.texture.id);
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(255, 255, 255, 255); rlColor4ub(255, 255, 255, 255);
rlNormal3f(0.0f, 0.0f, 1.0f); rlNormal3f(0.0f, 0.0f, 1.0f);
@ -171,7 +172,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadRenderTexture(portalView); UnloadRenderTexture(rtPortalView);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -32,9 +32,9 @@ int main(void)
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// Load RAW image data (512x512, 32bit RGBA, no file header) // Load RAW image data (512x512, 32bit RGBA, no file header)
Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 0); Image imFudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 0);
Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) Texture2D texFudesumi = LoadTextureFromImage(imFudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM)
UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data UnloadImage(imFudesumiRaw); // Unload CPU (RAM) image data
// Generate a checked texture by code // Generate a checked texture by code
int imWidth = 960; int imWidth = 960;
@ -58,7 +58,7 @@ int main(void)
// Load pixels data into an image structure and create texture // Load pixels data into an image structure and create texture
// NOTE: We can assign pixels directly to data because Color is R8G8B8A8 // NOTE: We can assign pixels directly to data because Color is R8G8B8A8
// data structure defining that pixelformat, format must be set properly // data structure defining that pixelformat, format must be set properly
Image checkedIm = { Image imChecked = {
.data = pixels, .data = pixels,
.width = imWidth, .width = imWidth,
.height = imHeight, .height = imHeight,
@ -66,8 +66,8 @@ int main(void)
.mipmaps = 1 .mipmaps = 1
}; };
Texture2D checked = LoadTextureFromImage(checkedIm); Texture2D texChecked = LoadTextureFromImage(imChecked);
UnloadImage(checkedIm); // Unload CPU (RAM) image data (pixels) UnloadImage(imChecked); // Unload CPU (RAM) image data (pixels)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
@ -86,8 +86,8 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f)); DrawTexture(texChecked, screenWidth/2 - texChecked.width/2, screenHeight/2 - texChecked.height/2, Fade(WHITE, 0.5f));
DrawTexture(fudesumi, 430, -30, WHITE); DrawTexture(texFudesumi, 430, -30, WHITE);
DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN); DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN);
DrawText("GENERATED by CODE", 72, 148, 30, BROWN); DrawText("GENERATED by CODE", 72, 148, 30, BROWN);
@ -101,8 +101,8 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(fudesumi); // Texture unloading UnloadTexture(texFudesumi); // Texture unloading
UnloadTexture(checked); // Texture unloading UnloadTexture(texChecked); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -42,8 +42,8 @@ int main(void)
unsigned char *indexBuffer = RL_CALLOC(imageWidth*imageWidth, sizeof(unsigned char)); unsigned char *indexBuffer = RL_CALLOC(imageWidth*imageWidth, sizeof(unsigned char));
unsigned char *flameRootBuffer = RL_CALLOC(flameWidth, sizeof(unsigned char)); unsigned char *flameRootBuffer = RL_CALLOC(flameWidth, sizeof(unsigned char));
Image screenImage = GenImageColor(imageWidth, imageHeight, BLACK); Image imScreen = GenImageColor(imageWidth, imageHeight, BLACK);
Texture screenTexture = LoadTextureFromImage(screenImage); Texture2D texScreen = LoadTextureFromImage(imScreen);
// Generate flame color palette // Generate flame color palette
for (int i = 0; i < MAX_COLORS; i++) for (int i = 0; i < MAX_COLORS; i++)
@ -120,11 +120,11 @@ int main(void)
unsigned char colorIndex = indexBuffer[i]; unsigned char colorIndex = indexBuffer[i];
Color col = palette[colorIndex]; Color col = palette[colorIndex];
ImageDrawPixel(&screenImage, x, y, col); ImageDrawPixel(&imScreen, x, y, col);
} }
} }
UpdateTexture(screenTexture, screenImage.data); UpdateTexture(texScreen, imScreen.data);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -133,7 +133,7 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextureEx(screenTexture, (Vector2){ 0, 0 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texScreen, (Vector2){ 0, 0 }, 0.0f, 2.0f, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -143,8 +143,8 @@ int main(void)
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
RL_FREE(indexBuffer); RL_FREE(indexBuffer);
RL_FREE(flameRootBuffer); RL_FREE(flameRootBuffer);
UnloadTexture(screenTexture); UnloadTexture(texScreen);
UnloadImage(screenImage); UnloadImage(imScreen);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -31,10 +31,12 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite animation"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite animation");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
// Load spritesheet animation, 6 frames width
Texture2D texture = LoadTexture("resources/scarfy.png");
Vector2 position = { 350.0f, 280.0f }; Vector2 position = { 350.0f, 280.0f };
Rectangle frameRec = { 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height }; Rectangle frameRec = { 0.0f, 0.0f, (float)texture.width/6, (float)texture.height };
int currentFrame = 0; int currentFrame = 0;
int framesCounter = 0; int framesCounter = 0;
@ -57,7 +59,7 @@ int main(void)
if (currentFrame > 5) currentFrame = 0; if (currentFrame > 5) currentFrame = 0;
frameRec.x = (float)currentFrame*(float)scarfy.width/6; frameRec.x = (float)currentFrame*(float)texture.width/6;
} }
// Control frames speed // Control frames speed
@ -74,8 +76,8 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(scarfy, 15, 40, WHITE); DrawTexture(texture, 15, 40, WHITE);
DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); DrawRectangleLines(15, 40, texture.width, texture.height, LIME);
DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED); DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED);
DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY);
@ -88,9 +90,9 @@ int main(void)
DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON);
} }
DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture DrawTextureRec(texture, frameRec, position, WHITE); // Draw part of the texture
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Scarfy spritesheet by Eiden Marsal", screenWidth - 220, screenHeight - 20, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -98,7 +100,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(scarfy); // Texture unloading UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -31,15 +31,15 @@ int main(void)
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
Sound fxButton = LoadSound("resources/buttonfx.wav"); // Load button sound Sound fxButton = LoadSound("resources/buttonfx.wav"); // Load button sound
Texture2D button = LoadTexture("resources/button.png"); // Load button texture Texture2D texButton = LoadTexture("resources/button.png"); // Load button texture
// Define frame rectangle for drawing // Define frame rectangle for drawing
float frameHeight = (float)button.height/NUM_FRAMES; float frameHeight = (float)texButton.height/NUM_FRAMES;
Rectangle sourceRec = { 0, 0, (float)button.width, frameHeight }; Rectangle sourceRec = { 0, 0, (float)texButton.width, frameHeight };
// Define button bounds on screen // Define button bounds on screen
Rectangle btnBounds = { screenWidth/2.0f - button.width/2.0f, screenHeight/2.0f - (float)button.height/NUM_FRAMES/2.0f, (float)button.width, frameHeight }; Rectangle btnBounds = { screenWidth/2.0f - texButton.width/2.0f, screenHeight/2.0f - (float)texButton.height/NUM_FRAMES/2.0f, (float)texButton.width, frameHeight };
int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED
bool btnAction = false; // Button action should be activated bool btnAction = false; // Button action should be activated
@ -84,7 +84,7 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextureRec(button, sourceRec, (Vector2){ btnBounds.x, btnBounds.y }, WHITE); // Draw button frame DrawTextureRec(texButton, sourceRec, (Vector2){ btnBounds.x, btnBounds.y }, WHITE); // Draw button frame
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -92,7 +92,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(button); // Unload button texture UnloadTexture(texButton); // Unload button texture
UnloadSound(fxButton); // Unload sound UnloadSound(fxButton); // Unload sound
CloseAudioDevice(); // Close audio device CloseAudioDevice(); // Close audio device

View File

@ -36,11 +36,11 @@ int main(void)
Sound fxBoom = LoadSound("resources/boom.wav"); Sound fxBoom = LoadSound("resources/boom.wav");
// Load explosion texture // Load explosion texture
Texture2D explosion = LoadTexture("resources/explosion.png"); Texture2D texExplosion = LoadTexture("resources/explosion.png");
// Init variables for animation // Init variables for animation
float frameWidth = (float)explosion.width/NUM_FRAMES_PER_LINE; // Sprite one frame rectangle width float frameWidth = (float)texExplosion.width/NUM_FRAMES_PER_LINE; // Sprite one frame rectangle width
float frameHeight = (float)explosion.height/NUM_LINES; // Sprite one frame rectangle height float frameHeight = (float)texExplosion.height/NUM_LINES; // Sprite one frame rectangle height
int currentFrame = 0; int currentFrame = 0;
int currentLine = 0; int currentLine = 0;
@ -107,7 +107,7 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Draw explosion required frame rectangle // Draw explosion required frame rectangle
if (active) DrawTextureRec(explosion, frameRec, position, WHITE); if (active) DrawTextureRec(texExplosion, frameRec, position, WHITE);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -115,7 +115,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(explosion); // Unload texture UnloadTexture(texExplosion); // Unload texture
UnloadSound(fxBoom); // Unload sound UnloadSound(fxBoom); // Unload sound
CloseAudioDevice(); CloseAudioDevice();

View File

@ -32,7 +32,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite stacking"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite stacking");
Texture2D booth = LoadTexture("resources/booth.png"); Texture2D texBooth = LoadTexture("resources/booth.png");
float stackScale = 3.0f; // Overall scale of the stacked sprite float stackScale = 3.0f; // Overall scale of the stacked sprite
float stackSpacing = 2.0f; // Vertical spacing between each layer float stackSpacing = 2.0f; // Vertical spacing between each layer
@ -67,8 +67,8 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
// Get the size of a single slice // Get the size of a single slice
float frameWidth = (float)booth.width; float frameWidth = (float)texBooth.width;
float frameHeight = (float)booth.height/(float)stackCount; float frameHeight = (float)texBooth.height/(float)stackCount;
// Get the scaled resolution to draw at // Get the scaled resolution to draw at
float scaledWidth = frameWidth*stackScale; float scaledWidth = frameWidth*stackScale;
@ -82,7 +82,7 @@ int main(void)
Rectangle dest = { screenWidth/2.0f, (screenHeight/2.0f) + (i*stackSpacing) - (stackSpacing*stackCount/2.0f), scaledWidth, scaledHeight }; Rectangle dest = { screenWidth/2.0f, (screenHeight/2.0f) + (i*stackSpacing) - (stackSpacing*stackCount/2.0f), scaledWidth, scaledHeight };
Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f }; Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f };
DrawTexturePro(booth, source, dest, origin, rotation, WHITE); DrawTexturePro(texBooth, source, dest, origin, rotation, WHITE);
} }
DrawText("A/D to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY); DrawText("A/D to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY);
@ -96,7 +96,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(booth); UnloadTexture(texBooth);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View File

@ -2,9 +2,9 @@
* *
* raylib [textures] example - srcrec dstrec * raylib [textures] example - srcrec dstrec
* *
* Example complexity rating: [★★★☆] 3/4 * Example complexity rating: [★★☆☆] 2/4
* *
* Example originally created with raylib 1.3, last time updated with raylib 1.3 * Example originally created with raylib 1.3, last time updated with raylib 6.2
* *
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software * BSD-like license that allows static linking with closed source software
@ -27,23 +27,26 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - srcrec dstrec"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - srcrec dstrec");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // Load texture, spritesheet of character containing 6 frames
Texture2D texture = LoadTexture("resources/scarfy.png");
Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading // NOTE: Spritesheet contains 6 frames in horizontal,
// so dividing by 6 to get the width of one frame
int frameWidth = texture.width/6;
int frameHeight = texture.height;
int frameWidth = scarfy.width/6; // Source rectangle: rectangle piece of the texture to use for drawing
int frameHeight = scarfy.height;
// Source rectangle (part of the texture to use for drawing)
Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight }; Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight };
// Destination rectangle (screen rectangle where drawing part of texture) // Destination rectangle: screen-coordinates rectangle to draw the source part of texture
// NOTE: Defines position on screen and scaling, set to center of screen with a scale x2
Rectangle destRec = { screenWidth/2.0f, screenHeight/2.0f, frameWidth*2.0f, frameHeight*2.0f }; Rectangle destRec = { screenWidth/2.0f, screenHeight/2.0f, frameWidth*2.0f, frameHeight*2.0f };
// Origin of the texture (rotation/scale point), it's relative to destination rectangle size // Origin of the texture (rotation/scale point)
Vector2 origin = { (float)frameWidth, (float)frameHeight }; // NOTE: Relative to destination rectangle size, set at the center of it
Vector2 origin = { (float)destRec.width/2, (float)destRec.height/2 };
int rotation = 0; int rotation = 0; // Rotation in degrees
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -67,12 +70,12 @@ int main(void)
// destRec defines the rectangle where our texture part will fit (scaling it to fit) // destRec defines the rectangle where our texture part will fit (scaling it to fit)
// origin defines the point of the texture used as reference for rotation and scaling // origin defines the point of the texture used as reference for rotation and scaling
// rotation defines the texture rotation (using origin as rotation point) // rotation defines the texture rotation (using origin as rotation point)
DrawTexturePro(scarfy, sourceRec, destRec, origin, (float)rotation, WHITE); DrawTexturePro(texture, sourceRec, destRec, origin, (float)rotation, WHITE);
DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY); DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY);
DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY);
DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawText("(c) Scarfy spritesheet by Eiden Marsal", screenWidth - 220, screenHeight - 20, 10, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -80,10 +83,10 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(scarfy); // Texture unloading UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;
} }

View File

@ -26,7 +26,7 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static Texture texRoad = { 0 }; static Texture2D texRoad = { 0 };
static bool showCurve = false; static bool showCurve = false;

View File

@ -39,7 +39,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [textures] example - tiled drawing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - tiled drawing");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture texPattern = LoadTexture("resources/patterns.png"); Texture2D texPattern = LoadTexture("resources/patterns.png");
SetTextureFilter(texPattern, TEXTURE_FILTER_BILINEAR); // Makes the texture smoother when upscaled SetTextureFilter(texPattern, TEXTURE_FILTER_BILINEAR); // Makes the texture smoother when upscaled
// Coordinates for all patterns inside the texture // Coordinates for all patterns inside the texture

View File

@ -1695,22 +1695,17 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
#if SUPPORT_FILEFORMAT_MOD #if SUPPORT_FILEFORMAT_MOD
else if ((strcmp(fileType, ".mod") == 0) || (strcmp(fileType, ".MOD") == 0)) else if ((strcmp(fileType, ".mod") == 0) || (strcmp(fileType, ".MOD") == 0))
{ {
jar_mod_context_t *ctxMod = (jar_mod_context_t *)RL_CALLOC(1, sizeof(jar_mod_context_t));
int result = 0; int result = 0;
jar_mod_context_t *ctxMod = (jar_mod_context_t *)RL_CALLOC(1, sizeof(jar_mod_context_t));
jar_mod_init(ctxMod); jar_mod_init(ctxMod);
// Copy data to allocated memory for default UnloadMusicStream // Load XM file data from memory buffer
unsigned char *newData = (unsigned char *)RL_CALLOC(dataSize, 1); unsigned char *newData = (unsigned char *)RL_CALLOC(dataSize, 1);
for (int i = 0; i < dataSize; i++) newData[i] = data[i]; memcpy(newData, data, dataSize);
// Memory loaded version for jar_mod_load_file() ctxMod->modfile = newData;
if (dataSize && (dataSize < 32*1024*1024)) ctxMod->modfilesize = dataSize;
{ if (jar_mod_load(ctxMod, (void *)ctxMod->modfile, dataSize)) result = dataSize;
ctxMod->modfilesize = dataSize;
ctxMod->modfile = newData;
if (jar_mod_load(ctxMod, (void *)ctxMod->modfile, dataSize)) result = dataSize;
}
if (result > 0) if (result > 0)
{ {

View File

@ -493,7 +493,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK; for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK;
// Create a new image with the processed color data (key color replaced by BLANK) // Create a new image with the processed color data (key color replaced by BLANK)
Image fontClear = { Image imFontClear = {
.data = pixels, .data = pixels,
.width = image.width, .width = image.width,
.height = image.height, .height = image.height,
@ -502,7 +502,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
}; };
// Set font with all data parsed from image // Set font with all data parsed from image
font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture font.texture = LoadTextureFromImage(imFontClear); // Convert processed image to OpenGL texture
font.glyphCount = index; font.glyphCount = index;
font.glyphPadding = 0; font.glyphPadding = 0;
@ -523,11 +523,11 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
font.glyphs[i].offsetY = 0; font.glyphs[i].offsetY = 0;
font.glyphs[i].advanceX = 0; font.glyphs[i].advanceX = 0;
// Fill character image data from fontClear data // Fill character image data from imFontClear data
font.glyphs[i].image = ImageFromImage(fontClear, tempCharRecs[i]); font.glyphs[i].image = ImageFromImage(imFontClear, tempCharRecs[i]);
} }
UnloadImage(fontClear); // Unload processed image once converted to texture UnloadImage(imFontClear); // Unload processed image once converted to texture
font.baseSize = (int)font.recs[0].height; font.baseSize = (int)font.recs[0].height;
@ -570,17 +570,17 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
{ {
font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING; font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING;
Image atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0); Image imAtlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0);
font.texture = LoadTextureFromImage(atlas); font.texture = LoadTextureFromImage(imAtlas);
// Update glyphs[i].image to use alpha, required to be used on ImageDrawText() // Update glyphs[i].image to use alpha, required to be used on ImageDrawText()
for (int i = 0; i < font.glyphCount; i++) for (int i = 0; i < font.glyphCount; i++)
{ {
UnloadImage(font.glyphs[i].image); UnloadImage(font.glyphs[i].image);
font.glyphs[i].image = ImageFromImage(atlas, font.recs[i]); font.glyphs[i].image = ImageFromImage(imAtlas, font.recs[i]);
} }
UnloadImage(atlas); UnloadImage(imAtlas);
TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount); TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount);
} }
@ -809,12 +809,12 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
#if SUPPORT_FILEFORMAT_TTF || SUPPORT_FILEFORMAT_BDF #if SUPPORT_FILEFORMAT_TTF || SUPPORT_FILEFORMAT_BDF
Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod) Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod)
{ {
Image atlas = { 0 }; Image imAtlas = { 0 };
if (glyphs == NULL) if (glyphs == NULL)
{ {
TRACELOG(LOG_WARNING, "FONT: Provided glyphs info not valid, returning empty image atlas"); TRACELOG(LOG_WARNING, "FONT: Provided glyphs info not valid, returning empty image atlas");
return atlas; return imAtlas;
} }
*glyphRecs = NULL; *glyphRecs = NULL;
@ -846,22 +846,22 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
if (totalArea < ((imageSize*imageSize)/2)) if (totalArea < ((imageSize*imageSize)/2))
{ {
atlas.width = imageSize; // Atlas bitmap width imAtlas.width = imageSize; // Atlas bitmap width
atlas.height = imageSize/2; // Atlas bitmap height imAtlas.height = imageSize/2; // Atlas bitmap height
} }
else else
{ {
atlas.width = imageSize; // Atlas bitmap width imAtlas.width = imageSize; // Atlas bitmap width
atlas.height = imageSize; // Atlas bitmap height imAtlas.height = imageSize; // Atlas bitmap height
} }
int atlasDataSize = atlas.width*atlas.height; // Save total size for bounds checking int atlasDataSize = imAtlas.width*imAtlas.height; // Save total size for bounds checking
atlas.data = (unsigned char *)RL_CALLOC(atlasDataSize, 1); // Create a bitmap to store characters (8 bpp) imAtlas.data = (unsigned char *)RL_CALLOC(atlasDataSize, 1); // Create a bitmap to store characters (8 bpp)
atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; imAtlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
atlas.mipmaps = 1; imAtlas.mipmaps = 1;
// DEBUG: View padding in the generated image setting a gray background... // DEBUG: View padding in the generated image setting a gray background...
//for (int i = 0; i < atlas.width*atlas.height; i++) ((unsigned char *)atlas.data)[i] = 100; //for (int i = 0; i < imAtlas.width*imAtlas.height; i++) ((unsigned char *)imAtlas.data)[i] = 100;
if (packMethod == 0) // Use basic packing algorithm if (packMethod == 0) // Use basic packing algorithm
{ {
@ -872,7 +872,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
for (int i = 0; i < glyphCount; i++) for (int i = 0; i < glyphCount; i++)
{ {
// Check remaining space for glyph // Check remaining space for glyph
if (offsetX >= (atlas.width - glyphs[i].image.width - 2*padding)) if (offsetX >= (imAtlas.width - glyphs[i].image.width - 2*padding))
{ {
offsetX = padding; offsetX = padding;
@ -881,19 +881,19 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
// height is bigger than fontSize, it could be up to (fontSize + 8) // height is bigger than fontSize, it could be up to (fontSize + 8)
offsetY += (fontSize + 2*padding); offsetY += (fontSize + 2*padding);
if (offsetY > (atlas.height - fontSize - padding)) if (offsetY > (imAtlas.height - fontSize - padding))
{ {
TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters"); TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters");
// Update atlas size to fit all characters // Update atlas size to fit all characters
int updatedAtlasHeight = atlas.height*2; int updatedAtlasHeight = imAtlas.height*2;
int updatedAtlasDataSize = atlas.width*updatedAtlasHeight; int updatedAtlasDataSize = imAtlas.width*updatedAtlasHeight;
unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1); unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1);
memcpy(updatedAtlasData, atlas.data, atlasDataSize); memcpy(updatedAtlasData, imAtlas.data, atlasDataSize);
RL_FREE(atlas.data); RL_FREE(imAtlas.data);
atlas.data = updatedAtlasData; imAtlas.data = updatedAtlasData;
atlas.height = updatedAtlasHeight; imAtlas.height = updatedAtlasHeight;
atlasDataSize = updatedAtlasDataSize; atlasDataSize = updatedAtlasDataSize;
} }
} }
@ -907,9 +907,9 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
int destY = offsetY + y; int destY = offsetY + y;
// Security: check both lower and upper bounds // Security: check both lower and upper bounds
if ((destX >= 0) && (destX < atlas.width) && (destY >= 0) && (destY < atlas.height)) if ((destX >= 0) && (destX < imAtlas.width) && (destY >= 0) && (destY < imAtlas.height))
{ {
((unsigned char *)atlas.data)[destY*atlas.width + destX] = ((unsigned char *)imAtlas.data)[destY*imAtlas.width + destX] =
((unsigned char *)glyphs[i].image.data)[y*glyphs[i].image.width + x]; ((unsigned char *)glyphs[i].image.data)[y*glyphs[i].image.width + x];
} }
} }
@ -930,7 +930,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
stbrp_context *context = (stbrp_context *)RL_CALLOC(1, sizeof(stbrp_context)); stbrp_context *context = (stbrp_context *)RL_CALLOC(1, sizeof(stbrp_context));
stbrp_node *nodes = (stbrp_node *)RL_CALLOC(glyphCount, sizeof(stbrp_node)); stbrp_node *nodes = (stbrp_node *)RL_CALLOC(glyphCount, sizeof(stbrp_node));
stbrp_init_target(context, atlas.width, atlas.height, nodes, glyphCount); stbrp_init_target(context, imAtlas.width, imAtlas.height, nodes, glyphCount);
stbrp_rect *rects = (stbrp_rect *)RL_CALLOC(glyphCount, sizeof(stbrp_rect)); stbrp_rect *rects = (stbrp_rect *)RL_CALLOC(glyphCount, sizeof(stbrp_rect));
// Fill rectangles for packaging // Fill rectangles for packaging
@ -963,9 +963,9 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
int destY = rects[i].y + padding + y; int destY = rects[i].y + padding + y;
// Security fix: check both lower and upper bounds // Security fix: check both lower and upper bounds
if (destX >= 0 && destX < atlas.width && destY >= 0 && destY < atlas.height) if (destX >= 0 && destX < imAtlas.width && destY >= 0 && destY < imAtlas.height)
{ {
((unsigned char *)atlas.data)[destY*atlas.width + destX] = ((unsigned char *)imAtlas.data)[destY*imAtlas.width + destX] =
((unsigned char *)glyphs[i].image.data)[y*glyphs[i].image.width + x]; ((unsigned char *)glyphs[i].image.data)[y*glyphs[i].image.width + x];
} }
} }
@ -982,33 +982,33 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
// Add a 3x3 white rectangle at the bottom-right corner of the generated atlas, // Add a 3x3 white rectangle at the bottom-right corner of the generated atlas,
// useful to use as the white texture to draw shapes with raylib // useful to use as the white texture to draw shapes with raylib
// Security: ensure the atlas is large enough to hold a 3x3 rectangle // Security: ensure the atlas is large enough to hold a 3x3 rectangle
if ((FONT_ATLAS_CORNER_REC_SIZE > 0) && (atlas.width >= 3) && (atlas.height >= 3)) if ((FONT_ATLAS_CORNER_REC_SIZE > 0) && (imAtlas.width >= 3) && (imAtlas.height >= 3))
{ {
for (int i = 0, k = atlas.width*atlas.height - 1; i < FONT_ATLAS_CORNER_REC_SIZE; i++) for (int i = 0, k = imAtlas.width*imAtlas.height - 1; i < FONT_ATLAS_CORNER_REC_SIZE; i++)
{ {
((unsigned char *)atlas.data)[k - 0] = 255; ((unsigned char *)imAtlas.data)[k - 0] = 255;
((unsigned char *)atlas.data)[k - 1] = 255; ((unsigned char *)imAtlas.data)[k - 1] = 255;
((unsigned char *)atlas.data)[k - 2] = 255; ((unsigned char *)imAtlas.data)[k - 2] = 255;
k -= atlas.width; k -= imAtlas.width;
} }
} }
// Convert image data from GRAYSCALE to GRAY_ALPHA // Convert image data from GRAYSCALE to GRAY_ALPHA
unsigned char *dataGrayAlpha = (unsigned char *)RL_CALLOC(atlas.width*atlas.height*2, sizeof(unsigned char)); // Two channels unsigned char *dataGrayAlpha = (unsigned char *)RL_CALLOC(imAtlas.width*imAtlas.height*2, sizeof(unsigned char)); // Two channels
for (int i = 0, k = 0; i < atlas.width*atlas.height; i++, k += 2) for (int i = 0, k = 0; i < imAtlas.width*imAtlas.height; i++, k += 2)
{ {
dataGrayAlpha[k] = 255; dataGrayAlpha[k] = 255;
dataGrayAlpha[k + 1] = ((unsigned char *)atlas.data)[i]; dataGrayAlpha[k + 1] = ((unsigned char *)imAtlas.data)[i];
} }
RL_FREE(atlas.data); RL_FREE(imAtlas.data);
atlas.data = dataGrayAlpha; imAtlas.data = dataGrayAlpha;
atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA; imAtlas.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA;
*glyphRecs = recs; *glyphRecs = recs;
return atlas; return imAtlas;
} }
#endif #endif
@ -1646,7 +1646,11 @@ int TextToInteger(const char *text)
// WARNING: Only '.' character is understood as decimal point // WARNING: Only '.' character is understood as decimal point
float TextToFloat(const char *text) float TextToFloat(const char *text)
{ {
float value = 0.0f; // Up to 9 significant digits are read as an integer and scaled once at the end,
// later digits only move the decimal point
unsigned int digits = 0;
int digitCount = 0;
int exponent = 0;
float sign = 1.0f; float sign = 1.0f;
if (text != NULL) if (text != NULL)
@ -1658,17 +1662,65 @@ float TextToFloat(const char *text)
} }
int i = 0; int i = 0;
for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0'); for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
if (text[i++] == '.')
{ {
float divisor = 10.0f; if (digitCount < 9)
{
digits = digits*10 + (unsigned int)(text[i] - '0');
if (digits > 0) digitCount++;
}
else exponent++;
}
if (text[i] == '.')
{
i++;
for (; ((text[i] >= '0') && (text[i] <= '9')); i++) for (; ((text[i] >= '0') && (text[i] <= '9')); i++)
{ {
value += ((float)(text[i] - '0'))/divisor; if (digitCount < 9)
divisor = divisor*10.0f; {
digits = digits*10 + (unsigned int)(text[i] - '0');
if (digits > 0) digitCount++;
exponent--;
}
} }
} }
if (((text[i] == 'e') || (text[i] == 'E')) && (i > 0))
{
int j = i + 1;
int exponentSign = 1;
int exponentValue = 0;
if ((text[j] == '+') || (text[j] == '-'))
{
if (text[j] == '-') exponentSign = -1;
j++;
}
if ((text[j] >= '0') && (text[j] <= '9'))
{
for (; ((text[j] >= '0') && (text[j] <= '9')); j++) if (exponentValue < 1000) exponentValue = exponentValue*10 + (text[j] - '0');
exponent += exponentSign*exponentValue;
}
}
}
float value = (float)digits;
if (value != 0.0f)
{
// Scale in exact steps of 1e10, stopping once the value overflows or underflows
while ((exponent > 10) && (value < 3.4e38f)) { value *= 1e10f; exponent -= 10; }
while ((exponent < -10) && (value > 0.0f)) { value /= 1e10f; exponent += 10; }
// Powers of ten up to 1e10 are exact in a float
int powerCount = (exponent < 0)? -exponent : exponent;
float power = 1.0f;
if (powerCount <= 10) for (int k = 0; k < powerCount; k++) power *= 10.0f;
if (exponent > 0) value *= power;
else if (exponent < 0) value /= power;
} }
return value*sign; return value*sign;
@ -2707,7 +2759,7 @@ static Font LoadBMFont(const char *fileName)
} }
} }
Image fullFont = imFonts[0]; Image imFullFont = imFonts[0];
for (int i = 1; i < pageCount; i++) UnloadImage(imFonts[i]); for (int i = 1; i < pageCount; i++) UnloadImage(imFonts[i]);
// If multiple atlas, then merge atlas // If multiple atlas, then merge atlas
@ -2715,19 +2767,19 @@ static Font LoadBMFont(const char *fileName)
if (pageCount > 1) if (pageCount > 1)
{ {
// Resize font atlas to draw additional images // Resize font atlas to draw additional images
ImageResizeCanvas(&fullFont, imWidth, imHeight*pageCount, 0, 0, BLACK); ImageResizeCanvas(&imFullFont, imWidth, imHeight*pageCount, 0, 0, BLACK);
for (int i = 1; i < pageCount; i++) for (int i = 1; i < pageCount; i++)
{ {
Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight }; Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight };
Rectangle dstRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight }; Rectangle dstRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight };
ImageDrawImagePro(&fullFont, imFonts[i], srcRec, dstRec, (Vector2){ 0 }, 0.0f, WHITE); ImageDrawImagePro(&imFullFont, imFonts[i], srcRec, dstRec, (Vector2){ 0 }, 0.0f, WHITE);
} }
} }
RL_FREE(imFonts); RL_FREE(imFonts);
font.texture = LoadTextureFromImage(fullFont); font.texture = LoadTextureFromImage(imFullFont);
// Fill font characters info data // Fill font characters info data
font.baseSize = fontSize; font.baseSize = fontSize;
@ -2765,7 +2817,7 @@ static Font LoadBMFont(const char *fileName)
font.glyphs[i].advanceX = charAdvanceX; font.glyphs[i].advanceX = charAdvanceX;
// Fill character image data from full font data // Fill character image data from full font data
font.glyphs[i].image = ImageFromImage(fullFont, font.recs[i]); font.glyphs[i].image = ImageFromImage(imFullFont, font.recs[i]);
} }
else else
{ {
@ -2774,7 +2826,7 @@ static Font LoadBMFont(const char *fileName)
} }
} }
UnloadImage(fullFont); UnloadImage(imFullFont);
UnloadFileText(fileText); UnloadFileText(fileText);
if (font.texture.id == 0) if (font.texture.id == 0)

View File

@ -1183,7 +1183,7 @@ Image GenImageText(int width, int height, const char *text)
// Copy an image to a new image // Copy an image to a new image
Image ImageCopy(Image image) Image ImageCopy(Image image)
{ {
Image newImage = { 0 }; Image imCopy = { 0 };
int width = image.width; int width = image.width;
int height = image.height; int height = image.height;
@ -1201,29 +1201,29 @@ Image ImageCopy(Image image)
if (height < 1) height = 1; if (height < 1) height = 1;
} }
newImage.data = RL_CALLOC(size, 1); imCopy.data = RL_CALLOC(size, 1);
if (newImage.data != NULL) if (imCopy.data != NULL)
{ {
// NOTE: Size must be provided in bytes // NOTE: Size must be provided in bytes
memcpy(newImage.data, image.data, size); memcpy(imCopy.data, image.data, size);
newImage.width = image.width; imCopy.width = image.width;
newImage.height = image.height; imCopy.height = image.height;
newImage.mipmaps = image.mipmaps; imCopy.mipmaps = image.mipmaps;
newImage.format = image.format; imCopy.format = image.format;
} }
return newImage; return imCopy;
} }
// Create an image from another image piece // Create an image from another image piece
Image ImageFromImage(Image image, Rectangle rec) Image ImageFromImage(Image image, Rectangle rec)
{ {
Image result = { 0 }; Image imResult = { 0 };
// Security check to avoid program crash // Security check to avoid program crash
if ((image.data == NULL) || (image.width == 0) || (image.height == 0)) return result; if ((image.data == NULL) || (image.width == 0) || (image.height == 0)) return imResult;
if (image.format < PIXELFORMAT_COMPRESSED_DXT1_RGB) if (image.format < PIXELFORMAT_COMPRESSED_DXT1_RGB)
{ {
@ -1234,15 +1234,15 @@ Image ImageFromImage(Image image, Rectangle rec)
{ {
int bytesPerPixel = GetPixelDataSize(1, 1, image.format); int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
result.width = (int)rec.width; imResult.width = (int)rec.width;
result.height = (int)rec.height; imResult.height = (int)rec.height;
result.data = RL_CALLOC((int)rec.width*(int)rec.height*bytesPerPixel, 1); imResult.data = RL_CALLOC((int)rec.width*(int)rec.height*bytesPerPixel, 1);
result.format = image.format; imResult.format = image.format;
result.mipmaps = 1; imResult.mipmaps = 1;
for (int y = 0; y < (int)rec.height; y++) for (int y = 0; y < (int)rec.height; y++)
{ {
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, memcpy(((unsigned char *)imResult.data) + y*(int)rec.width*bytesPerPixel,
((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel,
(int)rec.width*bytesPerPixel); (int)rec.width*bytesPerPixel);
} }
@ -1251,7 +1251,7 @@ Image ImageFromImage(Image image, Rectangle rec)
} }
else TRACELOG(LOG_WARNING, "IMAGE: Image manipulation not supported for compressed formats"); else TRACELOG(LOG_WARNING, "IMAGE: Image manipulation not supported for compressed formats");
return result; return imResult;
} }
// Crop an image to area defined by a rectangle // Crop an image to area defined by a rectangle
@ -1619,9 +1619,9 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
// Create an image from a selected channel of another image // Create an image from a selected channel of another image
Image ImageFromChannel(Image image, int selectedChannel) Image ImageFromChannel(Image image, int selectedChannel)
{ {
Image result = { 0 }; Image imChannel = { 0 };
if ((image.data == NULL) || (image.width == 0) || (image.height == 0)) return result; // Security check if ((image.data == NULL) || (image.width == 0) || (image.height == 0)) return imChannel; // Security check
// Check selected channel is valid // Check selected channel is valid
if (selectedChannel < 0) if (selectedChannel < 0)
@ -1668,10 +1668,10 @@ Image ImageFromChannel(Image image, int selectedChannel)
} }
// TODO: Support R16 and R32 channel sizes, not only 8-bit // TODO: Support R16 and R32 channel sizes, not only 8-bit
result.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; imChannel.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
result.height = image.height; imChannel.height = image.height;
result.width = image.width; imChannel.width = image.width;
result.mipmaps = 1; imChannel.mipmaps = 1;
unsigned char *pixels = (unsigned char *)RL_CALLOC(image.width*image.height, sizeof(unsigned char)); // Values from 0 to 255 unsigned char *pixels = (unsigned char *)RL_CALLOC(image.width*image.height, sizeof(unsigned char)); // Values from 0 to 255
@ -1778,9 +1778,9 @@ Image ImageFromChannel(Image image, int selectedChannel)
} }
} }
result.data = pixels; imChannel.data = pixels;
return result; return imChannel;
} }
// Resize and image to new size using Nearest-Neighbor scaling algorithm // Resize and image to new size using Nearest-Neighbor scaling algorithm
@ -2095,8 +2095,8 @@ void ImageAlphaMask(Image *image, Image alphaMask)
else else
{ {
// Force mask to be Grayscale // Force mask to be Grayscale
Image mask = ImageCopy(alphaMask); Image imMask = ImageCopy(alphaMask);
if (mask.format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) ImageFormat(&mask, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE); if (imMask.format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) ImageFormat(&imMask, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE);
// In case image is only grayscale, add alpha channel // In case image is only grayscale, add alpha channel
if (image->format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) if (image->format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
@ -2104,10 +2104,10 @@ void ImageAlphaMask(Image *image, Image alphaMask)
unsigned char *data = (unsigned char *)RL_CALLOC(image->width*image->height*2, 1); unsigned char *data = (unsigned char *)RL_CALLOC(image->width*image->height*2, 1);
// Apply alpha mask to alpha channel // Apply alpha mask to alpha channel
for (int i = 0, k = 0; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2) for (int i = 0, k = 0; (i < imMask.width*imMask.height) || (i < image->width*image->height); i++, k += 2)
{ {
data[k] = ((unsigned char *)image->data)[i]; data[k] = ((unsigned char *)image->data)[i];
data[k + 1] = ((unsigned char *)mask.data)[i]; data[k + 1] = ((unsigned char *)imMask.data)[i];
} }
RL_FREE(image->data); RL_FREE(image->data);
@ -2120,13 +2120,13 @@ void ImageAlphaMask(Image *image, Image alphaMask)
if (image->format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) ImageFormat(image, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); if (image->format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) ImageFormat(image, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
// Apply alpha mask to alpha channel // Apply alpha mask to alpha channel
for (int i = 0, k = 3; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 4) for (int i = 0, k = 3; (i < imMask.width*imMask.height) || (i < image->width*image->height); i++, k += 4)
{ {
((unsigned char *)image->data)[k] = ((unsigned char *)mask.data)[i]; ((unsigned char *)image->data)[k] = ((unsigned char *)imMask.data)[i];
} }
} }
UnloadImage(mask); UnloadImage(imMask);
} }
} }
@ -4288,8 +4288,8 @@ void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec
if (dst->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image drawing not supported for compressed formats"); if (dst->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image drawing not supported for compressed formats");
else else
{ {
Image srcMod = { 0 }; // Source copy (in case it was required) Image imSrcMod = { 0 }; // Source copy (in case it was required)
Image *srcPtr = &src; // Pointer to source image Image *imSrcPtr = &src; // Pointer to source image
bool useSrcMod = false; // Track source copy required bool useSrcMod = false; // Track source copy required
// Source rectangle out-of-bounds security checks // Source rectangle out-of-bounds security checks
@ -4302,11 +4302,11 @@ void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec
// In that case, make a copy of source, and apply all required transform // In that case, make a copy of source, and apply all required transform
if (((int)srcRec.width != (int)dstRec.width) || ((int)srcRec.height != (int)dstRec.height)) if (((int)srcRec.width != (int)dstRec.width) || ((int)srcRec.height != (int)dstRec.height))
{ {
srcMod = ImageFromImage(src, srcRec); // Create image from another image imSrcMod = ImageFromImage(src, srcRec); // Create image from another image
ImageResize(&srcMod, (int)dstRec.width, (int)dstRec.height); // Resize to destination rectangle ImageResize(&imSrcMod, (int)dstRec.width, (int)dstRec.height); // Resize to destination rectangle
srcRec = (Rectangle){ 0, 0, (float)srcMod.width, (float)srcMod.height }; srcRec = (Rectangle){ 0, 0, (float)imSrcMod.width, (float)imSrcMod.height };
srcPtr = &srcMod; imSrcPtr = &imSrcMod;
useSrcMod = true; useSrcMod = true;
} }
@ -4349,22 +4349,22 @@ void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec
// Fast path: Avoid blend if source has no alpha to blend // Fast path: Avoid blend if source has no alpha to blend
if ((tint.a == 255) && if ((tint.a == 255) &&
((srcPtr->format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) || ((imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) ||
(srcPtr->format == PIXELFORMAT_UNCOMPRESSED_R5G6B5) || (imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_R5G6B5) ||
(srcPtr->format == PIXELFORMAT_UNCOMPRESSED_R8G8B8) || (imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_R8G8B8) ||
(srcPtr->format == PIXELFORMAT_UNCOMPRESSED_R32) || (imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_R32) ||
(srcPtr->format == PIXELFORMAT_UNCOMPRESSED_R32G32B32) || (imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_R32G32B32) ||
(srcPtr->format == PIXELFORMAT_UNCOMPRESSED_R16) || (imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_R16) ||
(srcPtr->format == PIXELFORMAT_UNCOMPRESSED_R16G16B16))) (imSrcPtr->format == PIXELFORMAT_UNCOMPRESSED_R16G16B16)))
blendRequired = false; blendRequired = false;
int strideDst = GetPixelDataSize(dst->width, 1, dst->format); int strideDst = GetPixelDataSize(dst->width, 1, dst->format);
int bytesPerPixelDst = strideDst/(dst->width); int bytesPerPixelDst = strideDst/(dst->width);
int strideSrc = GetPixelDataSize(srcPtr->width, 1, srcPtr->format); int strideSrc = GetPixelDataSize(imSrcPtr->width, 1, imSrcPtr->format);
int bytesPerPixelSrc = strideSrc/(srcPtr->width); int bytesPerPixelSrc = strideSrc/(imSrcPtr->width);
unsigned char *pSrcBase = (unsigned char *)srcPtr->data + ((int)srcRec.y*srcPtr->width + (int)srcRec.x)*bytesPerPixelSrc; unsigned char *pSrcBase = (unsigned char *)imSrcPtr->data + ((int)srcRec.y*imSrcPtr->width + (int)srcRec.x)*bytesPerPixelSrc;
unsigned char *pDstBase = (unsigned char *)dst->data + ((int)dstRec.y*dst->width + (int)dstRec.x)*bytesPerPixelDst; unsigned char *pDstBase = (unsigned char *)dst->data + ((int)dstRec.y*dst->width + (int)dstRec.x)*bytesPerPixelDst;
for (int y = 0; y < (int)srcRec.height; y++) for (int y = 0; y < (int)srcRec.height; y++)
@ -4373,12 +4373,12 @@ void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec
unsigned char *pDst = pDstBase; unsigned char *pDst = pDstBase;
// Fast path: Avoid moving pixel by pixel if no blend required and same format // Fast path: Avoid moving pixel by pixel if no blend required and same format
if (!blendRequired && (srcPtr->format == dst->format)) memcpy(pDst, pSrc, (int)(srcRec.width)*bytesPerPixelSrc); if (!blendRequired && (imSrcPtr->format == dst->format)) memcpy(pDst, pSrc, (int)(srcRec.width)*bytesPerPixelSrc);
else else
{ {
for (int x = 0; x < (int)srcRec.width; x++) for (int x = 0; x < (int)srcRec.width; x++)
{ {
colSrc = GetPixelColor(pSrc, srcPtr->format); colSrc = GetPixelColor(pSrc, imSrcPtr->format);
colDst = GetPixelColor(pDst, dst->format); colDst = GetPixelColor(pDst, dst->format);
// Fast path: Avoid blend if source has no alpha to blend // Fast path: Avoid blend if source has no alpha to blend
@ -4396,21 +4396,21 @@ void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec
pDstBase += strideDst; pDstBase += strideDst;
} }
if (useSrcMod) UnloadImage(srcMod); // Unload source modified image if (useSrcMod) UnloadImage(imSrcMod); // Unload source modified image
if ((dst->mipmaps > 1) && (src.mipmaps > 1)) if ((dst->mipmaps > 1) && (src.mipmaps > 1))
{ {
Image mipmapDst = *dst; Image imMipmapDst = *dst;
mipmapDst.data = (char *)mipmapDst.data + GetPixelDataSize(mipmapDst.width, mipmapDst.height, mipmapDst.format); imMipmapDst.data = (char *)imMipmapDst.data + GetPixelDataSize(imMipmapDst.width, imMipmapDst.height, imMipmapDst.format);
mipmapDst.width /= 2; imMipmapDst.width /= 2;
mipmapDst.height /= 2; imMipmapDst.height /= 2;
mipmapDst.mipmaps--; imMipmapDst.mipmaps--;
Image mipmapSrc = src; Image imMipmapSrc = src;
mipmapSrc.data = (char *)mipmapSrc.data + GetPixelDataSize(mipmapSrc.width, mipmapSrc.height, mipmapSrc.format); imMipmapSrc.data = (char *)imMipmapSrc.data + GetPixelDataSize(imMipmapSrc.width, imMipmapSrc.height, imMipmapSrc.format);
mipmapSrc.width /= 2; imMipmapSrc.width /= 2;
mipmapSrc.height /= 2; imMipmapSrc.height /= 2;
mipmapSrc.mipmaps--; imMipmapSrc.mipmaps--;
Rectangle mipmapSrcRec = srcRec; Rectangle mipmapSrcRec = srcRec;
mipmapSrcRec.width /= 2; mipmapSrcRec.width /= 2;
@ -4424,7 +4424,7 @@ void ImageDrawImagePro(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec
mipmapDstRec.x /= 2; mipmapDstRec.x /= 2;
mipmapDstRec.y /= 2; mipmapDstRec.y /= 2;
ImageDrawImagePro(&mipmapDst, mipmapSrc, mipmapSrcRec, mipmapDstRec, (Vector2){ 0 }, 0.0f, tint); ImageDrawImagePro(&imMipmapDst, imMipmapSrc, mipmapSrcRec, mipmapDstRec, (Vector2){ 0 }, 0.0f, tint);
} }
} }
} }
@ -4535,14 +4535,14 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
{ {
int size = cubemap.width; int size = cubemap.width;
Image faces = { 0 }; // Vertical column image Image imFaces = { 0 }; // Vertical column image
Rectangle faceRecs[6] = { 0 }; // Face source rectangles Rectangle faceRecs[6] = { 0 }; // Face source rectangles
for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, (float)size, (float)size }; for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, (float)size, (float)size };
if (layout == CUBEMAP_LAYOUT_LINE_VERTICAL) if (layout == CUBEMAP_LAYOUT_LINE_VERTICAL)
{ {
faces = ImageCopy(image); // Image data already follows expected convention imFaces = ImageCopy(image); // Image data already follows expected convention
} }
/*else if (layout == CUBEMAP_LAYOUT_PANORAMA) /*else if (layout == CUBEMAP_LAYOUT_PANORAMA)
{ {
@ -4573,33 +4573,33 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
// Convert image data to 6 faces in a vertical column, that's the optimum layout for loading // Convert image data to 6 faces in a vertical column, that's the optimum layout for loading
// NOTE: Image formatting does not work with compressed textures // NOTE: Image formatting does not work with compressed textures
faces = GenImageColor(size, size*6, MAGENTA); imFaces = GenImageColor(size, size*6, MAGENTA);
ImageFormat(&faces, image.format); ImageFormat(&imFaces, image.format);
Image mipmapped = ImageCopy(image); Image imMipmapped = ImageCopy(image);
if (image.mipmaps > 1) if (image.mipmaps > 1)
{ {
ImageMipmaps(&mipmapped); ImageMipmaps(&imMipmapped);
ImageMipmaps(&faces); ImageMipmaps(&imFaces);
} }
for (int i = 0; i < 6; i++) ImageDrawImagePro(&faces, mipmapped, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, (Vector2){ 0 }, 0.0f, WHITE); for (int i = 0; i < 6; i++) ImageDrawImagePro(&imFaces, imMipmapped, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, (Vector2){ 0 }, 0.0f, WHITE);
UnloadImage(mipmapped); UnloadImage(imMipmapped);
} }
// NOTE: Cubemap data is expected to be provided as 6 images in a single data array, // NOTE: Cubemap data is expected to be provided as 6 images in a single data array,
// one after the other (that's a vertical image), following convention: +X, -X, +Y, -Y, +Z, -Z // one after the other (that's a vertical image), following convention: +X, -X, +Y, -Y, +Z, -Z
cubemap.id = rlLoadTextureCubemap(faces.data, size, faces.format, faces.mipmaps); cubemap.id = rlLoadTextureCubemap(imFaces.data, size, imFaces.format, imFaces.mipmaps);
if (cubemap.id != 0) if (cubemap.id != 0)
{ {
cubemap.format = faces.format; cubemap.format = imFaces.format;
cubemap.mipmaps = faces.mipmaps; cubemap.mipmaps = imFaces.mipmaps;
} }
else TRACELOG(LOG_WARNING, "IMAGE: Failed to load cubemap image"); else TRACELOG(LOG_WARNING, "IMAGE: Failed to load cubemap image");
UnloadImage(faces); UnloadImage(imFaces);
} }
else TRACELOG(LOG_WARNING, "IMAGE: Failed to detect cubemap image layout"); else TRACELOG(LOG_WARNING, "IMAGE: Failed to detect cubemap image layout");