mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-18 15:51:46 +00:00
REVIEWED: Move InitWindow()
/CloseWindow()
to rcore.c
#3313
This commit is contained in:
143
src/rcore.c
143
src/rcore.c
@@ -281,6 +281,9 @@ extern void LoadFontDefault(void); // [Module: text] Loads default font on
|
|||||||
extern void UnloadFontDefault(void); // [Module: text] Unloads default font from GPU memory
|
extern void UnloadFontDefault(void); // [Module: text] Unloads default font from GPU memory
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int InitPlatform(void); // Initialize platform (graphics, inputs and more)
|
||||||
|
static void ClosePlatform(void); // Close platform
|
||||||
|
|
||||||
static void InitTimer(void); // Initialize timer (hi-resolution if available)
|
static void InitTimer(void); // Initialize timer (hi-resolution if available)
|
||||||
static void SetupFramebuffer(int width, int height); // Setup main framebuffer
|
static void SetupFramebuffer(int width, int height); // Setup main framebuffer
|
||||||
static void SetupViewport(int width, int height); // Set viewport for a provided width and height
|
static void SetupViewport(int width, int height); // Set viewport for a provided width and height
|
||||||
@@ -369,6 +372,146 @@ const char *TextFormat(const char *text, ...); // Formatting of text with
|
|||||||
//void EnableCursor(void)
|
//void EnableCursor(void)
|
||||||
//void DisableCursor(void)
|
//void DisableCursor(void)
|
||||||
|
|
||||||
|
// Initialize window and OpenGL context
|
||||||
|
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
||||||
|
void InitWindow(int width, int height, const char *title)
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
||||||
|
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
||||||
|
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
||||||
|
#if defined(SUPPORT_MODULE_RSHAPES)
|
||||||
|
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
||||||
|
#else
|
||||||
|
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_MODULE_RTEXTURES)
|
||||||
|
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
||||||
|
#else
|
||||||
|
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_MODULE_RTEXT)
|
||||||
|
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
||||||
|
#else
|
||||||
|
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_MODULE_RMODELS)
|
||||||
|
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
||||||
|
#else
|
||||||
|
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_MODULE_RAUDIO)
|
||||||
|
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
||||||
|
#else
|
||||||
|
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialize window data
|
||||||
|
CORE.Window.screen.width = width;
|
||||||
|
CORE.Window.screen.height = height;
|
||||||
|
CORE.Window.eventWaiting = false;
|
||||||
|
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
||||||
|
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
||||||
|
|
||||||
|
// Initialize global input state
|
||||||
|
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
|
||||||
|
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
||||||
|
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
||||||
|
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
||||||
|
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
||||||
|
|
||||||
|
// Initialize platform
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
InitPlatform();
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize rlgl default data (buffers and shaders)
|
||||||
|
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
|
||||||
|
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
||||||
|
|
||||||
|
// Setup default viewport
|
||||||
|
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
||||||
|
|
||||||
|
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
||||||
|
// Load default font
|
||||||
|
// WARNING: External function: Module required: rtext
|
||||||
|
LoadFontDefault();
|
||||||
|
#if defined(SUPPORT_MODULE_RSHAPES)
|
||||||
|
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
|
||||||
|
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
|
||||||
|
Rectangle rec = GetFontDefault().recs[95];
|
||||||
|
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
||||||
|
{
|
||||||
|
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
|
||||||
|
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
|
||||||
|
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if defined(SUPPORT_MODULE_RSHAPES)
|
||||||
|
// Set default texture and rectangle to be used for shapes drawing
|
||||||
|
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
||||||
|
Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
||||||
|
SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
||||||
|
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||||
|
{
|
||||||
|
// Set default font texture filter for HighDPI (blurry)
|
||||||
|
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
|
||||||
|
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
||||||
|
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
||||||
|
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
|
||||||
|
CORE.Time.frameCounter = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialize random seed
|
||||||
|
SetRandomSeed((unsigned int)time(NULL));
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP: Application initialized successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close window and unload OpenGL context
|
||||||
|
void CloseWindow(void)
|
||||||
|
{
|
||||||
|
#if defined(SUPPORT_GIF_RECORDING)
|
||||||
|
if (gifRecording)
|
||||||
|
{
|
||||||
|
MsfGifResult result = msf_gif_end(&gifState);
|
||||||
|
msf_gif_free(result);
|
||||||
|
gifRecording = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
||||||
|
UnloadFontDefault(); // WARNING: Module required: rtext
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rlglClose(); // De-init rlgl
|
||||||
|
|
||||||
|
// De-initialize platform
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
ClosePlatform();
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
||||||
|
RL_FREE(events);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CORE.Window.ready = false;
|
||||||
|
TRACELOG(LOG_INFO, "Window closed successfully");
|
||||||
|
}
|
||||||
|
|
||||||
// Check if window has been initialized successfully
|
// Check if window has been initialized successfully
|
||||||
bool IsWindowReady(void)
|
bool IsWindowReady(void)
|
||||||
{
|
{
|
||||||
|
@@ -136,96 +136,6 @@ struct android_app *GetAndroidApp(void)
|
|||||||
// Module Functions Definition: Window and Graphics Device
|
// Module Functions Definition: Window and Graphics Device
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize window and OpenGL context
|
|
||||||
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
|
||||||
void InitWindow(int width, int height, const char *title)
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
|
||||||
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
|
||||||
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT)
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RMODELS)
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize window data
|
|
||||||
CORE.Window.screen.width = width;
|
|
||||||
CORE.Window.screen.height = height;
|
|
||||||
CORE.Window.eventWaiting = false;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
|
||||||
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
|
||||||
|
|
||||||
// Initialize global input state
|
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
|
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
|
||||||
|
|
||||||
// Initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
InitPlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
|
||||||
void CloseWindow(void)
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
msf_gif_free(result);
|
|
||||||
gifRecording = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
UnloadFontDefault(); // WARNING: Module required: rtext
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP)
|
|
||||||
timeEndPeriod(1); // Restore time period
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// De-initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
ClosePlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
RL_FREE(events);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CORE.Window.ready = false;
|
|
||||||
TRACELOG(LOG_INFO, "Window closed successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if application should close
|
// Check if application should close
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
|
@@ -142,162 +142,11 @@ static void JoystickCallback(int jid, int event);
|
|||||||
// Module Functions Definition: Window and Graphics Device
|
// Module Functions Definition: Window and Graphics Device
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize window and OpenGL context
|
|
||||||
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
|
||||||
void InitWindow(int width, int height, const char *title)
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
|
||||||
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
|
||||||
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT)
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RMODELS)
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize window data
|
|
||||||
CORE.Window.screen.width = width;
|
|
||||||
CORE.Window.screen.height = height;
|
|
||||||
CORE.Window.eventWaiting = false;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
|
||||||
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
|
||||||
|
|
||||||
// Initialize global input state
|
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
|
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
|
||||||
|
|
||||||
// Initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
InitPlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
// Initialize rlgl default data (buffers and shaders)
|
|
||||||
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
|
|
||||||
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
// Setup default viewport
|
|
||||||
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
// Load default font
|
|
||||||
// WARNING: External function: Module required: rtext
|
|
||||||
LoadFontDefault();
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
|
|
||||||
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
|
|
||||||
Rectangle rec = GetFontDefault().recs[95];
|
|
||||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
|
||||||
{
|
|
||||||
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set default texture and rectangle to be used for shapes drawing
|
|
||||||
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
|
||||||
Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
|
||||||
SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
|
||||||
{
|
|
||||||
// Set default font texture filter for HighDPI (blurry)
|
|
||||||
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
|
|
||||||
CORE.Time.frameCounter = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize random seed
|
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP: Application initialized successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
|
||||||
void CloseWindow(void)
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
msf_gif_free(result);
|
|
||||||
gifRecording = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
UnloadFontDefault(); // WARNING: Module required: rtext
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
|
||||||
|
|
||||||
// De-initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
ClosePlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
RL_FREE(events);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CORE.Window.ready = false;
|
|
||||||
TRACELOG(LOG_INFO, "Window closed successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if application should close
|
// Check if application should close
|
||||||
// NOTE: By default, if KEY_ESCAPE pressed or window close icon clicked
|
// NOTE: By default, if KEY_ESCAPE pressed or window close icon clicked
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
if (CORE.Window.ready)
|
if (CORE.Window.ready) return CORE.Window.shouldClose;
|
||||||
{
|
|
||||||
// While window minimized, stop loop execution
|
|
||||||
while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents();
|
|
||||||
|
|
||||||
CORE.Window.shouldClose = glfwWindowShouldClose(platform.handle);
|
|
||||||
|
|
||||||
// Reset close status for next frame
|
|
||||||
glfwSetWindowShouldClose(platform.handle, GLFW_FALSE);
|
|
||||||
|
|
||||||
return CORE.Window.shouldClose;
|
|
||||||
}
|
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1349,6 +1198,14 @@ void PollInputEvents(void)
|
|||||||
|
|
||||||
if (CORE.Window.eventWaiting) glfwWaitEvents(); // Wait for in input events before continue (drawing is paused)
|
if (CORE.Window.eventWaiting) glfwWaitEvents(); // Wait for in input events before continue (drawing is paused)
|
||||||
else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks)
|
else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks)
|
||||||
|
|
||||||
|
// While window minimized, stop loop execution
|
||||||
|
while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents();
|
||||||
|
|
||||||
|
CORE.Window.shouldClose = glfwWindowShouldClose(platform.handle);
|
||||||
|
|
||||||
|
// Reset close status for next frame
|
||||||
|
glfwSetWindowShouldClose(platform.handle, GLFW_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -194,146 +194,6 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode); // Help conv
|
|||||||
// Module Functions Definition: Window and Graphics Device
|
// Module Functions Definition: Window and Graphics Device
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize window and OpenGL context
|
|
||||||
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
|
||||||
void InitWindow(int width, int height, const char *title)
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
|
||||||
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
|
||||||
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT)
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RMODELS)
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize window data
|
|
||||||
CORE.Window.screen.width = width;
|
|
||||||
CORE.Window.screen.height = height;
|
|
||||||
CORE.Window.eventWaiting = false;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
|
||||||
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
|
||||||
|
|
||||||
// Initialize global input state
|
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
|
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
|
||||||
|
|
||||||
// Initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
InitPlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
// Initialize rlgl default data (buffers and shaders)
|
|
||||||
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
|
|
||||||
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
// Setup default viewport
|
|
||||||
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
// Load default font
|
|
||||||
// WARNING: External function: Module required: rtext
|
|
||||||
LoadFontDefault();
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
|
|
||||||
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
|
|
||||||
Rectangle rec = GetFontDefault().recs[95];
|
|
||||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
|
||||||
{
|
|
||||||
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set default texture and rectangle to be used for shapes drawing
|
|
||||||
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
|
||||||
Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
|
||||||
SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
|
||||||
{
|
|
||||||
// Set default font texture filter for HighDPI (blurry)
|
|
||||||
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize random seed
|
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
|
|
||||||
CORE.Time.frameCounter = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Application initialized successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
|
||||||
void CloseWindow(void)
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
msf_gif_free(result);
|
|
||||||
gifRecording = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
UnloadFontDefault(); // WARNING: Module required: rtext
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
|
||||||
|
|
||||||
// De-initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
ClosePlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
RL_FREE(events);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CORE.Window.ready = false;
|
|
||||||
TRACELOG(LOG_INFO, "Window closed successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if application should close
|
// Check if application should close
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
|
144
src/rcore_drm.c
144
src/rcore_drm.c
@@ -168,150 +168,6 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt
|
|||||||
// Module Functions Definition: Window and Graphics Device
|
// Module Functions Definition: Window and Graphics Device
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize window and OpenGL context
|
|
||||||
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
|
||||||
void InitWindow(int width, int height, const char *title)
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
|
||||||
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
|
||||||
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT)
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RMODELS)
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize window data
|
|
||||||
CORE.Window.screen.width = width;
|
|
||||||
CORE.Window.screen.height = height;
|
|
||||||
CORE.Window.eventWaiting = false;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
|
||||||
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
|
||||||
|
|
||||||
// Initialize global input state
|
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
|
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
|
||||||
|
|
||||||
// Initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
InitPlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
// Initialize rlgl default data (buffers and shaders)
|
|
||||||
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
|
|
||||||
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
// Setup default viewport
|
|
||||||
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
// Load default font
|
|
||||||
// WARNING: External function: Module required: rtext
|
|
||||||
LoadFontDefault();
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
|
|
||||||
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
|
|
||||||
Rectangle rec = GetFontDefault().recs[95];
|
|
||||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
|
||||||
{
|
|
||||||
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){rec.x + 2, rec.y + 2, 1, 1});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2});
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set default texture and rectangle to be used for shapes drawing
|
|
||||||
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
|
||||||
Texture2D texture = {rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8};
|
|
||||||
SetShapesTexture(texture, (Rectangle){0.0f, 0.0f, 1.0f, 1.0f}); // WARNING: Module required: rshapes
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
|
||||||
{
|
|
||||||
// Set default font texture filter for HighDPI (blurry)
|
|
||||||
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
|
|
||||||
CORE.Time.frameCounter = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize random seed
|
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: DRM: Application initialized successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
|
||||||
void CloseWindow(void)
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
msf_gif_free(result);
|
|
||||||
gifRecording = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
UnloadFontDefault(); // WARNING: Module required: rtext
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP)
|
|
||||||
timeEndPeriod(1); // Restore time period
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// De-initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
ClosePlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
RL_FREE(events);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CORE.Window.ready = false;
|
|
||||||
TRACELOG(LOG_INFO, "Window closed successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if application should close
|
// Check if application should close
|
||||||
// NOTE: By default, if KEY_ESCAPE pressed
|
// NOTE: By default, if KEY_ESCAPE pressed
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
|
@@ -83,153 +83,6 @@ static bool InitGraphicsDevice(void); // Initialize graphics device
|
|||||||
// Module Functions Definition: Window and Graphics Device
|
// Module Functions Definition: Window and Graphics Device
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize window and OpenGL context
|
|
||||||
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
|
||||||
void InitWindow(int width, int height, const char *title)
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
|
||||||
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
|
||||||
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT)
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RMODELS)
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NOTE: Keep internal pointer to input title string (no copy)
|
|
||||||
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
|
||||||
|
|
||||||
// Initialize global input state
|
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input));
|
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
|
||||||
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
|
|
||||||
CORE.Window.eventWaiting = false;
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Platform specific init window
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
CORE.Window.screen.width = width;
|
|
||||||
CORE.Window.screen.height = height;
|
|
||||||
CORE.Window.currentFbo.width = width;
|
|
||||||
CORE.Window.currentFbo.height = height;
|
|
||||||
|
|
||||||
// Initialize graphics device
|
|
||||||
// NOTE: returns true if window and graphic device has been initialized successfully
|
|
||||||
CORE.Window.ready = InitGraphicsDevice(width, height);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize OpenGL context (states and resources)
|
|
||||||
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
|
|
||||||
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
// Setup default viewport
|
|
||||||
// NOTE: It updated CORE.Window.render.width and CORE.Window.render.height
|
|
||||||
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
// Load default font
|
|
||||||
// WARNING: External function: Module required: rtext
|
|
||||||
LoadFontDefault();
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
|
|
||||||
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
|
|
||||||
Rectangle rec = GetFontDefault().recs[95];
|
|
||||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
|
||||||
{
|
|
||||||
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set default texture and rectangle to be used for shapes drawing
|
|
||||||
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
|
||||||
Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
|
||||||
SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
|
||||||
{
|
|
||||||
// Set default font texture filter for HighDPI (blurry)
|
|
||||||
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
|
|
||||||
CORE.Time.frameCounter = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize random seed
|
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Application initialized successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
|
||||||
void CloseWindow(void)
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
msf_gif_free(result);
|
|
||||||
gifRecording = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
UnloadFontDefault(); // WARNING: Module required: rtext
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
|
||||||
|
|
||||||
// Platform specific close window
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
// TODO.
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
RL_FREE(events);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CORE.Window.ready = false;
|
|
||||||
TRACELOG(LOG_INFO, "Window closed successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if application should close
|
// Check if application should close
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
@@ -503,27 +356,7 @@ void OpenURL(const char *url)
|
|||||||
if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
|
if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JNIEnv *env = NULL;
|
// TODO:
|
||||||
JavaVM *vm = platform.app->activity->vm;
|
|
||||||
(*vm)->AttachCurrentThread(vm, &env, NULL);
|
|
||||||
|
|
||||||
jstring urlString = (*env)->NewStringUTF(env, url);
|
|
||||||
jclass uriClass = (*env)->FindClass(env, "android/net/Uri");
|
|
||||||
jmethodID uriParse = (*env)->GetStaticMethodID(env, uriClass, "parse", "(Ljava/lang/String;)Landroid/net/Uri;");
|
|
||||||
jobject uri = (*env)->CallStaticObjectMethod(env, uriClass, uriParse, urlString);
|
|
||||||
|
|
||||||
jclass intentClass = (*env)->FindClass(env, "android/content/Intent");
|
|
||||||
jfieldID actionViewId = (*env)->GetStaticFieldID(env, intentClass, "ACTION_VIEW", "Ljava/lang/String;");
|
|
||||||
jobject actionView = (*env)->GetStaticObjectField(env, intentClass, actionViewId);
|
|
||||||
jmethodID newIntent = (*env)->GetMethodID(env, intentClass, "<init>", "(Ljava/lang/String;Landroid/net/Uri;)V");
|
|
||||||
jobject intent = (*env)->AllocObject(env, intentClass);
|
|
||||||
|
|
||||||
(*env)->CallVoidMethod(env, intent, newIntent, actionView, uri);
|
|
||||||
jclass activityClass = (*env)->FindClass(env, "android/app/Activity");
|
|
||||||
jmethodID startActivity = (*env)->GetMethodID(env, activityClass, "startActivity", "(Landroid/content/Intent;)V");
|
|
||||||
(*env)->CallVoidMethod(env, platform.app->activity->clazz, startActivity, intent);
|
|
||||||
|
|
||||||
(*vm)->DetachCurrentThread(vm);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
141
src/rcore_web.c
141
src/rcore_web.c
@@ -125,147 +125,6 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
|
|||||||
// Module Functions Definition: Window and Graphics Device
|
// Module Functions Definition: Window and Graphics Device
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize window and OpenGL context
|
|
||||||
// NOTE: data parameter could be used to pass any kind of required data to the initialization
|
|
||||||
void InitWindow(int width, int height, const char *title)
|
|
||||||
{
|
|
||||||
TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION);
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "Supported raylib modules:");
|
|
||||||
TRACELOG(LOG_INFO, " > rcore:..... loaded (mandatory)");
|
|
||||||
TRACELOG(LOG_INFO, " > rlgl:...... loaded (mandatory)");
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rshapes:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtextures:. not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT)
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rtext:..... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RMODELS)
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > rmodels:... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... loaded (optional)");
|
|
||||||
#else
|
|
||||||
TRACELOG(LOG_INFO, " > raudio:.... not loaded (optional)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize window data
|
|
||||||
CORE.Window.screen.width = width;
|
|
||||||
CORE.Window.screen.height = height;
|
|
||||||
CORE.Window.eventWaiting = false;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
|
||||||
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title;
|
|
||||||
|
|
||||||
// Initialize global input state
|
|
||||||
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
|
|
||||||
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
|
|
||||||
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
|
|
||||||
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
|
|
||||||
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
|
|
||||||
|
|
||||||
// Initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
InitPlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
// Initialize OpenGL context (states and resources)
|
|
||||||
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl
|
|
||||||
rlglInit(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
// Setup default viewport
|
|
||||||
// NOTE: It updated CORE.Window.render.width and CORE.Window.render.height
|
|
||||||
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height);
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
// Load default font
|
|
||||||
// WARNING: External function: Module required: rtext
|
|
||||||
LoadFontDefault();
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
|
|
||||||
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
|
|
||||||
Rectangle rec = GetFontDefault().recs[95];
|
|
||||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
|
||||||
{
|
|
||||||
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){rec.x + 2, rec.y + 2, 1, 1});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
|
|
||||||
SetShapesTexture(GetFontDefault().texture, (Rectangle){rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2});
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(SUPPORT_MODULE_RSHAPES)
|
|
||||||
// Set default texture and rectangle to be used for shapes drawing
|
|
||||||
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
|
||||||
Texture2D texture = {rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8};
|
|
||||||
SetShapesTexture(texture, (Rectangle){0.0f, 0.0f, 1.0f, 1.0f}); // WARNING: Module required: rshapes
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
|
||||||
{
|
|
||||||
// Set default font texture filter for HighDPI (blurry)
|
|
||||||
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
|
|
||||||
CORE.Time.frameCounter = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize random seed
|
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: WEB: Application initialized successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
|
||||||
void CloseWindow(void)
|
|
||||||
{
|
|
||||||
#if defined(SUPPORT_GIF_RECORDING)
|
|
||||||
if (gifRecording)
|
|
||||||
{
|
|
||||||
MsfGifResult result = msf_gif_end(&gifState);
|
|
||||||
msf_gif_free(result);
|
|
||||||
gifRecording = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
|
|
||||||
UnloadFontDefault(); // WARNING: Module required: rtext
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rlglClose(); // De-init rlgl
|
|
||||||
|
|
||||||
// De-initialize platform
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
ClosePlatform();
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined(SUPPORT_EVENTS_AUTOMATION)
|
|
||||||
RL_FREE(events);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CORE.Window.ready = false;
|
|
||||||
TRACELOG(LOG_INFO, "Window closed successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if application should close
|
// Check if application should close
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user