Make public TakeScreenshot() function
This commit is contained in:
parent
9956344215
commit
7e65c300b6
47
src/core.c
47
src/core.c
@ -316,9 +316,6 @@ static void PollInputEvents(void); // Register user events
|
||||
static void SwapBuffers(void); // Copy back buffer to front buffers
|
||||
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
||||
static void SetupViewport(void); // Set viewport parameters
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||
static void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
||||
@ -1001,6 +998,28 @@ void SetConfigFlags(char flags)
|
||||
if (configFlags & FLAG_FULLSCREEN_MODE) fullscreen = true;
|
||||
}
|
||||
|
||||
// Takes a screenshot and saves it in the same folder as executable
|
||||
void TakeScreenshot(void)
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||
static int shotNum = 0; // Screenshot number, increments every screenshot take during program execution
|
||||
char buffer[20]; // Buffer to store file name
|
||||
|
||||
unsigned char *imgData = rlglReadScreenPixels(renderWidth, renderHeight);
|
||||
|
||||
sprintf(buffer, "screenshot%03i.png", shotNum);
|
||||
|
||||
// Save image as PNG
|
||||
SavePNG(buffer, imgData, renderWidth, renderHeight, 4);
|
||||
|
||||
free(imgData);
|
||||
|
||||
shotNum++;
|
||||
|
||||
TraceLog(INFO, "[%s] Screenshot taken #03i", buffer, shotNum);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Check file extension
|
||||
bool IsFileExtension(const char *fileName, const char *ext)
|
||||
{
|
||||
@ -2284,28 +2303,6 @@ static void SwapBuffers(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||
// Takes a screenshot and saves it in the same folder as executable
|
||||
static void TakeScreenshot(void)
|
||||
{
|
||||
static int shotNum = 0; // Screenshot number, increments every screenshot take during program execution
|
||||
char buffer[20]; // Buffer to store file name
|
||||
|
||||
unsigned char *imgData = rlglReadScreenPixels(renderWidth, renderHeight);
|
||||
|
||||
sprintf(buffer, "screenshot%03i.png", shotNum);
|
||||
|
||||
// Save image as PNG
|
||||
SavePNG(buffer, imgData, renderWidth, renderHeight, 4);
|
||||
|
||||
free(imgData);
|
||||
|
||||
shotNum++;
|
||||
|
||||
TraceLog(INFO, "[%s] Screenshot taken!", buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||
// GLFW3 Error Callback, runs on GLFW3 error
|
||||
static void ErrorCallback(int error, const char *description)
|
||||
|
@ -690,6 +690,7 @@ RLAPI Color Fade(Color color, float alpha); // Color fade-
|
||||
RLAPI void ShowLogo(void); // Activates raylib logo at startup (can be done with flags)
|
||||
RLAPI void SetConfigFlags(char flags); // Setup some window configuration flags
|
||||
//RLAPI void TraceLog(int logType, const char *text, ...); // Show trace log messages (INFO, WARNING, ERROR, DEBUG)
|
||||
RLAPI void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable
|
||||
RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension
|
||||
|
||||
RLAPI bool IsFileDropped(void); // Check if a file have been dropped into window
|
||||
|
Loading…
x
Reference in New Issue
Block a user