Skip to content

Commit 0b4815b

Browse files
committed
WARNING: REMOVED: GIT recording option, added example
1 parent d7a7eda commit 0b4815b

File tree

10 files changed

+112
-118
lines changed

10 files changed

+112
-118
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
6868
| [core_input_actions](core/core_input_actions.c) | <img src="core/core_input_actions.png" alt="core_input_actions" width="80"> | ⭐⭐☆☆ | 5.5 | 5.6 | [Jett](https://github.com/JettMonstersGoBoom) |
6969
| [core_directory_files](core/core_directory_files.c) | <img src="core/core_directory_files.png" alt="core_directory_files" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Hugo ARNAL](https://github.com/hugoarnal) |
7070
| [core_highdpi_testbed](core/core_highdpi_testbed.c) | <img src="core/core_highdpi_testbed.png" alt="core_highdpi_testbed" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
71-
| [core_screen_recording](core/core_screen_recording.c) | <img src="core/core_screen_recording.png" alt="core_screen_recording" width="80"> |☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
71+
| [core_screen_recording](core/core_screen_recording.c) | <img src="core/core_screen_recording.png" alt="core_screen_recording" width="80"> |☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
7272
| [core_clipboard_text](core/core_clipboard_text.c) | <img src="core/core_clipboard_text.png" alt="core_clipboard_text" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Robin](https://github.com/RobinsAviary) |
7373
| [core_text_file_loading](core/core_text_file_loading.c) | <img src="core/core_text_file_loading.png" alt="core_text_file_loading" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Aanjishnu Bhattacharyya](https://github.com/NimComPoo-04) |
7474
| [core_compute_hash](core/core_compute_hash.c) | <img src="core/core_compute_hash.png" alt="core_compute_hash" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |

examples/core/core_screen_recording.c

Lines changed: 107 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
*
33
* raylib [core] example - screen recording
44
*
5-
* Example complexity rating: [★☆☆☆] 1/4
5+
* Example complexity rating: [★★☆☆] 2/4
66
*
77
* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev
88
*
9-
* Example contributed by Ramon Santamaria (@raysan5) and reviewed by Ramon Santamaria (@raysan5)
10-
*
119
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
1210
* BSD-like license that allows static linking with closed source software
1311
*
@@ -17,6 +15,16 @@
1715

1816
#include "raylib.h"
1917

18+
// Using msf_gif library to record frames into GIF
19+
#define MSF_GIF_IMPL
20+
#include "msf_gif.h" // GIF recording functionality
21+
22+
#include <math.h> // Required for: sinf()
23+
24+
#define GIF_RECORD_FRAMERATE 5 // Record framerate, we get a frame every N frames
25+
26+
#define MAX_SINEWAVE_POINTS 256
27+
2028
//------------------------------------------------------------------------------------
2129
// Program main entry point
2230
//------------------------------------------------------------------------------------
@@ -29,7 +37,20 @@ int main(void)
2937

3038
InitWindow(screenWidth, screenHeight, "raylib [core] example - screen recording");
3139

32-
// TODO: Load resources / Initialize variables at this point
40+
bool gifRecording = false; // GIF recording state
41+
unsigned int gifFrameCounter = 0; // GIF frames counter
42+
MsfGifState gifState = { 0 }; // MSGIF context state
43+
44+
Vector2 circlePosition = { 0.0f, screenHeight/2.0f };
45+
float timeCounter = 0.0f;
46+
47+
// Get sine wave points for line drawing
48+
Vector2 sinePoints[MAX_SINEWAVE_POINTS] = { 0 };
49+
for (int i = 0; i < MAX_SINEWAVE_POINTS; i++)
50+
{
51+
sinePoints[i].x = i*GetScreenWidth()/180.0f;
52+
sinePoints[i].y = screenHeight/2.0f + 150*sinf((2*PI/1.5f)*(1.0f/60.0f)*(float)i); // Calculate for 60 fps
53+
}
3354

3455
SetTargetFPS(60);
3556
//--------------------------------------------------------------------------------------
@@ -39,7 +60,59 @@ int main(void)
3960
{
4061
// Update
4162
//----------------------------------------------------------------------------------
42-
// TODO: Update variables / Implement example logic at this point
63+
// Update circle sinusoidal movement
64+
timeCounter += GetFrameTime();
65+
circlePosition.x += GetScreenWidth()/180.0f;
66+
circlePosition.y = screenHeight/2.0f + 150*sinf((2*PI/1.5f)*timeCounter);
67+
if (circlePosition.x > screenWidth)
68+
{
69+
circlePosition.x = 0.0f;
70+
circlePosition.y = screenHeight/2.0f;
71+
timeCounter = 0.0f;
72+
}
73+
74+
// Start-Stop GIF recording on CTRL+R
75+
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_R))
76+
{
77+
if (gifRecording)
78+
{
79+
// Stop current recording and save file
80+
gifRecording = false;
81+
MsfGifResult result = msf_gif_end(&gifState);
82+
SaveFileData(TextFormat("%s/screenrecording.gif", GetApplicationDirectory()), result.data, (unsigned int)result.dataSize);
83+
msf_gif_free(result);
84+
85+
TraceLog(LOG_INFO, "Finish animated GIF recording");
86+
}
87+
else
88+
{
89+
// Start a new recording
90+
gifRecording = true;
91+
gifFrameCounter = 0;
92+
msf_gif_begin(&gifState, GetRenderWidth(), GetRenderHeight());
93+
94+
TraceLog(LOG_INFO, "Start animated GIF recording");
95+
}
96+
}
97+
98+
if (gifRecording)
99+
{
100+
gifFrameCounter++;
101+
102+
// NOTE: We record one gif frame depending on the desired gif framerate
103+
if (gifFrameCounter > GIF_RECORD_FRAMERATE)
104+
{
105+
// Get image data for the current frame (from backbuffer)
106+
// WARNING: This process is quite slow, it can generate stuttering
107+
Image imScreen = LoadImageFromScreen();
108+
109+
// Add the frame to the gif recording, providing and "estimated" time for display in centiseconds
110+
msf_gif_frame(&gifState, imScreen.data, (int)((1.0f/60.0f)*GIF_RECORD_FRAMERATE)/10, 16, imScreen.width*4);
111+
gifFrameCounter = 0;
112+
113+
UnloadImage(imScreen); // Free image data
114+
}
115+
}
43116
//----------------------------------------------------------------------------------
44117

45118
// Draw
@@ -48,20 +121,43 @@ int main(void)
48121

49122
ClearBackground(RAYWHITE);
50123

51-
// TODO: Draw everything that requires to be drawn at this point
124+
for (int i = 0; i < (MAX_SINEWAVE_POINTS - 1); i++)
125+
{
126+
DrawLineV(sinePoints[i], sinePoints[i + 1], MAROON);
127+
DrawCircleV(sinePoints[i], 3, MAROON);
128+
}
129+
130+
DrawCircleV(circlePosition, 30, RED);
52131

53-
DrawLineEx((Vector2){ 0, 0 }, (Vector2){ screenWidth, screenHeight }, 2.0f, RED);
54-
DrawLineEx((Vector2){ 0, screenHeight }, (Vector2){ screenWidth, 0 }, 2.0f, RED);
55-
DrawText("example base code template", 260, 400, 20, LIGHTGRAY);
132+
DrawFPS(10, 10);
56133

134+
/*
135+
// Draw record indicator
136+
// WARNING: If drawn here, it will appear in the recorded image,
137+
// use a render texture instead for the recording and LoadImageFromTexture(rt.texture)
138+
if (gifRecording)
139+
{
140+
// Display the recording indicator every half-second
141+
if ((int)(GetTime()/0.5)%2 == 1)
142+
{
143+
DrawCircle(30, GetScreenHeight() - 20, 10, MAROON);
144+
DrawText("GIF RECORDING", 50, GetScreenHeight() - 25, 10, RED);
145+
}
146+
}
147+
*/
57148
EndDrawing();
58149
//----------------------------------------------------------------------------------
59150
}
60151

61152
// De-Initialization
62153
//--------------------------------------------------------------------------------------
63-
64-
// TODO: Unload all loaded resources at this point
154+
// If still recording a GIF on close window, just finish
155+
if (gifRecording)
156+
{
157+
MsfGifResult result = msf_gif_end(&gifState);
158+
msf_gif_free(result);
159+
gifRecording = false;
160+
}
65161

66162
CloseWindow(); // Close window and OpenGL context
67163
//--------------------------------------------------------------------------------------
30 Bytes
Loading
File renamed without changes.

examples/examples_list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ core;core_viewport_scaling;★★☆☆;5.5;5.5;2025;2025;"Agnis Aldins";@nezver
5050
core;core_input_actions;★★☆☆;5.5;5.6;2025;2025;"Jett";@JettMonstersGoBoom
5151
core;core_directory_files;★☆☆☆;5.5;5.6;2025;2025;"Hugo ARNAL";@hugoarnal
5252
core;core_highdpi_testbed;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
53-
core;core_screen_recording;★☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
53+
core;core_screen_recording;★☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
5454
core;core_clipboard_text;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Robin";@RobinsAviary
5555
core;core_text_file_loading;★☆☆☆;5.5;5.6;0;0;"Aanjishnu Bhattacharyya";@NimComPoo-04
5656
core;core_compute_hash;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5

src/config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
#define SUPPORT_PARTIALBUSY_WAIT_LOOP 1
6161
// Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
6262
#define SUPPORT_SCREEN_CAPTURE 1
63-
// Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
64-
#define SUPPORT_GIF_RECORDING 1
6563
// Support CompressData() and DecompressData() functions
6664
#define SUPPORT_COMPRESSION_API 1
6765
// Support automatic generated events, loading and recording of those events when required

src/raylib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
* [raudio] miniaudio (David Reid - github.com/mackron/miniaudio) for audio device/context management
3434
*
3535
* OPTIONAL DEPENDENCIES (included):
36-
* [rcore] msf_gif (Miles Fogle) for GIF recording
3736
* [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorithm
3837
* [rcore] sdefl (Micha Mettke) for DEFLATE compression algorithm
3938
* [rcore] rprand (Ramon Santamaria) for pseudo-random numbers generation

src/rcore.c

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
* #define SUPPORT_SCREEN_CAPTURE
5353
* Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
5454
*
55-
* #define SUPPORT_GIF_RECORDING
56-
* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
57-
*
5855
* #define SUPPORT_COMPRESSION_API
5956
* Support CompressData() and DecompressData() functions, those functions use zlib implementation
6057
* provided by stb_image and stb_image_write libraries, so, those libraries must be enabled on textures module
@@ -134,15 +131,6 @@
134131
#include "rcamera.h" // Camera system functionality
135132
#endif
136133

137-
#if defined(SUPPORT_GIF_RECORDING)
138-
#define MSF_GIF_MALLOC(contextPointer, newSize) RL_MALLOC(newSize)
139-
#define MSF_GIF_REALLOC(contextPointer, oldMemory, oldSize, newSize) RL_REALLOC(oldMemory, newSize)
140-
#define MSF_GIF_FREE(contextPointer, oldMemory, oldSize) RL_FREE(oldMemory)
141-
142-
#define MSF_GIF_IMPL
143-
#include "external/msf_gif.h" // GIF recording functionality
144-
#endif
145-
146134
#if defined(SUPPORT_COMPRESSION_API)
147135
#define SINFL_IMPLEMENTATION
148136
#define SINFL_NO_SIMD
@@ -402,12 +390,6 @@ bool isGpuReady = false;
402390
static int screenshotCounter = 0; // Screenshots counter
403391
#endif
404392

405-
#if defined(SUPPORT_GIF_RECORDING)
406-
static unsigned int gifFrameCounter = 0; // GIF frames counter
407-
static bool gifRecording = false; // GIF recording state
408-
static MsfGifState gifState = { 0 }; // MSGIF context state
409-
#endif
410-
411393
#if defined(SUPPORT_AUTOMATION_EVENTS)
412394
// Automation events type
413395
typedef enum AutomationEventType {
@@ -758,15 +740,6 @@ void InitWindow(int width, int height, const char *title)
758740
// Close window and unload OpenGL context
759741
void CloseWindow(void)
760742
{
761-
#if defined(SUPPORT_GIF_RECORDING)
762-
if (gifRecording)
763-
{
764-
MsfGifResult result = msf_gif_end(&gifState);
765-
msf_gif_free(result);
766-
gifRecording = false;
767-
}
768-
#endif
769-
770743
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
771744
UnloadFontDefault(); // WARNING: Module required: rtext
772745
#endif
@@ -929,47 +902,6 @@ void EndDrawing(void)
929902
{
930903
rlDrawRenderBatchActive(); // Update and draw internal render batch
931904

932-
#if defined(SUPPORT_GIF_RECORDING)
933-
// Draw record indicator
934-
if (gifRecording)
935-
{
936-
#ifndef GIF_RECORD_FRAMERATE
937-
#define GIF_RECORD_FRAMERATE 10
938-
#endif
939-
gifFrameCounter += (unsigned int)(GetFrameTime()*1000);
940-
941-
// NOTE: We record one gif frame depending on the desired gif framerate
942-
if (gifFrameCounter > 1000/GIF_RECORD_FRAMERATE)
943-
{
944-
// Get image data for the current frame (from backbuffer)
945-
// NOTE: This process is quite slow... :(
946-
Vector2 scale = GetWindowScaleDPI();
947-
unsigned char *screenData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
948-
949-
#ifndef GIF_RECORD_BITRATE
950-
#define GIF_RECORD_BITRATE 16
951-
#endif
952-
953-
// Add the frame to the gif recording, given how many frames have passed in centiseconds
954-
msf_gif_frame(&gifState, screenData, gifFrameCounter/10, GIF_RECORD_BITRATE, (int)((float)CORE.Window.render.width*scale.x)*4);
955-
gifFrameCounter -= 1000/GIF_RECORD_FRAMERATE;
956-
957-
RL_FREE(screenData); // Free image data
958-
}
959-
960-
#if defined(SUPPORT_MODULE_RSHAPES) && defined(SUPPORT_MODULE_RTEXT)
961-
// Display the recording indicator every half-second
962-
if ((int)(GetTime()/0.5)%2 == 1)
963-
{
964-
DrawCircle(30, CORE.Window.screen.height - 20, 10, MAROON); // WARNING: Module required: rshapes
965-
DrawText("GIF RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); // WARNING: Module required: rtext
966-
}
967-
#endif
968-
969-
rlDrawRenderBatchActive(); // Update and draw internal render batch
970-
}
971-
#endif
972-
973905
#if defined(SUPPORT_AUTOMATION_EVENTS)
974906
if (automationEventRecording) RecordAutomationEvent(); // Event recording
975907
#endif
@@ -1002,38 +934,8 @@ void EndDrawing(void)
1002934
#if defined(SUPPORT_SCREEN_CAPTURE)
1003935
if (IsKeyPressed(KEY_F12))
1004936
{
1005-
#if defined(SUPPORT_GIF_RECORDING)
1006-
if (IsKeyDown(KEY_LEFT_CONTROL))
1007-
{
1008-
if (gifRecording)
1009-
{
1010-
gifRecording = false;
1011-
1012-
MsfGifResult result = msf_gif_end(&gifState);
1013-
1014-
SaveFileData(TextFormat("%s/screenrec%03i.gif", CORE.Storage.basePath, screenshotCounter), result.data, (unsigned int)result.dataSize);
1015-
msf_gif_free(result);
1016-
1017-
TRACELOG(LOG_INFO, "SYSTEM: Finish animated GIF recording");
1018-
}
1019-
else
1020-
{
1021-
gifRecording = true;
1022-
gifFrameCounter = 0;
1023-
1024-
Vector2 scale = GetWindowScaleDPI();
1025-
msf_gif_begin(&gifState, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
1026-
screenshotCounter++;
1027-
1028-
TRACELOG(LOG_INFO, "SYSTEM: Start animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter));
1029-
}
1030-
}
1031-
else
1032-
#endif // SUPPORT_GIF_RECORDING
1033-
{
1034-
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
1035-
screenshotCounter++;
1036-
}
937+
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
938+
screenshotCounter++;
1037939
}
1038940
#endif // SUPPORT_SCREEN_CAPTURE
1039941

tools/rexm/examples_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Example elements validated:
6363
| core_input_actions |||||||||||||||
6464
| core_directory_files |||||||||||||||
6565
| core_highdpi_testbed |||||||||||||||
66-
| core_screen_recording ||||| ||||||||||
66+
| core_screen_recording ||||| ||||||||||
6767
| core_clipboard_text |||||||||||||||
6868
| core_text_file_loading |||||||||||||||
6969
| core_compute_hash |||||||||||||||

tools/rexm/examples_report_issues.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Example elements validated:
2121
| **EXAMPLE NAME** | [C] | [CAT]| [INFO]|[PNG]|[WPNG]| [RES]| [MK] |[MKWEB]| [VCX]| [SOL]|[RDME]|[JS] | [WOUT]|[WMETA]|
2222
|:---------------------------------|:---:|:----:|:-----:|:---:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:---:|:-----:|:-----:|
2323
| core_highdpi_testbed |||||||||||||||
24-
| core_screen_recording |||||||||||||||
2524
| rlgl_standalone |||||||||||||||
2625
| rlgl_compute_shader |||||||||||||||
2726
| easings_testbed |||||||||||||||

0 commit comments

Comments
 (0)