Change from using CORE.Window to a macro CORE_WINDOW to help multi-window branch maintenance.

This commit is contained in:
Jeffery Myers 2024-05-11 15:35:21 -07:00
parent a126ff8c95
commit ff814383df
10 changed files with 834 additions and 693 deletions

View File

@ -302,6 +302,76 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\src\platforms\rcore_android.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_desktop.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_desktop_rgfw.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_desktop_sdl.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_drm.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_template.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_web.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release.DLL|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug.DLL|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\..\src\raudio.c" /> <ClCompile Include="..\..\..\src\raudio.c" />
<ClCompile Include="..\..\..\src\rcore.c" /> <ClCompile Include="..\..\..\src\rcore.c" />
<ClCompile Include="..\..\..\src\rmodels.c" /> <ClCompile Include="..\..\..\src\rmodels.c" />

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="..\..\..\src\raudio.c" />
<ClCompile Include="..\..\..\src\rcore.c" />
<ClCompile Include="..\..\..\src\rmodels.c" />
<ClCompile Include="..\..\..\src\rglfw.c" />
<ClCompile Include="..\..\..\src\rshapes.c" />
<ClCompile Include="..\..\..\src\rtext.c" />
<ClCompile Include="..\..\..\src\rtextures.c" />
<ClCompile Include="..\..\..\src\utils.c" />
<ClCompile Include="..\..\..\src\platforms\rcore_android.c">
<Filter>platforms</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_desktop.c">
<Filter>platforms</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_desktop_rgfw.c">
<Filter>platforms</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_desktop_sdl.c">
<Filter>platforms</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_drm.c">
<Filter>platforms</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_template.c">
<Filter>platforms</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\platforms\rcore_web.c">
<Filter>platforms</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\src\external\cgltf.h" />
<ClInclude Include="..\..\..\src\rcamera.h" />
<ClInclude Include="..\..\..\src\config.h" />
<ClInclude Include="..\..\..\src\external\glad.h" />
<ClInclude Include="..\..\..\src\external\jar_mod.h" />
<ClInclude Include="..\..\..\src\external\jar_xm.h" />
<ClInclude Include="..\..\..\src\external\miniaudio.h" />
<ClInclude Include="..\..\..\src\external\stb_image.h" />
<ClInclude Include="..\..\..\src\external\stb_image_resize.h" />
<ClInclude Include="..\..\..\src\external\stb_image_write.h" />
<ClInclude Include="..\..\..\src\external\stb_rect_pack.h" />
<ClInclude Include="..\..\..\src\external\stb_truetype.h" />
<ClInclude Include="..\..\..\src\external\stb_vorbis.h" />
<ClInclude Include="..\..\..\src\rgestures.h" />
<ClInclude Include="..\..\..\src\raylib.h" />
<ClInclude Include="..\..\..\src\raymath.h" />
<ClInclude Include="..\..\..\src\rlgl.h" />
<ClInclude Include="..\..\..\src\utils.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\..\src\raylib.dll.rc" />
</ItemGroup>
<ItemGroup>
<Filter Include="platforms">
<UniqueIdentifier>{8bf2e34f-69a8-4a61-94bd-3611a50d0100}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View File

@ -74,6 +74,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { 0 }; // Platform specific data static PlatformData platform = { 0 }; // Platform specific data
@ -308,7 +309,7 @@ struct android_app *GetAndroidApp(void)
// Check if application should close // Check if application should close
bool WindowShouldClose(void) bool WindowShouldClose(void)
{ {
if (CORE.Window.ready) return CORE.Window.shouldClose; if (CORE_WINDOW.ready) return CORE_WINDOW.shouldClose;
else return true; else return true;
} }
@ -369,7 +370,7 @@ void SetWindowIcons(Image *images, int count)
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
CORE.Window.title = title; CORE_WINDOW.title = title;
} }
// Set window position on screen (windowed mode) // Set window position on screen (windowed mode)
@ -387,15 +388,15 @@ void SetWindowMonitor(int monitor)
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMinSize(int width, int height) void SetWindowMinSize(int width, int height)
{ {
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
} }
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height) void SetWindowMaxSize(int width, int height)
{ {
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
} }
// Set window dimensions // Set window dimensions
@ -530,7 +531,7 @@ void HideCursor(void)
void EnableCursor(void) void EnableCursor(void)
{ {
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorHidden = false;
} }
@ -539,7 +540,7 @@ void EnableCursor(void)
void DisableCursor(void) void DisableCursor(void)
{ {
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorHidden = true;
} }
@ -689,7 +690,7 @@ void PollInputEvents(void)
// NOTE: Never close window, native activity is controlled by the system! // NOTE: Never close window, native activity is controlled by the system!
if (platform.app->destroyRequested != 0) if (platform.app->destroyRequested != 0)
{ {
//CORE.Window.shouldClose = true; //CORE_WINDOW.shouldClose = true;
//ANativeActivity_finish(platform.app->activity); //ANativeActivity_finish(platform.app->activity);
} }
} }
@ -705,8 +706,8 @@ int InitPlatform(void)
{ {
// Initialize display basic configuration // Initialize display basic configuration
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
CORE.Window.currentFbo.width = CORE.Window.screen.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.screen.width;
CORE.Window.currentFbo.height = CORE.Window.screen.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.screen.height;
// Set desired windows flags before initializing anything // Set desired windows flags before initializing anything
ANativeActivity_setWindowFlags(platform.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER ANativeActivity_setWindowFlags(platform.app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER
@ -717,7 +718,7 @@ int InitPlatform(void)
else if (orientation == ACONFIGURATION_ORIENTATION_LAND) TRACELOG(LOG_INFO, "ANDROID: Window orientation set as landscape"); else if (orientation == ACONFIGURATION_ORIENTATION_LAND) TRACELOG(LOG_INFO, "ANDROID: Window orientation set as landscape");
// TODO: Automatic orientation doesn't seem to work // TODO: Automatic orientation doesn't seem to work
if (CORE.Window.screen.width <= CORE.Window.screen.height) if (CORE_WINDOW.screen.width <= CORE_WINDOW.screen.height)
{ {
AConfiguration_setOrientation(platform.app->config, ACONFIGURATION_ORIENTATION_PORT); AConfiguration_setOrientation(platform.app->config, ACONFIGURATION_ORIENTATION_PORT);
TRACELOG(LOG_WARNING, "ANDROID: Window orientation changed to portrait"); TRACELOG(LOG_WARNING, "ANDROID: Window orientation changed to portrait");
@ -734,10 +735,10 @@ int InitPlatform(void)
//AConfiguration_getScreenLong(platform.app->config); //AConfiguration_getScreenLong(platform.app->config);
// Set some default window flags // Set some default window flags
CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false CORE_WINDOW.flags &= ~FLAG_WINDOW_HIDDEN; // false
CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // false CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED; // false
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // true CORE_WINDOW.flags |= FLAG_WINDOW_MAXIMIZED; // true
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // false CORE_WINDOW.flags &= ~FLAG_WINDOW_UNFOCUSED; // false
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Initialize App command system // Initialize App command system
@ -765,7 +766,7 @@ int InitPlatform(void)
int pollEvents = 0; int pollEvents = 0;
// Wait for window to be initialized (display and context) // Wait for window to be initialized (display and context)
while (!CORE.Window.ready) while (!CORE_WINDOW.ready)
{ {
// Process events loop // Process events loop
while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void**)&platform.source)) >= 0) while ((pollResult = ALooper_pollAll(0, NULL, &pollEvents, (void**)&platform.source)) >= 0)
@ -774,7 +775,7 @@ int InitPlatform(void)
if (platform.source != NULL) platform.source->process(platform.app, platform.source); if (platform.source != NULL) platform.source->process(platform.app, platform.source);
// NOTE: Never close window, native activity is controlled by the system! // NOTE: Never close window, native activity is controlled by the system!
//if (platform.app->destroyRequested != 0) CORE.Window.shouldClose = true; //if (platform.app->destroyRequested != 0) CORE_WINDOW.shouldClose = true;
} }
} }
@ -812,12 +813,12 @@ void ClosePlatform(void)
// NOTE: returns false in case graphic device could not be created // NOTE: returns false in case graphic device could not be created
static int InitGraphicsDevice(void) static int InitGraphicsDevice(void)
{ {
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
EGLint samples = 0; EGLint samples = 0;
EGLint sampleBuffer = 0; EGLint sampleBuffer = 0;
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
samples = 4; samples = 4;
sampleBuffer = 1; sampleBuffer = 1;
@ -886,12 +887,12 @@ static int InitGraphicsDevice(void)
// At this point we need to manage render size vs screen size // At this point we need to manage render size vs screen size
// NOTE: This function use and modify global module variables: // NOTE: This function use and modify global module variables:
// -> CORE.Window.screen.width/CORE.Window.screen.height // -> CORE_WINDOW.screen.width/CORE_WINDOW.screen.height
// -> CORE.Window.render.width/CORE.Window.render.height // -> CORE_WINDOW.render.width/CORE_WINDOW.render.height
// -> CORE.Window.screenScale // -> CORE_WINDOW.screenScale
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); SetupFramebuffer(CORE_WINDOW.display.width, CORE_WINDOW.display.height);
ANativeWindow_setBuffersGeometry(platform.app->window, CORE.Window.render.width, CORE.Window.render.height, displayFormat); ANativeWindow_setBuffersGeometry(platform.app->window, CORE_WINDOW.render.width, CORE_WINDOW.render.height, displayFormat);
//ANativeWindow_setBuffersGeometry(platform.app->window, 0, 0, displayFormat); // Force use of native display size //ANativeWindow_setBuffersGeometry(platform.app->window, 0, 0, displayFormat); // Force use of native display size
platform.surface = eglCreateWindowSurface(platform.device, platform.config, platform.app->window, NULL); platform.surface = eglCreateWindowSurface(platform.device, platform.config, platform.app->window, NULL);
@ -906,25 +907,25 @@ static int InitGraphicsDevice(void)
} }
else else
{ {
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
// Load OpenGL extensions // Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions // NOTE: GL procedures address loader is required to load extensions
rlLoadExtensions(eglGetProcAddress); rlLoadExtensions(eglGetProcAddress);
CORE.Window.ready = true; CORE_WINDOW.ready = true;
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow(); if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
return 0; return 0;
} }
@ -953,8 +954,8 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
// context rebinding if the screen is scaled unless offsets are added. There's probably a more // context rebinding if the screen is scaled unless offsets are added. There's probably a more
// appropriate way to fix this // appropriate way to fix this
ANativeWindow_setBuffersGeometry(app->window, ANativeWindow_setBuffersGeometry(app->window,
CORE.Window.render.width + CORE.Window.renderOffset.x, CORE_WINDOW.render.width + CORE_WINDOW.renderOffset.x,
CORE.Window.render.height + CORE.Window.renderOffset.y, CORE_WINDOW.render.height + CORE_WINDOW.renderOffset.y,
displayFormat); displayFormat);
// Recreate display surface and re-attach OpenGL context // Recreate display surface and re-attach OpenGL context
@ -965,19 +966,19 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
} }
else else
{ {
CORE.Window.display.width = ANativeWindow_getWidth(platform.app->window); CORE_WINDOW.display.width = ANativeWindow_getWidth(platform.app->window);
CORE.Window.display.height = ANativeWindow_getHeight(platform.app->window); CORE_WINDOW.display.height = ANativeWindow_getHeight(platform.app->window);
// Initialize graphics device (display device and OpenGL context) // Initialize graphics device (display device and OpenGL context)
InitGraphicsDevice(); InitGraphicsDevice();
// Initialize OpenGL context (states and resources) // Initialize OpenGL context (states and resources)
// NOTE: CORE.Window.currentFbo.width and CORE.Window.currentFbo.height not used, just stored as globals in rlgl // 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); rlglInit(CORE_WINDOW.currentFbo.width, CORE_WINDOW.currentFbo.height);
// Setup default viewport // Setup default viewport
// NOTE: It updated CORE.Window.render.width and CORE.Window.render.height // NOTE: It updated CORE_WINDOW.render.width and CORE_WINDOW.render.height
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height); SetupViewport(CORE_WINDOW.currentFbo.width, CORE_WINDOW.currentFbo.height);
// Initialize hi-res timer // Initialize hi-res timer
InitTimer(); InitTimer();
@ -990,7 +991,7 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
// Set font white rectangle for shapes drawing, so shapes and text can be batched together // 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 // WARNING: rshapes module is required, if not available, default internal white rectangle is used
Rectangle rec = GetFontDefault().recs[95]; Rectangle rec = GetFontDefault().recs[95];
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering // 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 }); SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
@ -1033,14 +1034,14 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
case APP_CMD_GAINED_FOCUS: case APP_CMD_GAINED_FOCUS:
{ {
platform.appEnabled = true; platform.appEnabled = true;
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; CORE_WINDOW.flags &= ~FLAG_WINDOW_UNFOCUSED;
//ResumeMusicStream(); //ResumeMusicStream();
} break; } break;
case APP_CMD_PAUSE: break; case APP_CMD_PAUSE: break;
case APP_CMD_LOST_FOCUS: case APP_CMD_LOST_FOCUS:
{ {
platform.appEnabled = false; platform.appEnabled = false;
CORE.Window.flags |= FLAG_WINDOW_UNFOCUSED; CORE_WINDOW.flags |= FLAG_WINDOW_UNFOCUSED;
//PauseMusicStream(); //PauseMusicStream();
} break; } break;
case APP_CMD_TERM_WINDOW: case APP_CMD_TERM_WINDOW:
@ -1251,11 +1252,11 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Register touch points position // Register touch points position
CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) }; CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) };
// Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize CORE.Input.Touch.position[i] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x) / (float)CORE.Window.display.width; float widthRatio = (float)(CORE_WINDOW.screen.width + CORE_WINDOW.renderOffset.x) / (float)CORE_WINDOW.display.width;
float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y) / (float)CORE.Window.display.height; float heightRatio = (float)(CORE_WINDOW.screen.height + CORE_WINDOW.renderOffset.y) / (float)CORE_WINDOW.display.height;
CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x * widthRatio - (float)CORE.Window.renderOffset.x / 2; CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x * widthRatio - (float)CORE_WINDOW.renderOffset.x / 2;
CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y * heightRatio - (float)CORE.Window.renderOffset.y / 2; CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y * heightRatio - (float)CORE_WINDOW.renderOffset.y / 2;
} }
int32_t action = AMotionEvent_getAction(event); int32_t action = AMotionEvent_getAction(event);

View File

@ -95,6 +95,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { 0 }; // Platform specific data static PlatformData platform = { 0 }; // Platform specific data
@ -137,17 +138,17 @@ static void JoystickCallback(int jid, int event);
// 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) return CORE.Window.shouldClose; if (CORE_WINDOW.ready) return CORE_WINDOW.shouldClose;
else return true; else return true;
} }
// Toggle fullscreen mode // Toggle fullscreen mode
void ToggleFullscreen(void) void ToggleFullscreen(void)
{ {
if (!CORE.Window.fullscreen) if (!CORE_WINDOW.fullscreen)
{ {
// Store previous window position (in case we exit fullscreen) // Store previous window position (in case we exit fullscreen)
glfwGetWindowPos(platform.handle, &CORE.Window.position.x, &CORE.Window.position.y); glfwGetWindowPos(platform.handle, &CORE_WINDOW.position.x, &CORE_WINDOW.position.y);
int monitorCount = 0; int monitorCount = 0;
int monitorIndex = GetCurrentMonitor(); int monitorIndex = GetCurrentMonitor();
@ -160,31 +161,31 @@ void ToggleFullscreen(void)
{ {
TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor"); TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor");
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
glfwSetWindowMonitor(platform.handle, NULL, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); glfwSetWindowMonitor(platform.handle, NULL, 0, 0, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, GLFW_DONT_CARE);
} }
else else
{ {
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
glfwSetWindowMonitor(platform.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); glfwSetWindowMonitor(platform.handle, monitor, 0, 0, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, GLFW_DONT_CARE);
} }
} }
else else
{ {
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); glfwSetWindowMonitor(platform.handle, NULL, CORE_WINDOW.position.x, CORE_WINDOW.position.y, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, GLFW_DONT_CARE);
} }
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS) // Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
// NOTE: V-Sync can be enabled by graphic driver configuration // NOTE: V-Sync can be enabled by graphic driver configuration
if (CORE.Window.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1); if (CORE_WINDOW.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1);
} }
// Toggle borderless windowed mode // Toggle borderless windowed mode
@ -192,9 +193,9 @@ void ToggleBorderlessWindowed(void)
{ {
// Leave fullscreen before attempting to set borderless windowed mode and get screen position from it // Leave fullscreen before attempting to set borderless windowed mode and get screen position from it
bool wasOnFullscreen = false; bool wasOnFullscreen = false;
if (CORE.Window.fullscreen) if (CORE_WINDOW.fullscreen)
{ {
CORE.Window.previousPosition = CORE.Window.position; CORE_WINDOW.previousPosition = CORE_WINDOW.position;
ToggleFullscreen(); ToggleFullscreen();
wasOnFullscreen = true; wasOnFullscreen = true;
} }
@ -213,14 +214,14 @@ void ToggleBorderlessWindowed(void)
{ {
// Store screen position and size // Store screen position and size
// NOTE: If it was on fullscreen, screen position was already stored, so skip setting it here // NOTE: If it was on fullscreen, screen position was already stored, so skip setting it here
if (!wasOnFullscreen) glfwGetWindowPos(platform.handle, &CORE.Window.previousPosition.x, &CORE.Window.previousPosition.y); if (!wasOnFullscreen) glfwGetWindowPos(platform.handle, &CORE_WINDOW.previousPosition.x, &CORE_WINDOW.previousPosition.y);
CORE.Window.previousScreen = CORE.Window.screen; CORE_WINDOW.previousScreen = CORE_WINDOW.screen;
// Set undecorated and topmost modes and flags // Set undecorated and topmost modes and flags
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE);
CORE.Window.flags |= FLAG_WINDOW_UNDECORATED; CORE_WINDOW.flags |= FLAG_WINDOW_UNDECORATED;
glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_TRUE);
CORE.Window.flags |= FLAG_WINDOW_TOPMOST; CORE_WINDOW.flags |= FLAG_WINDOW_TOPMOST;
// Get monitor position and size // Get monitor position and size
int monitorPosX = 0; int monitorPosX = 0;
@ -236,25 +237,25 @@ void ToggleBorderlessWindowed(void)
// Refocus window // Refocus window
glfwFocusWindow(platform.handle); glfwFocusWindow(platform.handle);
CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
} }
else else
{ {
// Remove topmost and undecorated modes and flags // Remove topmost and undecorated modes and flags
glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_FALSE);
CORE.Window.flags &= ~FLAG_WINDOW_TOPMOST; CORE_WINDOW.flags &= ~FLAG_WINDOW_TOPMOST;
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE);
CORE.Window.flags &= ~FLAG_WINDOW_UNDECORATED; CORE_WINDOW.flags &= ~FLAG_WINDOW_UNDECORATED;
// Return previous screen size and position // Return previous screen size and position
// NOTE: The order matters here, it must set size first, then set position, otherwise the screen will be positioned incorrectly // NOTE: The order matters here, it must set size first, then set position, otherwise the screen will be positioned incorrectly
glfwSetWindowSize(platform.handle, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height); glfwSetWindowSize(platform.handle, CORE_WINDOW.previousScreen.width, CORE_WINDOW.previousScreen.height);
glfwSetWindowPos(platform.handle, CORE.Window.previousPosition.x, CORE.Window.previousPosition.y); glfwSetWindowPos(platform.handle, CORE_WINDOW.previousPosition.x, CORE_WINDOW.previousPosition.y);
// Refocus window // Refocus window
glfwFocusWindow(platform.handle); glfwFocusWindow(platform.handle);
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
} }
} }
else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor");
@ -268,7 +269,7 @@ void MaximizeWindow(void)
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
{ {
glfwMaximizeWindow(platform.handle); glfwMaximizeWindow(platform.handle);
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; CORE_WINDOW.flags |= FLAG_WINDOW_MAXIMIZED;
} }
} }
@ -286,8 +287,8 @@ void RestoreWindow(void)
{ {
// Restores the specified window if it was previously iconified (minimized) or maximized // Restores the specified window if it was previously iconified (minimized) or maximized
glfwRestoreWindow(platform.handle); glfwRestoreWindow(platform.handle);
CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED;
CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; CORE_WINDOW.flags &= ~FLAG_WINDOW_MAXIMIZED;
} }
} }
@ -298,109 +299,109 @@ void SetWindowState(unsigned int flags)
// NOTE: In most cases the functions already change the flags internally // NOTE: In most cases the functions already change the flags internally
// State change: FLAG_VSYNC_HINT // State change: FLAG_VSYNC_HINT
if (((CORE.Window.flags & FLAG_VSYNC_HINT) != (flags & FLAG_VSYNC_HINT)) && ((flags & FLAG_VSYNC_HINT) > 0)) if (((CORE_WINDOW.flags & FLAG_VSYNC_HINT) != (flags & FLAG_VSYNC_HINT)) && ((flags & FLAG_VSYNC_HINT) > 0))
{ {
glfwSwapInterval(1); glfwSwapInterval(1);
CORE.Window.flags |= FLAG_VSYNC_HINT; CORE_WINDOW.flags |= FLAG_VSYNC_HINT;
} }
// State change: FLAG_BORDERLESS_WINDOWED_MODE // State change: FLAG_BORDERLESS_WINDOWED_MODE
// NOTE: This must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running // NOTE: This must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running
if (((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) != (flags & FLAG_BORDERLESS_WINDOWED_MODE)) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0)) if (((CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) != (flags & FLAG_BORDERLESS_WINDOWED_MODE)) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0))
{ {
ToggleBorderlessWindowed(); // NOTE: Window state flag updated inside function ToggleBorderlessWindowed(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_FULLSCREEN_MODE // State change: FLAG_FULLSCREEN_MODE
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) != (flags & FLAG_FULLSCREEN_MODE)) if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) != (flags & FLAG_FULLSCREEN_MODE))
{ {
ToggleFullscreen(); // NOTE: Window state flag updated inside function ToggleFullscreen(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_WINDOW_RESIZABLE // State change: FLAG_WINDOW_RESIZABLE
if (((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != (flags & FLAG_WINDOW_RESIZABLE)) && ((flags & FLAG_WINDOW_RESIZABLE) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) != (flags & FLAG_WINDOW_RESIZABLE)) && ((flags & FLAG_WINDOW_RESIZABLE) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE);
CORE.Window.flags |= FLAG_WINDOW_RESIZABLE; CORE_WINDOW.flags |= FLAG_WINDOW_RESIZABLE;
} }
// State change: FLAG_WINDOW_UNDECORATED // State change: FLAG_WINDOW_UNDECORATED
if (((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) != (flags & FLAG_WINDOW_UNDECORATED)) && (flags & FLAG_WINDOW_UNDECORATED)) if (((CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED) != (flags & FLAG_WINDOW_UNDECORATED)) && (flags & FLAG_WINDOW_UNDECORATED))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE);
CORE.Window.flags |= FLAG_WINDOW_UNDECORATED; CORE_WINDOW.flags |= FLAG_WINDOW_UNDECORATED;
} }
// State change: FLAG_WINDOW_HIDDEN // State change: FLAG_WINDOW_HIDDEN
if (((CORE.Window.flags & FLAG_WINDOW_HIDDEN) != (flags & FLAG_WINDOW_HIDDEN)) && ((flags & FLAG_WINDOW_HIDDEN) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_HIDDEN) != (flags & FLAG_WINDOW_HIDDEN)) && ((flags & FLAG_WINDOW_HIDDEN) > 0))
{ {
glfwHideWindow(platform.handle); glfwHideWindow(platform.handle);
CORE.Window.flags |= FLAG_WINDOW_HIDDEN; CORE_WINDOW.flags |= FLAG_WINDOW_HIDDEN;
} }
// State change: FLAG_WINDOW_MINIMIZED // State change: FLAG_WINDOW_MINIMIZED
if (((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) != (flags & FLAG_WINDOW_MINIMIZED)) && ((flags & FLAG_WINDOW_MINIMIZED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) != (flags & FLAG_WINDOW_MINIMIZED)) && ((flags & FLAG_WINDOW_MINIMIZED) > 0))
{ {
//GLFW_ICONIFIED //GLFW_ICONIFIED
MinimizeWindow(); // NOTE: Window state flag updated inside function MinimizeWindow(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_WINDOW_MAXIMIZED // State change: FLAG_WINDOW_MAXIMIZED
if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) != (flags & FLAG_WINDOW_MAXIMIZED)) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_MAXIMIZED) != (flags & FLAG_WINDOW_MAXIMIZED)) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0))
{ {
//GLFW_MAXIMIZED //GLFW_MAXIMIZED
MaximizeWindow(); // NOTE: Window state flag updated inside function MaximizeWindow(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_WINDOW_UNFOCUSED // State change: FLAG_WINDOW_UNFOCUSED
if (((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) != (flags & FLAG_WINDOW_UNFOCUSED)) && ((flags & FLAG_WINDOW_UNFOCUSED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_UNFOCUSED) != (flags & FLAG_WINDOW_UNFOCUSED)) && ((flags & FLAG_WINDOW_UNFOCUSED) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_FOCUS_ON_SHOW, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
CORE.Window.flags |= FLAG_WINDOW_UNFOCUSED; CORE_WINDOW.flags |= FLAG_WINDOW_UNFOCUSED;
} }
// State change: FLAG_WINDOW_TOPMOST // State change: FLAG_WINDOW_TOPMOST
if (((CORE.Window.flags & FLAG_WINDOW_TOPMOST) != (flags & FLAG_WINDOW_TOPMOST)) && ((flags & FLAG_WINDOW_TOPMOST) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_TOPMOST) != (flags & FLAG_WINDOW_TOPMOST)) && ((flags & FLAG_WINDOW_TOPMOST) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_TRUE);
CORE.Window.flags |= FLAG_WINDOW_TOPMOST; CORE_WINDOW.flags |= FLAG_WINDOW_TOPMOST;
} }
// State change: FLAG_WINDOW_ALWAYS_RUN // State change: FLAG_WINDOW_ALWAYS_RUN
if (((CORE.Window.flags & FLAG_WINDOW_ALWAYS_RUN) != (flags & FLAG_WINDOW_ALWAYS_RUN)) && ((flags & FLAG_WINDOW_ALWAYS_RUN) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_ALWAYS_RUN) != (flags & FLAG_WINDOW_ALWAYS_RUN)) && ((flags & FLAG_WINDOW_ALWAYS_RUN) > 0))
{ {
CORE.Window.flags |= FLAG_WINDOW_ALWAYS_RUN; CORE_WINDOW.flags |= FLAG_WINDOW_ALWAYS_RUN;
} }
// The following states can not be changed after window creation // The following states can not be changed after window creation
// State change: FLAG_WINDOW_TRANSPARENT // State change: FLAG_WINDOW_TRANSPARENT
if (((CORE.Window.flags & FLAG_WINDOW_TRANSPARENT) != (flags & FLAG_WINDOW_TRANSPARENT)) && ((flags & FLAG_WINDOW_TRANSPARENT) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_TRANSPARENT) != (flags & FLAG_WINDOW_TRANSPARENT)) && ((flags & FLAG_WINDOW_TRANSPARENT) > 0))
{ {
TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization"); TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization");
} }
// State change: FLAG_WINDOW_HIGHDPI // State change: FLAG_WINDOW_HIGHDPI
if (((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) != (flags & FLAG_WINDOW_HIGHDPI)) && ((flags & FLAG_WINDOW_HIGHDPI) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) != (flags & FLAG_WINDOW_HIGHDPI)) && ((flags & FLAG_WINDOW_HIGHDPI) > 0))
{ {
TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization"); TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization");
} }
// State change: FLAG_WINDOW_MOUSE_PASSTHROUGH // State change: FLAG_WINDOW_MOUSE_PASSTHROUGH
if (((CORE.Window.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) != (flags & FLAG_WINDOW_MOUSE_PASSTHROUGH)) && ((flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) != (flags & FLAG_WINDOW_MOUSE_PASSTHROUGH)) && ((flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);
CORE.Window.flags |= FLAG_WINDOW_MOUSE_PASSTHROUGH; CORE_WINDOW.flags |= FLAG_WINDOW_MOUSE_PASSTHROUGH;
} }
// State change: FLAG_MSAA_4X_HINT // State change: FLAG_MSAA_4X_HINT
if (((CORE.Window.flags & FLAG_MSAA_4X_HINT) != (flags & FLAG_MSAA_4X_HINT)) && ((flags & FLAG_MSAA_4X_HINT) > 0)) if (((CORE_WINDOW.flags & FLAG_MSAA_4X_HINT) != (flags & FLAG_MSAA_4X_HINT)) && ((flags & FLAG_MSAA_4X_HINT) > 0))
{ {
TRACELOG(LOG_WARNING, "WINDOW: MSAA can only be configured before window initialization"); TRACELOG(LOG_WARNING, "WINDOW: MSAA can only be configured before window initialization");
} }
// State change: FLAG_INTERLACED_HINT // State change: FLAG_INTERLACED_HINT
if (((CORE.Window.flags & FLAG_INTERLACED_HINT) != (flags & FLAG_INTERLACED_HINT)) && ((flags & FLAG_INTERLACED_HINT) > 0)) if (((CORE_WINDOW.flags & FLAG_INTERLACED_HINT) != (flags & FLAG_INTERLACED_HINT)) && ((flags & FLAG_INTERLACED_HINT) > 0))
{ {
TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization"); TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization");
} }
@ -413,107 +414,107 @@ void ClearWindowState(unsigned int flags)
// NOTE: In most cases the functions already change the flags internally // NOTE: In most cases the functions already change the flags internally
// State change: FLAG_VSYNC_HINT // State change: FLAG_VSYNC_HINT
if (((CORE.Window.flags & FLAG_VSYNC_HINT) > 0) && ((flags & FLAG_VSYNC_HINT) > 0)) if (((CORE_WINDOW.flags & FLAG_VSYNC_HINT) > 0) && ((flags & FLAG_VSYNC_HINT) > 0))
{ {
glfwSwapInterval(0); glfwSwapInterval(0);
CORE.Window.flags &= ~FLAG_VSYNC_HINT; CORE_WINDOW.flags &= ~FLAG_VSYNC_HINT;
} }
// State change: FLAG_BORDERLESS_WINDOWED_MODE // State change: FLAG_BORDERLESS_WINDOWED_MODE
// NOTE: This must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running // NOTE: This must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running
if (((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0)) if (((CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0))
{ {
ToggleBorderlessWindowed(); // NOTE: Window state flag updated inside function ToggleBorderlessWindowed(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_FULLSCREEN_MODE // State change: FLAG_FULLSCREEN_MODE
if (((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) && ((flags & FLAG_FULLSCREEN_MODE) > 0)) if (((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0) && ((flags & FLAG_FULLSCREEN_MODE) > 0))
{ {
ToggleFullscreen(); // NOTE: Window state flag updated inside function ToggleFullscreen(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_WINDOW_RESIZABLE // State change: FLAG_WINDOW_RESIZABLE
if (((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) && ((flags & FLAG_WINDOW_RESIZABLE) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) > 0) && ((flags & FLAG_WINDOW_RESIZABLE) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE);
CORE.Window.flags &= ~FLAG_WINDOW_RESIZABLE; CORE_WINDOW.flags &= ~FLAG_WINDOW_RESIZABLE;
} }
// State change: FLAG_WINDOW_HIDDEN // State change: FLAG_WINDOW_HIDDEN
if (((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0) && ((flags & FLAG_WINDOW_HIDDEN) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_HIDDEN) > 0) && ((flags & FLAG_WINDOW_HIDDEN) > 0))
{ {
glfwShowWindow(platform.handle); glfwShowWindow(platform.handle);
CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; CORE_WINDOW.flags &= ~FLAG_WINDOW_HIDDEN;
} }
// State change: FLAG_WINDOW_MINIMIZED // State change: FLAG_WINDOW_MINIMIZED
if (((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) && ((flags & FLAG_WINDOW_MINIMIZED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) && ((flags & FLAG_WINDOW_MINIMIZED) > 0))
{ {
RestoreWindow(); // NOTE: Window state flag updated inside function RestoreWindow(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_WINDOW_MAXIMIZED // State change: FLAG_WINDOW_MAXIMIZED
if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_MAXIMIZED) > 0) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0))
{ {
RestoreWindow(); // NOTE: Window state flag updated inside function RestoreWindow(); // NOTE: Window state flag updated inside function
} }
// State change: FLAG_WINDOW_UNDECORATED // State change: FLAG_WINDOW_UNDECORATED
if (((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) > 0) && ((flags & FLAG_WINDOW_UNDECORATED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED) > 0) && ((flags & FLAG_WINDOW_UNDECORATED) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE);
CORE.Window.flags &= ~FLAG_WINDOW_UNDECORATED; CORE_WINDOW.flags &= ~FLAG_WINDOW_UNDECORATED;
} }
// State change: FLAG_WINDOW_UNFOCUSED // State change: FLAG_WINDOW_UNFOCUSED
if (((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) > 0) && ((flags & FLAG_WINDOW_UNFOCUSED) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_UNFOCUSED) > 0) && ((flags & FLAG_WINDOW_UNFOCUSED) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_FOCUS_ON_SHOW, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; CORE_WINDOW.flags &= ~FLAG_WINDOW_UNFOCUSED;
} }
// State change: FLAG_WINDOW_TOPMOST // State change: FLAG_WINDOW_TOPMOST
if (((CORE.Window.flags & FLAG_WINDOW_TOPMOST) > 0) && ((flags & FLAG_WINDOW_TOPMOST) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_TOPMOST) > 0) && ((flags & FLAG_WINDOW_TOPMOST) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_FALSE);
CORE.Window.flags &= ~FLAG_WINDOW_TOPMOST; CORE_WINDOW.flags &= ~FLAG_WINDOW_TOPMOST;
} }
// State change: FLAG_WINDOW_ALWAYS_RUN // State change: FLAG_WINDOW_ALWAYS_RUN
if (((CORE.Window.flags & FLAG_WINDOW_ALWAYS_RUN) > 0) && ((flags & FLAG_WINDOW_ALWAYS_RUN) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_ALWAYS_RUN) > 0) && ((flags & FLAG_WINDOW_ALWAYS_RUN) > 0))
{ {
CORE.Window.flags &= ~FLAG_WINDOW_ALWAYS_RUN; CORE_WINDOW.flags &= ~FLAG_WINDOW_ALWAYS_RUN;
} }
// The following states can not be changed after window creation // The following states can not be changed after window creation
// State change: FLAG_WINDOW_TRANSPARENT // State change: FLAG_WINDOW_TRANSPARENT
if (((CORE.Window.flags & FLAG_WINDOW_TRANSPARENT) > 0) && ((flags & FLAG_WINDOW_TRANSPARENT) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_TRANSPARENT) > 0) && ((flags & FLAG_WINDOW_TRANSPARENT) > 0))
{ {
TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization"); TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization");
} }
// State change: FLAG_WINDOW_HIGHDPI // State change: FLAG_WINDOW_HIGHDPI
if (((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) && ((flags & FLAG_WINDOW_HIGHDPI) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0) && ((flags & FLAG_WINDOW_HIGHDPI) > 0))
{ {
TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization"); TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization");
} }
// State change: FLAG_WINDOW_MOUSE_PASSTHROUGH // State change: FLAG_WINDOW_MOUSE_PASSTHROUGH
if (((CORE.Window.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0) && ((flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0) && ((flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_MOUSE_PASSTHROUGH, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_MOUSE_PASSTHROUGH, GLFW_FALSE);
CORE.Window.flags &= ~FLAG_WINDOW_MOUSE_PASSTHROUGH; CORE_WINDOW.flags &= ~FLAG_WINDOW_MOUSE_PASSTHROUGH;
} }
// State change: FLAG_MSAA_4X_HINT // State change: FLAG_MSAA_4X_HINT
if (((CORE.Window.flags & FLAG_MSAA_4X_HINT) > 0) && ((flags & FLAG_MSAA_4X_HINT) > 0)) if (((CORE_WINDOW.flags & FLAG_MSAA_4X_HINT) > 0) && ((flags & FLAG_MSAA_4X_HINT) > 0))
{ {
TRACELOG(LOG_WARNING, "WINDOW: MSAA can only be configured before window initialization"); TRACELOG(LOG_WARNING, "WINDOW: MSAA can only be configured before window initialization");
} }
// State change: FLAG_INTERLACED_HINT // State change: FLAG_INTERLACED_HINT
if (((CORE.Window.flags & FLAG_INTERLACED_HINT) > 0) && ((flags & FLAG_INTERLACED_HINT) > 0)) if (((CORE_WINDOW.flags & FLAG_INTERLACED_HINT) > 0) && ((flags & FLAG_INTERLACED_HINT) > 0))
{ {
TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization"); TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization");
} }
@ -585,7 +586,7 @@ void SetWindowIcons(Image *images, int count)
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
CORE.Window.title = title; CORE_WINDOW.title = title;
glfwSetWindowTitle(platform.handle, title); glfwSetWindowTitle(platform.handle, title);
} }
@ -603,7 +604,7 @@ void SetWindowMonitor(int monitor)
if ((monitor >= 0) && (monitor < monitorCount)) if ((monitor >= 0) && (monitor < monitorCount))
{ {
if (CORE.Window.fullscreen) if (CORE_WINDOW.fullscreen)
{ {
TRACELOG(LOG_INFO, "GLFW: Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor])); TRACELOG(LOG_INFO, "GLFW: Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));
@ -614,8 +615,8 @@ void SetWindowMonitor(int monitor)
{ {
TRACELOG(LOG_INFO, "GLFW: Selected monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor])); TRACELOG(LOG_INFO, "GLFW: Selected monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));
const int screenWidth = CORE.Window.screen.width; const int screenWidth = CORE_WINDOW.screen.width;
const int screenHeight = CORE.Window.screen.height; const int screenHeight = CORE_WINDOW.screen.height;
int monitorWorkareaX = 0; int monitorWorkareaX = 0;
int monitorWorkareaY = 0; int monitorWorkareaY = 0;
int monitorWorkareaWidth = 0; int monitorWorkareaWidth = 0;
@ -638,13 +639,13 @@ void SetWindowMonitor(int monitor)
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMinSize(int width, int height) void SetWindowMinSize(int width, int height)
{ {
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.width; int minWidth = (CORE_WINDOW.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMin.width;
int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.height; int minHeight = (CORE_WINDOW.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMin.height;
int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.width; int maxWidth = (CORE_WINDOW.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMax.width;
int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.height; int maxHeight = (CORE_WINDOW.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMax.height;
glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight); glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight);
} }
@ -652,13 +653,13 @@ void SetWindowMinSize(int width, int height)
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height) void SetWindowMaxSize(int width, int height)
{ {
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.width; int minWidth = (CORE_WINDOW.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMin.width;
int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.height; int minHeight = (CORE_WINDOW.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMin.height;
int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.width; int maxWidth = (CORE_WINDOW.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMax.width;
int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.height; int maxHeight = (CORE_WINDOW.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE_WINDOW.screenMax.height;
glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight); glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight);
} }
@ -754,8 +755,8 @@ int GetCurrentMonitor(void)
int wcy = 0; int wcy = 0;
glfwGetWindowPos(platform.handle, &wcx, &wcy); glfwGetWindowPos(platform.handle, &wcx, &wcy);
wcx += (int)CORE.Window.screen.width/2; wcx += (int)CORE_WINDOW.screen.width/2;
wcy += (int)CORE.Window.screen.height/2; wcy += (int)CORE_WINDOW.screen.height/2;
for (int i = 0; i < monitorCount; i++) for (int i = 0; i < monitorCount; i++)
{ {
@ -970,7 +971,7 @@ void EnableCursor(void)
glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE);
@ -983,7 +984,7 @@ void DisableCursor(void)
glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE); if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
@ -1199,15 +1200,15 @@ void PollInputEvents(void)
} }
} }
CORE.Window.resizedLastFrame = false; CORE_WINDOW.resizedLastFrame = false;
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) -> Update keys state else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks) -> Update keys state
// While window minimized, stop loop execution // While window minimized, stop loop execution
while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents(); while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents();
CORE.Window.shouldClose = glfwWindowShouldClose(platform.handle); CORE_WINDOW.shouldClose = glfwWindowShouldClose(platform.handle);
// Reset close status for next frame // Reset close status for next frame
glfwSetWindowShouldClose(platform.handle, GLFW_FALSE); glfwSetWindowShouldClose(platform.handle, GLFW_FALSE);
@ -1223,12 +1224,12 @@ static void SetDimensionsFromMonitor(GLFWmonitor *monitor)
const GLFWvidmode *mode = glfwGetVideoMode(monitor); const GLFWvidmode *mode = glfwGetVideoMode(monitor);
// Default display resolution to that of the current mode // Default display resolution to that of the current mode
CORE.Window.display.width = mode->width; CORE_WINDOW.display.width = mode->width;
CORE.Window.display.height = mode->height; CORE_WINDOW.display.height = mode->height;
// Set screen width/height to the display width/height if they are 0 // Set screen width/height to the display width/height if they are 0
if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width; if (CORE_WINDOW.screen.width == 0) CORE_WINDOW.screen.width = CORE_WINDOW.display.width;
if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height; if (CORE_WINDOW.screen.height == 0) CORE_WINDOW.screen.height = CORE_WINDOW.display.height;
} }
// Initialize platform: graphics, inputs and more // Initialize platform: graphics, inputs and more
@ -1267,34 +1268,34 @@ int InitPlatform(void)
//glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
// Check window creation flags // Check window creation flags
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) CORE.Window.fullscreen = true; if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0) CORE_WINDOW.fullscreen = true;
if ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window if ((CORE_WINDOW.flags & FLAG_WINDOW_HIDDEN) > 0) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window
else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden
if ((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) > 0) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window if ((CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED) > 0) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window
else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) > 0) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window
else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable
// Disable FLAG_WINDOW_MINIMIZED, not supported on initialization // Disable FLAG_WINDOW_MINIMIZED, not supported on initialization
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED;
// Disable FLAG_WINDOW_MAXIMIZED, not supported on initialization // Disable FLAG_WINDOW_MAXIMIZED, not supported on initialization
if ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; if ((CORE_WINDOW.flags & FLAG_WINDOW_MAXIMIZED) > 0) CORE_WINDOW.flags &= ~FLAG_WINDOW_MAXIMIZED;
if ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) > 0) glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE); if ((CORE_WINDOW.flags & FLAG_WINDOW_UNFOCUSED) > 0) glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
else glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE); else glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE);
if ((CORE.Window.flags & FLAG_WINDOW_TOPMOST) > 0) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE); if ((CORE_WINDOW.flags & FLAG_WINDOW_TOPMOST) > 0) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE); else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
// NOTE: Some GLFW flags are not supported on HTML5 // NOTE: Some GLFW flags are not supported on HTML5
if ((CORE.Window.flags & FLAG_WINDOW_TRANSPARENT) > 0) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); // Transparent framebuffer if ((CORE_WINDOW.flags & FLAG_WINDOW_TRANSPARENT) > 0) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); // Transparent framebuffer
else glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); // Opaque framebuffer else glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); // Opaque framebuffer
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
// Resize window content area based on the monitor content scale. // Resize window content area based on the monitor content scale.
// NOTE: This hint only has an effect on platforms where screen coordinates and pixels always map 1:1 such as Windows and X11. // NOTE: This hint only has an effect on platforms where screen coordinates and pixels always map 1:1 such as Windows and X11.
@ -1307,10 +1308,10 @@ int InitPlatform(void)
else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE); else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE);
// Mouse passthrough // Mouse passthrough
if ((CORE.Window.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0) glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE); if ((CORE_WINDOW.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0) glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);
else glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_FALSE); else glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_FALSE);
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
// NOTE: MSAA is only enabled for main framebuffer, not user-created FBOs // NOTE: MSAA is only enabled for main framebuffer, not user-created FBOs
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4"); TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4");
@ -1372,7 +1373,7 @@ int InitPlatform(void)
glfwSetJoystickCallback(NULL); glfwSetJoystickCallback(NULL);
GLFWmonitor *monitor = NULL; GLFWmonitor *monitor = NULL;
if (CORE.Window.fullscreen) if (CORE_WINDOW.fullscreen)
{ {
// According to glfwCreateWindow(), if the user does not have a choice, fullscreen applications // According to glfwCreateWindow(), if the user does not have a choice, fullscreen applications
// should default to the primary monitor. // should default to the primary monitor.
@ -1387,41 +1388,41 @@ int InitPlatform(void)
SetDimensionsFromMonitor(monitor); SetDimensionsFromMonitor(monitor);
// Remember center for switching from fullscreen to window // Remember center for switching from fullscreen to window
if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width)) if ((CORE_WINDOW.screen.height == CORE_WINDOW.display.height) && (CORE_WINDOW.screen.width == CORE_WINDOW.display.width))
{ {
// If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed. // If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed.
// Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11. // Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11.
CORE.Window.position.x = CORE.Window.display.width/4; CORE_WINDOW.position.x = CORE_WINDOW.display.width/4;
CORE.Window.position.y = CORE.Window.display.height/4; CORE_WINDOW.position.y = CORE_WINDOW.display.height/4;
} }
else else
{ {
CORE.Window.position.x = CORE.Window.display.width/2 - CORE.Window.screen.width/2; CORE_WINDOW.position.x = CORE_WINDOW.display.width/2 - CORE_WINDOW.screen.width/2;
CORE.Window.position.y = CORE.Window.display.height/2 - CORE.Window.screen.height/2; CORE_WINDOW.position.y = CORE_WINDOW.display.height/2 - CORE_WINDOW.screen.height/2;
} }
if (CORE.Window.position.x < 0) CORE.Window.position.x = 0; if (CORE_WINDOW.position.x < 0) CORE_WINDOW.position.x = 0;
if (CORE.Window.position.y < 0) CORE.Window.position.y = 0; if (CORE_WINDOW.position.y < 0) CORE_WINDOW.position.y = 0;
// Obtain recommended CORE.Window.display.width/CORE.Window.display.height from a valid videomode for the monitor // Obtain recommended CORE_WINDOW.display.width/CORE_WINDOW.display.height from a valid videomode for the monitor
int count = 0; int count = 0;
const GLFWvidmode *modes = glfwGetVideoModes(monitor, &count); const GLFWvidmode *modes = glfwGetVideoModes(monitor, &count);
// Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height // Get closest video mode to desired CORE_WINDOW.screen.width/CORE_WINDOW.screen.height
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
if ((unsigned int)modes[i].width >= CORE.Window.screen.width) if ((unsigned int)modes[i].width >= CORE_WINDOW.screen.width)
{ {
if ((unsigned int)modes[i].height >= CORE.Window.screen.height) if ((unsigned int)modes[i].height >= CORE_WINDOW.screen.height)
{ {
CORE.Window.display.width = modes[i].width; CORE_WINDOW.display.width = modes[i].width;
CORE.Window.display.height = modes[i].height; CORE_WINDOW.display.height = modes[i].height;
break; break;
} }
} }
} }
TRACELOG(LOG_WARNING, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_WARNING, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
// NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example, // NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example,
// for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3), // for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3),
@ -1430,20 +1431,20 @@ int InitPlatform(void)
// Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight // Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight
// It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset) // It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset)
// Modified global variables: CORE.Window.screen.width/CORE.Window.screen.height - CORE.Window.render.width/CORE.Window.render.height - CORE.Window.renderOffset.x/CORE.Window.renderOffset.y - CORE.Window.screenScale // Modified global variables: CORE_WINDOW.screen.width/CORE_WINDOW.screen.height - CORE_WINDOW.render.width/CORE_WINDOW.render.height - CORE_WINDOW.renderOffset.x/CORE_WINDOW.renderOffset.y - CORE_WINDOW.screenScale
// TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed... // TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed...
// HighDPI monitors are properly considered in a following similar function: SetupViewport() // HighDPI monitors are properly considered in a following similar function: SetupViewport()
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); SetupFramebuffer(CORE_WINDOW.display.width, CORE_WINDOW.display.height);
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL); platform.handle = glfwCreateWindow(CORE_WINDOW.display.width, CORE_WINDOW.display.height, (CORE_WINDOW.title != 0)? CORE_WINDOW.title : " ", monitor, NULL);
// NOTE: Full-screen change, not working properly... // NOTE: Full-screen change, not working properly...
//glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); //glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, GLFW_DONT_CARE);
} }
else else
{ {
// No-fullscreen window creation // No-fullscreen window creation
bool wantWindowedFullscreen = (CORE.Window.screen.height == 0) && (CORE.Window.screen.width == 0); bool wantWindowedFullscreen = (CORE_WINDOW.screen.height == 0) && (CORE_WINDOW.screen.width == 0);
// If we are windowed fullscreen, ensures that window does not minimize when focus is lost. // If we are windowed fullscreen, ensures that window does not minimize when focus is lost.
// This hinting code will not work if the user already specified the correct monitor dimensions; // This hinting code will not work if the user already specified the correct monitor dimensions;
@ -1454,10 +1455,10 @@ int InitPlatform(void)
} }
// Default to at least one pixel in size, as creation with a zero dimension is not allowed. // Default to at least one pixel in size, as creation with a zero dimension is not allowed.
int creationWidth = CORE.Window.screen.width != 0 ? CORE.Window.screen.width : 1; int creationWidth = CORE_WINDOW.screen.width != 0 ? CORE_WINDOW.screen.width : 1;
int creationHeight = CORE.Window.screen.height != 0 ? CORE.Window.screen.height : 1; int creationHeight = CORE_WINDOW.screen.height != 0 ? CORE_WINDOW.screen.height : 1;
platform.handle = glfwCreateWindow(creationWidth, creationHeight, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL); platform.handle = glfwCreateWindow(creationWidth, creationHeight, (CORE_WINDOW.title != 0)? CORE_WINDOW.title : " ", NULL, NULL);
// After the window was created, determine the monitor that the window manager assigned. // After the window was created, determine the monitor that the window manager assigned.
// Derive display sizes, and, if possible, window size in case it was zero at beginning. // Derive display sizes, and, if possible, window size in case it was zero at beginning.
@ -1471,10 +1472,10 @@ int InitPlatform(void)
monitor = monitors[monitorIndex]; monitor = monitors[monitorIndex];
SetDimensionsFromMonitor(monitor); SetDimensionsFromMonitor(monitor);
TRACELOG(LOG_INFO, "wantWindowed: %d, size: %dx%d", wantWindowedFullscreen, CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, "wantWindowed: %d, size: %dx%d", wantWindowedFullscreen, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
if (wantWindowedFullscreen) if (wantWindowedFullscreen)
{ {
glfwSetWindowSize(platform.handle, CORE.Window.screen.width, CORE.Window.screen.height); glfwSetWindowSize(platform.handle, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
} }
} }
else else
@ -1487,8 +1488,8 @@ int InitPlatform(void)
if (platform.handle) if (platform.handle)
{ {
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
} }
} }
@ -1505,24 +1506,24 @@ int InitPlatform(void)
// Check context activation // Check context activation
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR)) if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
{ {
CORE.Window.ready = true; CORE_WINDOW.ready = true;
glfwSwapInterval(0); // No V-Sync by default glfwSwapInterval(0); // No V-Sync by default
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS) // Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need // NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
// to be activated on web platforms since VSync is enforced there. // to be activated on web platforms since VSync is enforced there.
if (CORE.Window.flags & FLAG_VSYNC_HINT) if (CORE_WINDOW.flags & FLAG_VSYNC_HINT)
{ {
// WARNING: It seems to hit a critical render path in Intel HD Graphics // WARNING: It seems to hit a critical render path in Intel HD Graphics
glfwSwapInterval(1); glfwSwapInterval(1);
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC"); TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC");
} }
int fbWidth = CORE.Window.screen.width; int fbWidth = CORE_WINDOW.screen.width;
int fbHeight = CORE.Window.screen.height; int fbHeight = CORE_WINDOW.screen.height;
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling. // NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling.
// Framebuffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE); // Framebuffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
@ -1530,23 +1531,23 @@ int InitPlatform(void)
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight); glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
// Screen scaling matrix is required in case desired screen area is different from display area // Screen scaling matrix is required in case desired screen area is different from display area
CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f); CORE_WINDOW.screenScale = MatrixScale((float)fbWidth/CORE_WINDOW.screen.width, (float)fbHeight/CORE_WINDOW.screen.height, 1.0f);
// Mouse input scaling for the new screen size // Mouse input scaling for the new screen size
SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight); SetMouseScale((float)CORE_WINDOW.screen.width/fbWidth, (float)CORE_WINDOW.screen.height/fbHeight);
#endif #endif
} }
CORE.Window.render.width = fbWidth; CORE_WINDOW.render.width = fbWidth;
CORE.Window.render.height = fbHeight; CORE_WINDOW.render.height = fbHeight;
CORE.Window.currentFbo.width = fbWidth; CORE_WINDOW.currentFbo.width = fbWidth;
CORE.Window.currentFbo.height = fbHeight; CORE_WINDOW.currentFbo.height = fbHeight;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
else else
{ {
@ -1554,10 +1555,10 @@ int InitPlatform(void)
return -1; return -1;
} }
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow(); if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
// If graphic device is no properly initialized, we end program // If graphic device is no properly initialized, we end program
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; } if (!CORE_WINDOW.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
else else
{ {
// Try to center window on screen but avoiding window-bar outside of screen // Try to center window on screen but avoiding window-bar outside of screen
@ -1567,8 +1568,8 @@ int InitPlatform(void)
int monitorHeight = 0; int monitorHeight = 0;
glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight); glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight);
int posX = monitorX + (monitorWidth - (int)CORE.Window.screen.width)/2; int posX = monitorX + (monitorWidth - (int)CORE_WINDOW.screen.width)/2;
int posY = monitorY + (monitorHeight - (int)CORE.Window.screen.height)/2; int posY = monitorY + (monitorHeight - (int)CORE_WINDOW.screen.height)/2;
if (posX < monitorX) posX = monitorX; if (posX < monitorX) posX = monitorX;
if (posY < monitorY) posY = monitorY; if (posY < monitorY) posY = monitorY;
SetWindowPosition(posX, posY); SetWindowPosition(posX, posY);
@ -1588,7 +1589,7 @@ int InitPlatform(void)
glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback); glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback);
glfwSetDropCallback(platform.handle, WindowDropCallback); glfwSetDropCallback(platform.handle, WindowDropCallback);
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback); glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback);
} }
@ -1661,28 +1662,28 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
// Reset viewport and projection matrix for new size // Reset viewport and projection matrix for new size
SetupViewport(width, height); SetupViewport(width, height);
CORE.Window.currentFbo.width = width; CORE_WINDOW.currentFbo.width = width;
CORE.Window.currentFbo.height = height; CORE_WINDOW.currentFbo.height = height;
CORE.Window.resizedLastFrame = true; CORE_WINDOW.resizedLastFrame = true;
if (IsWindowFullscreen()) return; if (IsWindowFullscreen()) return;
// Set current screen size // Set current screen size
#if defined(__APPLE__) #if defined(__APPLE__)
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
#else #else
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
Vector2 windowScaleDPI = GetWindowScaleDPI(); Vector2 windowScaleDPI = GetWindowScaleDPI();
CORE.Window.screen.width = (unsigned int)(width/windowScaleDPI.x); CORE_WINDOW.screen.width = (unsigned int)(width/windowScaleDPI.x);
CORE.Window.screen.height = (unsigned int)(height/windowScaleDPI.y); CORE_WINDOW.screen.height = (unsigned int)(height/windowScaleDPI.y);
} }
else else
{ {
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
} }
#endif #endif
@ -1691,28 +1692,28 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley) static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley)
{ {
CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f); CORE_WINDOW.screenScale = MatrixScale(scalex, scaley, 1.0f);
} }
// GLFW3 WindowIconify Callback, runs when window is minimized/restored // GLFW3 WindowIconify Callback, runs when window is minimized/restored
static void WindowIconifyCallback(GLFWwindow *window, int iconified) static void WindowIconifyCallback(GLFWwindow *window, int iconified)
{ {
if (iconified) CORE.Window.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified if (iconified) CORE_WINDOW.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified
else CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored else CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored
} }
// GLFW3 WindowMaximize Callback, runs when window is maximized/restored // GLFW3 WindowMaximize Callback, runs when window is maximized/restored
static void WindowMaximizeCallback(GLFWwindow *window, int maximized) static void WindowMaximizeCallback(GLFWwindow *window, int maximized)
{ {
if (maximized) CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // The window was maximized if (maximized) CORE_WINDOW.flags |= FLAG_WINDOW_MAXIMIZED; // The window was maximized
else CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; // The window was restored else CORE_WINDOW.flags &= ~FLAG_WINDOW_MAXIMIZED; // The window was restored
} }
// GLFW3 WindowFocus Callback, runs when window get/lose focus // GLFW3 WindowFocus Callback, runs when window get/lose focus
static void WindowFocusCallback(GLFWwindow *window, int focused) static void WindowFocusCallback(GLFWwindow *window, int focused)
{ {
if (focused) CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // The window was focused if (focused) CORE_WINDOW.flags &= ~FLAG_WINDOW_UNFOCUSED; // The window was focused
else CORE.Window.flags |= FLAG_WINDOW_UNFOCUSED; // The window lost focus else CORE_WINDOW.flags |= FLAG_WINDOW_UNFOCUSED; // The window lost focus
} }
// GLFW3 Window Drop Callback, runs when drop files into window // GLFW3 Window Drop Callback, runs when drop files into window
@ -1721,24 +1722,24 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
if (count > 0) if (count > 0)
{ {
// In case previous dropped filepaths have not been freed, we free them // In case previous dropped filepaths have not been freed, we free them
if (CORE.Window.dropFileCount > 0) if (CORE_WINDOW.dropFileCount > 0)
{ {
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]); for (unsigned int i = 0; i < CORE_WINDOW.dropFileCount; i++) RL_FREE(CORE_WINDOW.dropFilepaths[i]);
RL_FREE(CORE.Window.dropFilepaths); RL_FREE(CORE_WINDOW.dropFilepaths);
CORE.Window.dropFileCount = 0; CORE_WINDOW.dropFileCount = 0;
CORE.Window.dropFilepaths = NULL; CORE_WINDOW.dropFilepaths = NULL;
} }
// WARNING: Paths are freed by GLFW when the callback returns, we must keep an internal copy // WARNING: Paths are freed by GLFW when the callback returns, we must keep an internal copy
CORE.Window.dropFileCount = count; CORE_WINDOW.dropFileCount = count;
CORE.Window.dropFilepaths = (char **)RL_CALLOC(CORE.Window.dropFileCount, sizeof(char *)); CORE_WINDOW.dropFilepaths = (char **)RL_CALLOC(CORE_WINDOW.dropFileCount, sizeof(char *));
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) for (unsigned int i = 0; i < CORE_WINDOW.dropFileCount; i++)
{ {
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); CORE_WINDOW.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[i], paths[i]); strcpy(CORE_WINDOW.dropFilepaths[i], paths[i]);
} }
} }
} }
@ -1816,7 +1817,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
// Register touch points position, only one point registered // Register touch points position, only one point registered
gestureEvent.position[0] = GetMousePosition(); gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[0] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[0].y /= (float)GetScreenHeight();
@ -1847,7 +1848,7 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
// Register touch points position, only one point registered // Register touch points position, only one point registered
gestureEvent.position[0] = CORE.Input.Touch.position[0]; gestureEvent.position[0] = CORE.Input.Touch.position[0];
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[0] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[0].y /= (float)GetScreenHeight();

View File

@ -111,6 +111,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { NULL }; // Platform specific static PlatformData platform = { NULL }; // Platform specific
@ -132,9 +133,9 @@ bool InitGraphicsDevice(void); // Initialize graphics device
// Check if application should close // Check if application should close
bool WindowShouldClose(void) bool WindowShouldClose(void)
{ {
if (CORE.Window.shouldClose == false) if (CORE_WINDOW.shouldClose == false)
CORE.Window.shouldClose = RGFW_window_shouldClose(platform.window); CORE_WINDOW.shouldClose = RGFW_window_shouldClose(platform.window);
if (CORE.Window.ready) return CORE.Window.shouldClose; if (CORE_WINDOW.ready) return CORE_WINDOW.shouldClose;
else return true; else return true;
} }
@ -148,7 +149,7 @@ void ToggleFullscreen(void)
// Toggle borderless windowed mode // Toggle borderless windowed mode
void ToggleBorderlessWindowed(void) void ToggleBorderlessWindowed(void)
{ {
CORE.Window.flags & FLAG_WINDOW_UNDECORATED; CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED;
if (platform.window != NULL) if (platform.window != NULL)
TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() after window creation not available on target platform"); TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() after window creation not available on target platform");
@ -175,7 +176,7 @@ void RestoreWindow(void)
// Set window configuration state using flags // Set window configuration state using flags
void SetWindowState(unsigned int flags) void SetWindowState(unsigned int flags)
{ {
CORE.Window.flags |= flags; CORE_WINDOW.flags |= flags;
if (flags & FLAG_VSYNC_HINT) if (flags & FLAG_VSYNC_HINT)
{ {
@ -248,7 +249,7 @@ void SetWindowState(unsigned int flags)
// Clear window configuration state flags // Clear window configuration state flags
void ClearWindowState(unsigned int flags) void ClearWindowState(unsigned int flags)
{ {
CORE.Window.flags &= ~flags; CORE_WINDOW.flags &= ~flags;
if (flags & FLAG_VSYNC_HINT) if (flags & FLAG_VSYNC_HINT)
{ {
@ -258,7 +259,7 @@ void ClearWindowState(unsigned int flags)
{ {
ToggleBorderlessWindowed(); ToggleBorderlessWindowed();
RGFW_window_restore(platform.window); RGFW_window_restore(platform.window);
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
} }
if (flags & FLAG_WINDOW_RESIZABLE) if (flags & FLAG_WINDOW_RESIZABLE)
{ {
@ -379,7 +380,7 @@ void SetWindowIcons(Image *images, int count)
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
RGFW_window_setName(platform.window, title); RGFW_window_setName(platform.window, title);
CORE.Window.title = title; CORE_WINDOW.title = title;
} }
// Set window position on screen (windowed mode) // Set window position on screen (windowed mode)
@ -398,16 +399,16 @@ void SetWindowMonitor(int monitor)
void SetWindowMinSize(int width, int height) void SetWindowMinSize(int width, int height)
{ {
RGFW_window_setMinSize(platform.window, RGFW_AREA(width, height)); RGFW_window_setMinSize(platform.window, RGFW_AREA(width, height));
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
} }
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height) void SetWindowMaxSize(int width, int height)
{ {
RGFW_window_setMaxSize(platform.window, RGFW_AREA(width, height)); RGFW_window_setMaxSize(platform.window, RGFW_AREA(width, height));
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
} }
// Set window dimensions // Set window dimensions
@ -566,7 +567,7 @@ void EnableCursor(void)
RGFW_window_mouseUnhold(platform.window); RGFW_window_mouseUnhold(platform.window);
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
RGFW_window_showMouse(platform.window, true); RGFW_window_showMouse(platform.window, true);
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorHidden = false;
} }
@ -576,7 +577,7 @@ void DisableCursor(void)
{ {
RGFW_window_mouseHold(platform.window); RGFW_window_mouseHold(platform.window);
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
HideCursor(); HideCursor();
} }
@ -727,7 +728,7 @@ void PollInputEvents(void)
// Poll input events for current platform // Poll input events for current platform
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CORE.Window.resizedLastFrame = false; CORE_WINDOW.resizedLastFrame = false;
#define RGFW_HOLD_MOUSE (1L<<2) #define RGFW_HOLD_MOUSE (1L<<2)
@ -761,30 +762,30 @@ void PollInputEvents(void)
// All input events can be processed after polling // All input events can be processed after polling
switch (event->type) switch (event->type)
{ {
case RGFW_quit: CORE.Window.shouldClose = true; break; case RGFW_quit: CORE_WINDOW.shouldClose = true; break;
case RGFW_dnd: // Dropped file case RGFW_dnd: // Dropped file
{ {
size_t i; size_t i;
for (i = 0; i < event->droppedFilesCount; i++) { for (i = 0; i < event->droppedFilesCount; i++) {
if (CORE.Window.dropFileCount == 0) if (CORE_WINDOW.dropFileCount == 0)
{ {
// When a new file is dropped, we reserve a fixed number of slots for all possible dropped files // When a new file is dropped, we reserve a fixed number of slots for all possible dropped files
// at the moment we limit the number of drops at once to 1024 files but this behaviour should probably be reviewed // at the moment we limit the number of drops at once to 1024 files but this behaviour should probably be reviewed
// TODO: Pointers should probably be reallocated for any new file added... // TODO: Pointers should probably be reallocated for any new file added...
CORE.Window.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *)); CORE_WINDOW.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *));
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event->droppedFiles[i]); strcpy(CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount], event->droppedFiles[i]);
CORE.Window.dropFileCount++; CORE_WINDOW.dropFileCount++;
} }
else if (CORE.Window.dropFileCount < 1024) else if (CORE_WINDOW.dropFileCount < 1024)
{ {
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event->droppedFiles[i]); strcpy(CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount], event->droppedFiles[i]);
CORE.Window.dropFileCount++; CORE_WINDOW.dropFileCount++;
} }
else TRACELOG(LOG_WARNING, "FILE: Maximum drag and drop files at once is limited to 1024 files!"); else TRACELOG(LOG_WARNING, "FILE: Maximum drag and drop files at once is limited to 1024 files!");
} }
@ -794,13 +795,13 @@ void PollInputEvents(void)
case RGFW_windowAttribsChange: case RGFW_windowAttribsChange:
{ {
SetupViewport(platform.window->r.w, platform.window->r.h); SetupViewport(platform.window->r.w, platform.window->r.h);
CORE.Window.position.x = platform.window->r.x; CORE_WINDOW.position.x = platform.window->r.x;
CORE.Window.position.y = platform.window->r.x; CORE_WINDOW.position.y = platform.window->r.x;
CORE.Window.screen.width = platform.window->r.w; CORE_WINDOW.screen.width = platform.window->r.w;
CORE.Window.screen.height = platform.window->r.h; CORE_WINDOW.screen.height = platform.window->r.h;
CORE.Window.currentFbo.width = platform.window->r.w;; CORE_WINDOW.currentFbo.width = platform.window->r.w;;
CORE.Window.currentFbo.height = platform.window->r.h; CORE_WINDOW.currentFbo.height = platform.window->r.h;
CORE.Window.resizedLastFrame = true; CORE_WINDOW.resizedLastFrame = true;
} break; } break;
// Keyboard events // Keyboard events
@ -822,7 +823,7 @@ void PollInputEvents(void)
// TODO: Put exitKey verification outside the switch? // TODO: Put exitKey verification outside the switch?
if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey]) if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey])
{ {
CORE.Window.shouldClose = true; CORE_WINDOW.shouldClose = true;
} }
// NOTE: event.text.text data comes an UTF-8 text sequence but we register codepoints (int) // NOTE: event.text.text data comes an UTF-8 text sequence but we register codepoints (int)
@ -1038,7 +1039,7 @@ void PollInputEvents(void)
if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0]; if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0];
else gestureEvent.position[0] = GetMousePosition(); else gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[0] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[0].y /= (float)GetScreenHeight();
@ -1072,18 +1073,18 @@ int InitPlatform(void)
unsigned int flags = RGFW_CENTER | RGFW_ALLOW_DND; unsigned int flags = RGFW_CENTER | RGFW_ALLOW_DND;
// Check window creation flags // Check window creation flags
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0)
{ {
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
flags |= RGFW_FULLSCREEN; flags |= RGFW_FULLSCREEN;
} }
if ((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) > 0) flags |= RGFW_NO_BORDER; if ((CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED) > 0) flags |= RGFW_NO_BORDER;
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) == 0) flags |= RGFW_NO_RESIZE; if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) == 0) flags |= RGFW_NO_RESIZE;
if ((CORE.Window.flags & FLAG_WINDOW_TRANSPARENT) > 0) flags |= RGFW_TRANSPARENT_WINDOW; if ((CORE_WINDOW.flags & FLAG_WINDOW_TRANSPARENT) > 0) flags |= RGFW_TRANSPARENT_WINDOW;
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) flags |= RGFW_FULLSCREEN; if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0) flags |= RGFW_FULLSCREEN;
// NOTE: Some OpenGL context attributes must be set before window creation // NOTE: Some OpenGL context attributes must be set before window creation
@ -1101,14 +1102,14 @@ int InitPlatform(void)
RGFW_setGLVersion(4, 1); RGFW_setGLVersion(4, 1);
} }
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
RGFW_setGLSamples(4); RGFW_setGLSamples(4);
} }
platform.window = RGFW_createWindow(CORE.Window.title, RGFW_RECT(0, 0, CORE.Window.screen.width, CORE.Window.screen.height), flags); platform.window = RGFW_createWindow(CORE_WINDOW.title, RGFW_RECT(0, 0, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height), flags);
if (CORE.Window.flags & FLAG_VSYNC_HINT) if (CORE_WINDOW.flags & FLAG_VSYNC_HINT)
RGFW_window_swapInterval(platform.window, 1); RGFW_window_swapInterval(platform.window, 1);
RGFW_window_makeCurrent(platform.window); RGFW_window_makeCurrent(platform.window);
@ -1116,18 +1117,18 @@ int InitPlatform(void)
// Check surface and context activation // Check surface and context activation
if (platform.window != NULL) if (platform.window != NULL)
{ {
CORE.Window.ready = true; CORE_WINDOW.ready = true;
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
else else
{ {
@ -1137,18 +1138,18 @@ int InitPlatform(void)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// If everything work as expected, we can continue // If everything work as expected, we can continue
CORE.Window.position.x = platform.window->r.x; CORE_WINDOW.position.x = platform.window->r.x;
CORE.Window.position.y = platform.window->r.y; CORE_WINDOW.position.y = platform.window->r.y;
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
// TODO: Load OpenGL extensions // TODO: Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions // NOTE: GL procedures address loader is required to load extensions

View File

@ -73,6 +73,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { 0 }; // Platform specific data static PlatformData platform = { 0 }; // Platform specific data
@ -240,7 +241,7 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode); // Help conv
// Check if application should close // Check if application should close
bool WindowShouldClose(void) bool WindowShouldClose(void)
{ {
if (CORE.Window.ready) return CORE.Window.shouldClose; if (CORE_WINDOW.ready) return CORE_WINDOW.shouldClose;
else return true; else return true;
} }
@ -251,17 +252,17 @@ void ToggleFullscreen(void)
const int monitorCount = SDL_GetNumVideoDisplays(); const int monitorCount = SDL_GetNumVideoDisplays();
if ((monitor >= 0) && (monitor < monitorCount)) if ((monitor >= 0) && (monitor < monitorCount))
{ {
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0)
{ {
SDL_SetWindowFullscreen(platform.window, 0); SDL_SetWindowFullscreen(platform.window, 0);
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
} }
else else
{ {
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN); SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN);
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
} }
} }
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor"); else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
@ -274,15 +275,15 @@ void ToggleBorderlessWindowed(void)
const int monitorCount = SDL_GetNumVideoDisplays(); const int monitorCount = SDL_GetNumVideoDisplays();
if ((monitor >= 0) && (monitor < monitorCount)) if ((monitor >= 0) && (monitor < monitorCount))
{ {
if ((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0) if ((CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0)
{ {
SDL_SetWindowFullscreen(platform.window, 0); SDL_SetWindowFullscreen(platform.window, 0);
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
} }
else else
{ {
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
} }
} }
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor"); else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
@ -292,14 +293,14 @@ void ToggleBorderlessWindowed(void)
void MaximizeWindow(void) void MaximizeWindow(void)
{ {
SDL_MaximizeWindow(platform.window); SDL_MaximizeWindow(platform.window);
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; CORE_WINDOW.flags |= FLAG_WINDOW_MAXIMIZED;
} }
// Set window state: minimized // Set window state: minimized
void MinimizeWindow(void) void MinimizeWindow(void)
{ {
SDL_MinimizeWindow(platform.window); SDL_MinimizeWindow(platform.window);
CORE.Window.flags |= FLAG_WINDOW_MINIMIZED; CORE_WINDOW.flags |= FLAG_WINDOW_MINIMIZED;
} }
// Set window state: not minimized/maximized // Set window state: not minimized/maximized
@ -311,7 +312,7 @@ void RestoreWindow(void)
// Set window configuration state using flags // Set window configuration state using flags
void SetWindowState(unsigned int flags) void SetWindowState(unsigned int flags)
{ {
CORE.Window.flags |= flags; CORE_WINDOW.flags |= flags;
if (flags & FLAG_VSYNC_HINT) if (flags & FLAG_VSYNC_HINT)
{ {
@ -324,7 +325,7 @@ void SetWindowState(unsigned int flags)
if ((monitor >= 0) && (monitor < monitorCount)) if ((monitor >= 0) && (monitor < monitorCount))
{ {
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN); SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN);
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
} }
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor"); else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
} }
@ -400,7 +401,7 @@ void SetWindowState(unsigned int flags)
// Clear window configuration state flags // Clear window configuration state flags
void ClearWindowState(unsigned int flags) void ClearWindowState(unsigned int flags)
{ {
CORE.Window.flags &= ~flags; CORE_WINDOW.flags &= ~flags;
if (flags & FLAG_VSYNC_HINT) if (flags & FLAG_VSYNC_HINT)
{ {
@ -409,7 +410,7 @@ void ClearWindowState(unsigned int flags)
if (flags & FLAG_FULLSCREEN_MODE) if (flags & FLAG_FULLSCREEN_MODE)
{ {
SDL_SetWindowFullscreen(platform.window, 0); SDL_SetWindowFullscreen(platform.window, 0);
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
} }
if (flags & FLAG_WINDOW_RESIZABLE) if (flags & FLAG_WINDOW_RESIZABLE)
{ {
@ -577,7 +578,7 @@ void SetWindowTitle(const char *title)
{ {
SDL_SetWindowTitle(platform.window, title); SDL_SetWindowTitle(platform.window, title);
CORE.Window.title = title; CORE_WINDOW.title = title;
} }
// Set window position on screen (windowed mode) // Set window position on screen (windowed mode)
@ -585,8 +586,8 @@ void SetWindowPosition(int x, int y)
{ {
SDL_SetWindowPosition(platform.window, x, y); SDL_SetWindowPosition(platform.window, x, y);
CORE.Window.position.x = x; CORE_WINDOW.position.x = x;
CORE.Window.position.y = y; CORE_WINDOW.position.y = y;
} }
// Set monitor for the current window // Set monitor for the current window
@ -599,10 +600,10 @@ void SetWindowMonitor(int monitor)
// 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3, // 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3,
// see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba // see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba
// 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again. // 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again.
const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) ? true : false; const bool wasFullscreen = ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0) ? true : false;
const int screenWidth = CORE.Window.screen.width; const int screenWidth = CORE_WINDOW.screen.width;
const int screenHeight = CORE.Window.screen.height; const int screenHeight = CORE_WINDOW.screen.height;
SDL_Rect usableBounds; SDL_Rect usableBounds;
if (SDL_GetDisplayUsableBounds(monitor, &usableBounds) == 0) if (SDL_GetDisplayUsableBounds(monitor, &usableBounds) == 0)
{ {
@ -620,16 +621,16 @@ void SetWindowMonitor(int monitor)
// 3. It wasn't done here because we can't assume changing the window size automatically // 3. It wasn't done here because we can't assume changing the window size automatically
// is acceptable behavior by the user. // is acceptable behavior by the user.
SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y); SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y);
CORE.Window.position.x = usableBounds.x; CORE_WINDOW.position.x = usableBounds.x;
CORE.Window.position.y = usableBounds.y; CORE_WINDOW.position.y = usableBounds.y;
} }
else else
{ {
const int x = usableBounds.x + (usableBounds.w/2) - (screenWidth/2); const int x = usableBounds.x + (usableBounds.w/2) - (screenWidth/2);
const int y = usableBounds.y + (usableBounds.h/2) - (screenHeight/2); const int y = usableBounds.y + (usableBounds.h/2) - (screenHeight/2);
SDL_SetWindowPosition(platform.window, x, y); SDL_SetWindowPosition(platform.window, x, y);
CORE.Window.position.x = x; CORE_WINDOW.position.x = x;
CORE.Window.position.y = y; CORE_WINDOW.position.y = y;
} }
if (wasFullscreen == 1) ToggleFullscreen(); // Re-enter fullscreen if (wasFullscreen == 1) ToggleFullscreen(); // Re-enter fullscreen
@ -644,8 +645,8 @@ void SetWindowMinSize(int width, int height)
{ {
SDL_SetWindowMinimumSize(platform.window, width, height); SDL_SetWindowMinimumSize(platform.window, width, height);
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
} }
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
@ -653,8 +654,8 @@ void SetWindowMaxSize(int width, int height)
{ {
SDL_SetWindowMaximumSize(platform.window, width, height); SDL_SetWindowMaximumSize(platform.window, width, height);
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
} }
// Set window dimensions // Set window dimensions
@ -662,8 +663,8 @@ void SetWindowSize(int width, int height)
{ {
SDL_SetWindowSize(platform.window, width, height); SDL_SetWindowSize(platform.window, width, height);
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
} }
// Set window opacity, value opacity is between 0.0 and 1.0 // Set window opacity, value opacity is between 0.0 and 1.0
@ -979,8 +980,8 @@ static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
{ {
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i); SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
CORE.Input.Touch.pointId[i] = finger->id; CORE.Input.Touch.pointId[i] = finger->id;
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width; CORE.Input.Touch.position[i].x = finger->x*CORE_WINDOW.screen.width;
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height; CORE.Input.Touch.position[i].y = finger->y*CORE_WINDOW.screen.height;
CORE.Input.Touch.currentTouchState[i] = 1; CORE.Input.Touch.currentTouchState[i] = 1;
} }
@ -1054,7 +1055,7 @@ void PollInputEvents(void)
} }
*/ */
CORE.Window.resizedLastFrame = false; CORE_WINDOW.resizedLastFrame = false;
SDL_Event event = { 0 }; SDL_Event event = { 0 };
while (SDL_PollEvent(&event) != 0) while (SDL_PollEvent(&event) != 0)
@ -1062,30 +1063,30 @@ void PollInputEvents(void)
// All input events can be processed after polling // All input events can be processed after polling
switch (event.type) switch (event.type)
{ {
case SDL_QUIT: CORE.Window.shouldClose = true; break; case SDL_QUIT: CORE_WINDOW.shouldClose = true; break;
case SDL_DROPFILE: // Dropped file case SDL_DROPFILE: // Dropped file
{ {
if (CORE.Window.dropFileCount == 0) if (CORE_WINDOW.dropFileCount == 0)
{ {
// When a new file is dropped, we reserve a fixed number of slots for all possible dropped files // When a new file is dropped, we reserve a fixed number of slots for all possible dropped files
// at the moment we limit the number of drops at once to 1024 files but this behaviour should probably be reviewed // at the moment we limit the number of drops at once to 1024 files but this behaviour should probably be reviewed
// TODO: Pointers should probably be reallocated for any new file added... // TODO: Pointers should probably be reallocated for any new file added...
CORE.Window.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *)); CORE_WINDOW.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *));
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.file); strcpy(CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount], event.drop.file);
SDL_free(event.drop.file); SDL_free(event.drop.file);
CORE.Window.dropFileCount++; CORE_WINDOW.dropFileCount++;
} }
else if (CORE.Window.dropFileCount < 1024) else if (CORE_WINDOW.dropFileCount < 1024)
{ {
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.file); strcpy(CORE_WINDOW.dropFilepaths[CORE_WINDOW.dropFileCount], event.drop.file);
SDL_free(event.drop.file); SDL_free(event.drop.file);
CORE.Window.dropFileCount++; CORE_WINDOW.dropFileCount++;
} }
else TRACELOG(LOG_WARNING, "FILE: Maximum drag and drop files at once is limited to 1024 files!"); else TRACELOG(LOG_WARNING, "FILE: Maximum drag and drop files at once is limited to 1024 files!");
@ -1102,11 +1103,11 @@ void PollInputEvents(void)
const int width = event.window.data1; const int width = event.window.data1;
const int height = event.window.data2; const int height = event.window.data2;
SetupViewport(width, height); SetupViewport(width, height);
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
CORE.Window.currentFbo.width = width; CORE_WINDOW.currentFbo.width = width;
CORE.Window.currentFbo.height = height; CORE_WINDOW.currentFbo.height = height;
CORE.Window.resizedLastFrame = true; CORE_WINDOW.resizedLastFrame = true;
} break; } break;
case SDL_WINDOWEVENT_ENTER: case SDL_WINDOWEVENT_ENTER:
{ {
@ -1148,7 +1149,7 @@ void PollInputEvents(void)
// TODO: Put exitKey verification outside the switch? // TODO: Put exitKey verification outside the switch?
if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey]) if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey])
{ {
CORE.Window.shouldClose = true; CORE_WINDOW.shouldClose = true;
} }
} break; } break;
@ -1400,7 +1401,7 @@ void PollInputEvents(void)
if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0]; if (touchAction == 2 || realTouch) gestureEvent.position[0] = CORE.Input.Touch.position[0];
else gestureEvent.position[0] = GetMousePosition(); else gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[0] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[0].y /= (float)GetScreenHeight();
@ -1436,32 +1437,32 @@ int InitPlatform(void)
flags |= SDL_WINDOW_MOUSE_CAPTURE; // Window has mouse captured flags |= SDL_WINDOW_MOUSE_CAPTURE; // Window has mouse captured
// Check window creation flags // Check window creation flags
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0)
{ {
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
flags |= SDL_WINDOW_FULLSCREEN; flags |= SDL_WINDOW_FULLSCREEN;
} }
//if ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) == 0) flags |= SDL_WINDOW_HIDDEN; //if ((CORE_WINDOW.flags & FLAG_WINDOW_HIDDEN) == 0) flags |= SDL_WINDOW_HIDDEN;
if ((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) > 0) flags |= SDL_WINDOW_BORDERLESS; if ((CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED) > 0) flags |= SDL_WINDOW_BORDERLESS;
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) flags |= SDL_WINDOW_RESIZABLE; if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) > 0) flags |= SDL_WINDOW_RESIZABLE;
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) flags |= SDL_WINDOW_MINIMIZED; if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) flags |= SDL_WINDOW_MINIMIZED;
if ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) flags |= SDL_WINDOW_MAXIMIZED; if ((CORE_WINDOW.flags & FLAG_WINDOW_MAXIMIZED) > 0) flags |= SDL_WINDOW_MAXIMIZED;
if ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_UNFOCUSED) > 0)
{ {
flags &= ~SDL_WINDOW_INPUT_FOCUS; flags &= ~SDL_WINDOW_INPUT_FOCUS;
flags &= ~SDL_WINDOW_MOUSE_FOCUS; flags &= ~SDL_WINDOW_MOUSE_FOCUS;
} }
if ((CORE.Window.flags & FLAG_WINDOW_TOPMOST) > 0) flags |= SDL_WINDOW_ALWAYS_ON_TOP; if ((CORE_WINDOW.flags & FLAG_WINDOW_TOPMOST) > 0) flags |= SDL_WINDOW_ALWAYS_ON_TOP;
if ((CORE.Window.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0) flags &= ~SDL_WINDOW_MOUSE_CAPTURE; if ((CORE_WINDOW.flags & FLAG_WINDOW_MOUSE_PASSTHROUGH) > 0) flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) flags |= SDL_WINDOW_ALLOW_HIGHDPI; if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0) flags |= SDL_WINDOW_ALLOW_HIGHDPI;
//if ((CORE.Window.flags & FLAG_WINDOW_TRANSPARENT) > 0) flags |= SDL_WINDOW_TRANSPARENT; // Alternative: SDL_GL_ALPHA_SIZE = 8 //if ((CORE_WINDOW.flags & FLAG_WINDOW_TRANSPARENT) > 0) flags |= SDL_WINDOW_TRANSPARENT; // Alternative: SDL_GL_ALPHA_SIZE = 8
//if ((CORE.Window.flags & FLAG_FULLSCREEN_DESKTOP) > 0) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; //if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_DESKTOP) > 0) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
// NOTE: Some OpenGL context attributes must be set before window creation // NOTE: Some OpenGL context attributes must be set before window creation
@ -1499,19 +1500,19 @@ int InitPlatform(void)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
} }
if (CORE.Window.flags & FLAG_VSYNC_HINT) if (CORE_WINDOW.flags & FLAG_VSYNC_HINT)
{ {
SDL_GL_SetSwapInterval(1); SDL_GL_SetSwapInterval(1);
} }
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
} }
// Init window // Init window
platform.window = SDL_CreateWindow(CORE.Window.title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CORE.Window.screen.width, CORE.Window.screen.height, flags); platform.window = SDL_CreateWindow(CORE_WINDOW.title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, flags);
// Init OpenGL context // Init OpenGL context
platform.glContext = SDL_GL_CreateContext(platform.window); platform.glContext = SDL_GL_CreateContext(platform.window);
@ -1519,24 +1520,24 @@ int InitPlatform(void)
// Check window and glContext have been initialized successfully // Check window and glContext have been initialized successfully
if ((platform.window != NULL) && (platform.glContext != NULL)) if ((platform.window != NULL) && (platform.glContext != NULL))
{ {
CORE.Window.ready = true; CORE_WINDOW.ready = true;
SDL_DisplayMode displayMode = { 0 }; SDL_DisplayMode displayMode = { 0 };
SDL_GetCurrentDisplayMode(GetCurrentMonitor(), &displayMode); SDL_GetCurrentDisplayMode(GetCurrentMonitor(), &displayMode);
CORE.Window.display.width = displayMode.w; CORE_WINDOW.display.width = displayMode.w;
CORE.Window.display.height = displayMode.h; CORE_WINDOW.display.height = displayMode.h;
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
else else
{ {

View File

@ -133,6 +133,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { 0 }; // Platform specific data static PlatformData platform = { 0 }; // Platform specific data
@ -249,7 +250,7 @@ static int FindNearestConnectorMode(const drmModeConnector *connector, uint widt
// NOTE: By default, if KEY_ESCAPE pressed // NOTE: By default, if KEY_ESCAPE pressed
bool WindowShouldClose(void) bool WindowShouldClose(void)
{ {
if (CORE.Window.ready) return CORE.Window.shouldClose; if (CORE_WINDOW.ready) return CORE_WINDOW.shouldClose;
else return true; else return true;
} }
@ -310,7 +311,7 @@ void SetWindowIcons(Image *images, int count)
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
CORE.Window.title = title; CORE_WINDOW.title = title;
} }
// Set window position on screen (windowed mode) // Set window position on screen (windowed mode)
@ -328,15 +329,15 @@ void SetWindowMonitor(int monitor)
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMinSize(int width, int height) void SetWindowMinSize(int width, int height)
{ {
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
} }
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height) void SetWindowMaxSize(int width, int height)
{ {
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
} }
// Set window dimensions // Set window dimensions
@ -525,7 +526,7 @@ void HideCursor(void)
void EnableCursor(void) void EnableCursor(void)
{ {
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
platform.cursorRelative = false; platform.cursorRelative = false;
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorHidden = false;
@ -661,7 +662,7 @@ void PollInputEvents(void)
#endif #endif
// Check exit key // Check exit key
if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE_WINDOW.shouldClose = true;
// Register previous mouse position // Register previous mouse position
if (platform.cursorRelative) CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f }; if (platform.cursorRelative) CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f };
@ -713,8 +714,8 @@ int InitPlatform(void)
// Initialize graphic device: display/window and graphic context // Initialize graphic device: display/window and graphic context
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
#if defined(DEFAULT_GRAPHIC_DEVICE_DRM) #if defined(DEFAULT_GRAPHIC_DEVICE_DRM)
platform.fd = open(DEFAULT_GRAPHIC_DEVICE_DRM, O_RDWR); platform.fd = open(DEFAULT_GRAPHIC_DEVICE_DRM, O_RDWR);
@ -795,7 +796,7 @@ int InitPlatform(void)
} }
// If InitWindow should use the current mode find it in the connector's mode list // If InitWindow should use the current mode find it in the connector's mode list
if ((CORE.Window.screen.width <= 0) || (CORE.Window.screen.height <= 0)) if ((CORE_WINDOW.screen.width <= 0) || (CORE_WINDOW.screen.height <= 0))
{ {
TRACELOG(LOG_TRACE, "DISPLAY: Selecting DRM connector mode for current used mode..."); TRACELOG(LOG_TRACE, "DISPLAY: Selecting DRM connector mode for current used mode...");
@ -809,24 +810,24 @@ int InitPlatform(void)
return -1; return -1;
} }
CORE.Window.screen.width = CORE.Window.display.width; CORE_WINDOW.screen.width = CORE_WINDOW.display.width;
CORE.Window.screen.height = CORE.Window.display.height; CORE_WINDOW.screen.height = CORE_WINDOW.display.height;
} }
const bool allowInterlaced = CORE.Window.flags & FLAG_INTERLACED_HINT; const bool allowInterlaced = CORE_WINDOW.flags & FLAG_INTERLACED_HINT;
const int fps = (CORE.Time.target > 0)? (1.0/CORE.Time.target) : 60; const int fps = (CORE.Time.target > 0)? (1.0/CORE.Time.target) : 60;
// Try to find an exact matching mode // Try to find an exact matching mode
platform.modeIndex = FindExactConnectorMode(platform.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, allowInterlaced); platform.modeIndex = FindExactConnectorMode(platform.connector, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, fps, allowInterlaced);
// If nothing found, try to find a nearly matching mode // If nothing found, try to find a nearly matching mode
if (platform.modeIndex < 0) platform.modeIndex = FindNearestConnectorMode(platform.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, allowInterlaced); if (platform.modeIndex < 0) platform.modeIndex = FindNearestConnectorMode(platform.connector, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, fps, allowInterlaced);
// If nothing found, try to find an exactly matching mode including interlaced // If nothing found, try to find an exactly matching mode including interlaced
if (platform.modeIndex < 0) platform.modeIndex = FindExactConnectorMode(platform.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, true); if (platform.modeIndex < 0) platform.modeIndex = FindExactConnectorMode(platform.connector, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, fps, true);
// If nothing found, try to find a nearly matching mode including interlaced // If nothing found, try to find a nearly matching mode including interlaced
if (platform.modeIndex < 0) platform.modeIndex = FindNearestConnectorMode(platform.connector, CORE.Window.screen.width, CORE.Window.screen.height, fps, true); if (platform.modeIndex < 0) platform.modeIndex = FindNearestConnectorMode(platform.connector, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, fps, true);
// If nothing found, there is no suitable mode // If nothing found, there is no suitable mode
if (platform.modeIndex < 0) if (platform.modeIndex < 0)
@ -837,8 +838,8 @@ int InitPlatform(void)
return -1; return -1;
} }
CORE.Window.display.width = platform.connector->modes[platform.modeIndex].hdisplay; CORE_WINDOW.display.width = platform.connector->modes[platform.modeIndex].hdisplay;
CORE.Window.display.height = platform.connector->modes[platform.modeIndex].vdisplay; CORE_WINDOW.display.height = platform.connector->modes[platform.modeIndex].vdisplay;
TRACELOG(LOG_INFO, "DISPLAY: Selected DRM connector mode %s (%ux%u%c@%u)", platform.connector->modes[platform.modeIndex].name, TRACELOG(LOG_INFO, "DISPLAY: Selected DRM connector mode %s (%ux%u%c@%u)", platform.connector->modes[platform.modeIndex].name,
platform.connector->modes[platform.modeIndex].hdisplay, platform.connector->modes[platform.modeIndex].vdisplay, platform.connector->modes[platform.modeIndex].hdisplay, platform.connector->modes[platform.modeIndex].vdisplay,
@ -846,8 +847,8 @@ int InitPlatform(void)
platform.connector->modes[platform.modeIndex].vrefresh); platform.connector->modes[platform.modeIndex].vrefresh);
// Use the width and height of the surface for render // Use the width and height of the surface for render
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
drmModeFreeEncoder(enc); drmModeFreeEncoder(enc);
enc = NULL; enc = NULL;
@ -872,7 +873,7 @@ int InitPlatform(void)
EGLint samples = 0; EGLint samples = 0;
EGLint sampleBuffer = 0; EGLint sampleBuffer = 0;
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
samples = 4; samples = 4;
sampleBuffer = 1; sampleBuffer = 1;
@ -992,10 +993,10 @@ int InitPlatform(void)
// At this point we need to manage render size vs screen size // At this point we need to manage render size vs screen size
// NOTE: This function use and modify global module variables: // NOTE: This function use and modify global module variables:
// -> CORE.Window.screen.width/CORE.Window.screen.height // -> CORE_WINDOW.screen.width/CORE_WINDOW.screen.height
// -> CORE.Window.render.width/CORE.Window.render.height // -> CORE_WINDOW.render.width/CORE_WINDOW.render.height
// -> CORE.Window.screenScale // -> CORE_WINDOW.screenScale
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); SetupFramebuffer(CORE_WINDOW.display.width, CORE_WINDOW.display.height);
// There must be at least one frame displayed before the buffers are swapped // There must be at least one frame displayed before the buffers are swapped
//eglSwapInterval(platform.device, 1); //eglSwapInterval(platform.device, 1);
@ -1005,18 +1006,18 @@ int InitPlatform(void)
// Check surface and context activation // Check surface and context activation
if (result != EGL_FALSE) if (result != EGL_FALSE)
{ {
CORE.Window.ready = true; CORE_WINDOW.ready = true;
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
else else
{ {
@ -1024,17 +1025,17 @@ int InitPlatform(void)
return -1; return -1;
} }
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow(); if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
// If graphic device is no properly initialized, we end program // If graphic device is no properly initialized, we end program
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; } if (!CORE_WINDOW.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2); else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE_WINDOW.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE_WINDOW.screen.height / 2);
// Set some default window flags // Set some default window flags
CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false CORE_WINDOW.flags &= ~FLAG_WINDOW_HIDDEN; // false
CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // false CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED; // false
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // true CORE_WINDOW.flags |= FLAG_WINDOW_MAXIMIZED; // true
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // false CORE_WINDOW.flags &= ~FLAG_WINDOW_UNFOCUSED; // false
// Load OpenGL extensions // Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions // NOTE: GL procedures address loader is required to load extensions
@ -1132,7 +1133,7 @@ void ClosePlatform(void)
platform.device = EGL_NO_DISPLAY; platform.device = EGL_NO_DISPLAY;
} }
CORE.Window.shouldClose = true; // Added to force threads to exit when the close window is called CORE_WINDOW.shouldClose = true; // Added to force threads to exit when the close window is called
// Close the evdev devices // Close the evdev devices
@ -1723,16 +1724,16 @@ static void PollMouseEvents(void)
// Basic movement // Basic movement
if (event.code == ABS_X) if (event.code == ABS_X)
{ {
CORE.Input.Mouse.currentPosition.x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange CORE.Input.Mouse.currentPosition.x = (event.value - platform.absRange.x)*CORE_WINDOW.screen.width/platform.absRange.width; // Scale according to absRange
CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange CORE.Input.Touch.position[0].x = (event.value - platform.absRange.x)*CORE_WINDOW.screen.width/platform.absRange.width; // Scale according to absRange
touchAction = 2; // TOUCH_ACTION_MOVE touchAction = 2; // TOUCH_ACTION_MOVE
} }
if (event.code == ABS_Y) if (event.code == ABS_Y)
{ {
CORE.Input.Mouse.currentPosition.y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange CORE.Input.Mouse.currentPosition.y = (event.value - platform.absRange.y)*CORE_WINDOW.screen.height/platform.absRange.height; // Scale according to absRange
CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange CORE.Input.Touch.position[0].y = (event.value - platform.absRange.y)*CORE_WINDOW.screen.height/platform.absRange.height; // Scale according to absRange
touchAction = 2; // TOUCH_ACTION_MOVE touchAction = 2; // TOUCH_ACTION_MOVE
} }
@ -1742,12 +1743,12 @@ static void PollMouseEvents(void)
if (event.code == ABS_MT_POSITION_X) if (event.code == ABS_MT_POSITION_X)
{ {
if (platform.touchSlot < MAX_TOUCH_POINTS) CORE.Input.Touch.position[platform.touchSlot].x = (event.value - platform.absRange.x)*CORE.Window.screen.width/platform.absRange.width; // Scale according to absRange if (platform.touchSlot < MAX_TOUCH_POINTS) CORE.Input.Touch.position[platform.touchSlot].x = (event.value - platform.absRange.x)*CORE_WINDOW.screen.width/platform.absRange.width; // Scale according to absRange
} }
if (event.code == ABS_MT_POSITION_Y) if (event.code == ABS_MT_POSITION_Y)
{ {
if (platform.touchSlot < MAX_TOUCH_POINTS) CORE.Input.Touch.position[platform.touchSlot].y = (event.value - platform.absRange.y)*CORE.Window.screen.height/platform.absRange.height; // Scale according to absRange if (platform.touchSlot < MAX_TOUCH_POINTS) CORE.Input.Touch.position[platform.touchSlot].y = (event.value - platform.absRange.y)*CORE_WINDOW.screen.height/platform.absRange.height; // Scale according to absRange
} }
if (event.code == ABS_MT_TRACKING_ID) if (event.code == ABS_MT_TRACKING_ID)
@ -1804,10 +1805,10 @@ static void PollMouseEvents(void)
if (!CORE.Input.Mouse.cursorHidden) if (!CORE.Input.Mouse.cursorHidden)
{ {
if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0; if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0;
if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x; if (CORE.Input.Mouse.currentPosition.x > CORE_WINDOW.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE_WINDOW.screen.width/CORE.Input.Mouse.scale.x;
if (CORE.Input.Mouse.currentPosition.y < 0) CORE.Input.Mouse.currentPosition.y = 0; if (CORE.Input.Mouse.currentPosition.y < 0) CORE.Input.Mouse.currentPosition.y = 0;
if (CORE.Input.Mouse.currentPosition.y > CORE.Window.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE.Window.screen.height/CORE.Input.Mouse.scale.y; if (CORE.Input.Mouse.currentPosition.y > CORE_WINDOW.screen.height/CORE.Input.Mouse.scale.y) CORE.Input.Mouse.currentPosition.y = CORE_WINDOW.screen.height/CORE.Input.Mouse.scale.y;
} }
// Update touch point count // Update touch point count

View File

@ -65,6 +65,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { 0 }; // Platform specific data static PlatformData platform = { 0 }; // Platform specific data
@ -86,7 +87,7 @@ bool InitGraphicsDevice(void); // Initialize graphics device
// Check if application should close // Check if application should close
bool WindowShouldClose(void) bool WindowShouldClose(void)
{ {
if (CORE.Window.ready) return CORE.Window.shouldClose; if (CORE_WINDOW.ready) return CORE_WINDOW.shouldClose;
else return true; else return true;
} }
@ -147,7 +148,7 @@ void SetWindowIcons(Image *images, int count)
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
CORE.Window.title = title; CORE_WINDOW.title = title;
} }
// Set window position on screen (windowed mode) // Set window position on screen (windowed mode)
@ -165,15 +166,15 @@ void SetWindowMonitor(int monitor)
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMinSize(int width, int height) void SetWindowMinSize(int width, int height)
{ {
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
} }
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height) void SetWindowMaxSize(int width, int height)
{ {
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
} }
// Set window dimensions // Set window dimensions
@ -308,7 +309,7 @@ void HideCursor(void)
void EnableCursor(void) void EnableCursor(void)
{ {
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorHidden = false;
} }
@ -317,7 +318,7 @@ void EnableCursor(void)
void DisableCursor(void) void DisableCursor(void)
{ {
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorHidden = true;
} }
@ -437,12 +438,12 @@ int InitPlatform(void)
// raylib uses OpenGL so, platform should create that kind of connection // raylib uses OpenGL so, platform should create that kind of connection
// Below example illustrates that process using EGL library // Below example illustrates that process using EGL library
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
EGLint samples = 0; EGLint samples = 0;
EGLint sampleBuffer = 0; EGLint sampleBuffer = 0;
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
samples = 4; samples = 4;
sampleBuffer = 1; sampleBuffer = 1;
@ -521,18 +522,18 @@ int InitPlatform(void)
// Check surface and context activation // Check surface and context activation
if (result != EGL_FALSE) if (result != EGL_FALSE)
{ {
CORE.Window.ready = true; CORE_WINDOW.ready = true;
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
else else
{ {
@ -542,16 +543,16 @@ int InitPlatform(void)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// If everything work as expected, we can continue // If everything work as expected, we can continue
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
// TODO: Load OpenGL extensions // TODO: Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions // NOTE: GL procedures address loader is required to load extensions

View File

@ -80,6 +80,7 @@ typedef struct {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
extern CoreData CORE; // Global CORE state context extern CoreData CORE; // Global CORE state context
#define CORE_WINDOW CORE.Window
static PlatformData platform = { 0 }; // Platform specific data static PlatformData platform = { 0 }; // Platform specific data
@ -166,8 +167,8 @@ void ToggleFullscreen(void)
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0); const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
if (wasFullscreen) if (wasFullscreen)
{ {
if (CORE.Window.flags & FLAG_FULLSCREEN_MODE) enterFullscreen = false; if (CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) enterFullscreen = false;
else if (CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) enterFullscreen = true; else if (CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) enterFullscreen = true;
else else
{ {
const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0); const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0);
@ -178,9 +179,9 @@ void ToggleFullscreen(void)
EM_ASM(document.exitFullscreen();); EM_ASM(document.exitFullscreen(););
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
} }
else enterFullscreen = true; else enterFullscreen = true;
@ -193,8 +194,8 @@ void ToggleFullscreen(void)
Module.requestFullscreen(false, false); Module.requestFullscreen(false, false);
}, 100); }, 100);
); );
CORE.Window.fullscreen = true; CORE_WINDOW.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
} }
// NOTE: Old notes below: // NOTE: Old notes below:
@ -211,7 +212,7 @@ void ToggleFullscreen(void)
*/ */
// EM_ASM(Module.requestFullscreen(false, false);); // EM_ASM(Module.requestFullscreen(false, false););
/* /*
if (!CORE.Window.fullscreen) if (!CORE_WINDOW.fullscreen)
{ {
// Option 1: Request fullscreen for the canvas element // Option 1: Request fullscreen for the canvas element
// This option does not seem to work at all: // This option does not seem to work at all:
@ -246,8 +247,8 @@ void ToggleFullscreen(void)
emscripten_get_canvas_element_size("#canvas", &width, &height); emscripten_get_canvas_element_size("#canvas", &width, &height);
TRACELOG(LOG_WARNING, "Emscripten: Enter fullscreen: Canvas size: %i x %i", width, height); TRACELOG(LOG_WARNING, "Emscripten: Enter fullscreen: Canvas size: %i x %i", width, height);
CORE.Window.fullscreen = true; // Toggle fullscreen flag CORE_WINDOW.fullscreen = true; // Toggle fullscreen flag
CORE.Window.flags |= FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags |= FLAG_FULLSCREEN_MODE;
} }
else else
{ {
@ -258,8 +259,8 @@ void ToggleFullscreen(void)
emscripten_get_canvas_element_size("#canvas", &width, &height); emscripten_get_canvas_element_size("#canvas", &width, &height);
TRACELOG(LOG_WARNING, "Emscripten: Exit fullscreen: Canvas size: %i x %i", width, height); TRACELOG(LOG_WARNING, "Emscripten: Exit fullscreen: Canvas size: %i x %i", width, height);
CORE.Window.fullscreen = false; // Toggle fullscreen flag CORE_WINDOW.fullscreen = false; // Toggle fullscreen flag
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
} }
*/ */
} }
@ -273,8 +274,8 @@ void ToggleBorderlessWindowed(void)
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0); const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
if (wasFullscreen) if (wasFullscreen)
{ {
if (CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) enterBorderless = false; if (CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) enterBorderless = false;
else if (CORE.Window.flags & FLAG_FULLSCREEN_MODE) enterBorderless = true; else if (CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) enterBorderless = true;
else else
{ {
const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0); const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0);
@ -285,9 +286,9 @@ void ToggleBorderlessWindowed(void)
EM_ASM(document.exitFullscreen();); EM_ASM(document.exitFullscreen(););
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
} }
else enterBorderless = true; else enterBorderless = true;
@ -305,7 +306,7 @@ void ToggleBorderlessWindowed(void)
}, 100); }, 100);
}, 100); }, 100);
); );
CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
} }
} }
@ -348,7 +349,7 @@ void SetWindowState(unsigned int flags)
{ {
const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0); const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0);
const int canvasStyleWidth = EM_ASM_INT( { return parseInt(document.getElementById('canvas').style.width); }, 0); const int canvasStyleWidth = EM_ASM_INT( { return parseInt(document.getElementById('canvas').style.width); }, 0);
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) || canvasStyleWidth > canvasWidth) ToggleBorderlessWindowed(); if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) || canvasStyleWidth > canvasWidth) ToggleBorderlessWindowed();
} }
else ToggleBorderlessWindowed(); else ToggleBorderlessWindowed();
} }
@ -362,16 +363,16 @@ void SetWindowState(unsigned int flags)
{ {
const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0); const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0);
const int screenWidth = EM_ASM_INT( { return screen.width; }, 0); const int screenWidth = EM_ASM_INT( { return screen.width; }, 0);
if ((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) || screenWidth == canvasWidth ) ToggleFullscreen(); if ((CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) || screenWidth == canvasWidth ) ToggleFullscreen();
} }
else ToggleFullscreen(); else ToggleFullscreen();
} }
// State change: FLAG_WINDOW_RESIZABLE // State change: FLAG_WINDOW_RESIZABLE
if (((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != (flags & FLAG_WINDOW_RESIZABLE)) && ((flags & FLAG_WINDOW_RESIZABLE) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) != (flags & FLAG_WINDOW_RESIZABLE)) && ((flags & FLAG_WINDOW_RESIZABLE) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE); glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE);
CORE.Window.flags |= FLAG_WINDOW_RESIZABLE; CORE_WINDOW.flags |= FLAG_WINDOW_RESIZABLE;
} }
// State change: FLAG_WINDOW_UNDECORATED // State change: FLAG_WINDOW_UNDECORATED
@ -470,10 +471,10 @@ void ClearWindowState(unsigned int flags)
{ {
const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0); const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0);
const int screenWidth = EM_ASM_INT( { return screen.width; }, 0); const int screenWidth = EM_ASM_INT( { return screen.width; }, 0);
if ((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) || (screenWidth == canvasWidth)) EM_ASM(document.exitFullscreen();); if ((CORE_WINDOW.flags & FLAG_BORDERLESS_WINDOWED_MODE) || (screenWidth == canvasWidth)) EM_ASM(document.exitFullscreen(););
} }
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
} }
// State change: FLAG_FULLSCREEN_MODE // State change: FLAG_FULLSCREEN_MODE
@ -484,18 +485,18 @@ void ClearWindowState(unsigned int flags)
{ {
const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0); const int canvasWidth = EM_ASM_INT( { return document.getElementById('canvas').width; }, 0);
const int canvasStyleWidth = EM_ASM_INT( { return parseInt(document.getElementById('canvas').style.width); }, 0); const int canvasStyleWidth = EM_ASM_INT( { return parseInt(document.getElementById('canvas').style.width); }, 0);
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) || (canvasStyleWidth > canvasWidth)) EM_ASM(document.exitFullscreen();); if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) || (canvasStyleWidth > canvasWidth)) EM_ASM(document.exitFullscreen(););
} }
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
} }
// State change: FLAG_WINDOW_RESIZABLE // State change: FLAG_WINDOW_RESIZABLE
if (((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) && ((flags & FLAG_WINDOW_RESIZABLE) > 0)) if (((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) > 0) && ((flags & FLAG_WINDOW_RESIZABLE) > 0))
{ {
glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE); glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE);
CORE.Window.flags &= ~FLAG_WINDOW_RESIZABLE; CORE_WINDOW.flags &= ~FLAG_WINDOW_RESIZABLE;
} }
// State change: FLAG_WINDOW_HIDDEN // State change: FLAG_WINDOW_HIDDEN
@ -589,7 +590,7 @@ void SetWindowIcons(Image *images, int count)
// Set title for window // Set title for window
void SetWindowTitle(const char *title) void SetWindowTitle(const char *title)
{ {
CORE.Window.title = title; CORE_WINDOW.title = title;
emscripten_set_window_title(title); emscripten_set_window_title(title);
} }
@ -608,21 +609,21 @@ void SetWindowMonitor(int monitor)
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMinSize(int width, int height) void SetWindowMinSize(int width, int height)
{ {
CORE.Window.screenMin.width = width; CORE_WINDOW.screenMin.width = width;
CORE.Window.screenMin.height = height; CORE_WINDOW.screenMin.height = height;
// Trigger the resize event once to update the window minimum width and height // Trigger the resize event once to update the window minimum width and height
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
} }
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height) void SetWindowMaxSize(int width, int height)
{ {
CORE.Window.screenMax.width = width; CORE_WINDOW.screenMax.width = width;
CORE.Window.screenMax.height = height; CORE_WINDOW.screenMax.height = height;
// Trigger the resize event once to update the window maximum width and height // Trigger the resize event once to update the window maximum width and height
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
} }
// Set window dimensions // Set window dimensions
@ -792,7 +793,7 @@ void EnableCursor(void)
emscripten_exit_pointerlock(); emscripten_exit_pointerlock();
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
// NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback() // NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback()
} }
@ -804,7 +805,7 @@ void DisableCursor(void)
emscripten_request_pointerlock("#canvas", 1); emscripten_request_pointerlock("#canvas", 1);
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE_WINDOW.screen.width/2, CORE_WINDOW.screen.height/2);
// NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback() // NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback()
} }
@ -990,10 +991,10 @@ void PollInputEvents(void)
} }
} }
CORE.Window.resizedLastFrame = false; CORE_WINDOW.resizedLastFrame = false;
// TODO: This code does not seem to do anything?? // TODO: This code does not seem to do anything??
//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) --> WARNING: Where is key input reset? //else glfwPollEvents(); // Poll input events: keyboard/mouse/window events (callbacks) --> WARNING: Where is key input reset?
} }
@ -1023,27 +1024,27 @@ int InitPlatform(void)
// glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers // glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
// Check window creation flags // Check window creation flags
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) CORE.Window.fullscreen = true; if ((CORE_WINDOW.flags & FLAG_FULLSCREEN_MODE) > 0) CORE_WINDOW.fullscreen = true;
if ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window if ((CORE_WINDOW.flags & FLAG_WINDOW_HIDDEN) > 0) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window
else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden
if ((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) > 0) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window if ((CORE_WINDOW.flags & FLAG_WINDOW_UNDECORATED) > 0) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window
else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) > 0) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window
else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable
// Disable FLAG_WINDOW_MINIMIZED, not supported on initialization // Disable FLAG_WINDOW_MINIMIZED, not supported on initialization
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED;
// Disable FLAG_WINDOW_MAXIMIZED, not supported on initialization // Disable FLAG_WINDOW_MAXIMIZED, not supported on initialization
if ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; if ((CORE_WINDOW.flags & FLAG_WINDOW_MAXIMIZED) > 0) CORE_WINDOW.flags &= ~FLAG_WINDOW_MAXIMIZED;
if ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) > 0) glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE); if ((CORE_WINDOW.flags & FLAG_WINDOW_UNFOCUSED) > 0) glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
else glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE); else glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE);
if ((CORE.Window.flags & FLAG_WINDOW_TOPMOST) > 0) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE); if ((CORE_WINDOW.flags & FLAG_WINDOW_TOPMOST) > 0) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE); else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
// NOTE: Some GLFW flags are not supported on HTML5 // NOTE: Some GLFW flags are not supported on HTML5
@ -1051,10 +1052,10 @@ int InitPlatform(void)
// Scale content area based on the monitor content scale where window is placed on // Scale content area based on the monitor content scale where window is placed on
// NOTE: This feature requires emscripten 3.1.51 // NOTE: This feature requires emscripten 3.1.51
//if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); //if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0) glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
//else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE); //else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE);
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
// NOTE: MSAA is only enabled for main framebuffer, not user-created FBOs // NOTE: MSAA is only enabled for main framebuffer, not user-created FBOs
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4"); TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4");
@ -1107,50 +1108,50 @@ int InitPlatform(void)
} }
// NOTE: Getting video modes is not implemented in emscripten GLFW3 version // NOTE: Getting video modes is not implemented in emscripten GLFW3 version
CORE.Window.display.width = CORE.Window.screen.width; CORE_WINDOW.display.width = CORE_WINDOW.screen.width;
CORE.Window.display.height = CORE.Window.screen.height; CORE_WINDOW.display.height = CORE_WINDOW.screen.height;
// Init fullscreen toggle required var: // Init fullscreen toggle required var:
platform.ourFullscreen = false; platform.ourFullscreen = false;
if (CORE.Window.fullscreen) if (CORE_WINDOW.fullscreen)
{ {
// remember center for switchinging from fullscreen to window // remember center for switchinging from fullscreen to window
if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width)) if ((CORE_WINDOW.screen.height == CORE_WINDOW.display.height) && (CORE_WINDOW.screen.width == CORE_WINDOW.display.width))
{ {
// If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed. // If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed.
// Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11. // Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11.
CORE.Window.position.x = CORE.Window.display.width/4; CORE_WINDOW.position.x = CORE_WINDOW.display.width/4;
CORE.Window.position.y = CORE.Window.display.height/4; CORE_WINDOW.position.y = CORE_WINDOW.display.height/4;
} }
else else
{ {
CORE.Window.position.x = CORE.Window.display.width/2 - CORE.Window.screen.width/2; CORE_WINDOW.position.x = CORE_WINDOW.display.width/2 - CORE_WINDOW.screen.width/2;
CORE.Window.position.y = CORE.Window.display.height/2 - CORE.Window.screen.height/2; CORE_WINDOW.position.y = CORE_WINDOW.display.height/2 - CORE_WINDOW.screen.height/2;
} }
if (CORE.Window.position.x < 0) CORE.Window.position.x = 0; if (CORE_WINDOW.position.x < 0) CORE_WINDOW.position.x = 0;
if (CORE.Window.position.y < 0) CORE.Window.position.y = 0; if (CORE_WINDOW.position.y < 0) CORE_WINDOW.position.y = 0;
// Obtain recommended CORE.Window.display.width/CORE.Window.display.height from a valid videomode for the monitor // Obtain recommended CORE_WINDOW.display.width/CORE_WINDOW.display.height from a valid videomode for the monitor
int count = 0; int count = 0;
const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count); const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count);
// Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height // Get closest video mode to desired CORE_WINDOW.screen.width/CORE_WINDOW.screen.height
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
if ((unsigned int)modes[i].width >= CORE.Window.screen.width) if ((unsigned int)modes[i].width >= CORE_WINDOW.screen.width)
{ {
if ((unsigned int)modes[i].height >= CORE.Window.screen.height) if ((unsigned int)modes[i].height >= CORE_WINDOW.screen.height)
{ {
CORE.Window.display.width = modes[i].width; CORE_WINDOW.display.width = modes[i].width;
CORE.Window.display.height = modes[i].height; CORE_WINDOW.display.height = modes[i].height;
break; break;
} }
} }
} }
TRACELOG(LOG_WARNING, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_WARNING, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
// NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example, // NOTE: ISSUE: Closest videomode could not match monitor aspect-ratio, for example,
// for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3), // for a desired screen size of 800x450 (16:9), closest supported videomode is 800x600 (4:3),
@ -1159,25 +1160,25 @@ int InitPlatform(void)
// Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight // Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight
// It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset) // It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset)
// Modified global variables: CORE.Window.screen.width/CORE.Window.screen.height - CORE.Window.render.width/CORE.Window.render.height - CORE.Window.renderOffset.x/CORE.Window.renderOffset.y - CORE.Window.screenScale // Modified global variables: CORE_WINDOW.screen.width/CORE_WINDOW.screen.height - CORE_WINDOW.render.width/CORE_WINDOW.render.height - CORE_WINDOW.renderOffset.x/CORE_WINDOW.renderOffset.y - CORE_WINDOW.screenScale
// TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed... // TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed...
// HighDPI monitors are properly considered in a following similar function: SetupViewport() // HighDPI monitors are properly considered in a following similar function: SetupViewport()
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); SetupFramebuffer(CORE_WINDOW.display.width, CORE_WINDOW.display.height);
platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", glfwGetPrimaryMonitor(), NULL); platform.handle = glfwCreateWindow(CORE_WINDOW.display.width, CORE_WINDOW.display.height, (CORE_WINDOW.title != 0)? CORE_WINDOW.title : " ", glfwGetPrimaryMonitor(), NULL);
// NOTE: Full-screen change, not working properly... // NOTE: Full-screen change, not working properly...
// glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); // glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, GLFW_DONT_CARE);
} }
else else
{ {
// No-fullscreen window creation // No-fullscreen window creation
platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL); platform.handle = glfwCreateWindow(CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, (CORE_WINDOW.title != 0)? CORE_WINDOW.title : " ", NULL, NULL);
if (platform.handle) if (platform.handle)
{ {
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
} }
} }
@ -1189,7 +1190,7 @@ int InitPlatform(void)
} }
// WARNING: glfwCreateWindow() title doesn't work with emscripten // WARNING: glfwCreateWindow() title doesn't work with emscripten
emscripten_set_window_title((CORE.Window.title != 0)? CORE.Window.title : " "); emscripten_set_window_title((CORE_WINDOW.title != 0)? CORE_WINDOW.title : " ");
// Set window callback events // Set window callback events
glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback); // NOTE: Resizing not allowed by default! glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback); // NOTE: Resizing not allowed by default!
@ -1197,7 +1198,7 @@ int InitPlatform(void)
glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback); glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback);
glfwSetDropCallback(platform.handle, WindowDropCallback); glfwSetDropCallback(platform.handle, WindowDropCallback);
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback); glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback);
} }
@ -1216,21 +1217,21 @@ int InitPlatform(void)
// Check context activation // Check context activation
if (result == true) //(result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR)) if (result == true) //(result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
{ {
CORE.Window.ready = true; CORE_WINDOW.ready = true;
int fbWidth = CORE.Window.screen.width; int fbWidth = CORE_WINDOW.screen.width;
int fbHeight = CORE.Window.screen.height; int fbHeight = CORE_WINDOW.screen.height;
CORE.Window.render.width = fbWidth; CORE_WINDOW.render.width = fbWidth;
CORE.Window.render.height = fbHeight; CORE_WINDOW.render.height = fbHeight;
CORE.Window.currentFbo.width = fbWidth; CORE_WINDOW.currentFbo.width = fbWidth;
CORE.Window.currentFbo.height = fbHeight; CORE_WINDOW.currentFbo.height = fbHeight;
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE_WINDOW.display.width, CORE_WINDOW.display.height);
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height);
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE_WINDOW.renderOffset.x, CORE_WINDOW.renderOffset.y);
} }
else else
{ {
@ -1238,10 +1239,10 @@ int InitPlatform(void)
return -1; return -1;
} }
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow(); if ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
// If graphic device is no properly initialized, we end program // If graphic device is no properly initialized, we end program
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; } if (!CORE_WINDOW.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
// Load OpenGL extensions // Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions // NOTE: GL procedures address loader is required to load extensions
@ -1316,24 +1317,24 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
// Reset viewport and projection matrix for new size // Reset viewport and projection matrix for new size
SetupViewport(width, height); SetupViewport(width, height);
CORE.Window.currentFbo.width = width; CORE_WINDOW.currentFbo.width = width;
CORE.Window.currentFbo.height = height; CORE_WINDOW.currentFbo.height = height;
CORE.Window.resizedLastFrame = true; CORE_WINDOW.resizedLastFrame = true;
if (IsWindowFullscreen()) return; if (IsWindowFullscreen()) return;
// Set current screen size // Set current screen size
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
Vector2 windowScaleDPI = GetWindowScaleDPI(); Vector2 windowScaleDPI = GetWindowScaleDPI();
CORE.Window.screen.width = (unsigned int)(width/windowScaleDPI.x); CORE_WINDOW.screen.width = (unsigned int)(width/windowScaleDPI.x);
CORE.Window.screen.height = (unsigned int)(height/windowScaleDPI.y); CORE_WINDOW.screen.height = (unsigned int)(height/windowScaleDPI.y);
} }
else else
{ {
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
} }
// NOTE: Postprocessing texture is not scaled to new size // NOTE: Postprocessing texture is not scaled to new size
@ -1341,14 +1342,14 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley) static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley)
{ {
CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f); CORE_WINDOW.screenScale = MatrixScale(scalex, scaley, 1.0f);
} }
// GLFW3 WindowIconify Callback, runs when window is minimized/restored // GLFW3 WindowIconify Callback, runs when window is minimized/restored
static void WindowIconifyCallback(GLFWwindow *window, int iconified) static void WindowIconifyCallback(GLFWwindow *window, int iconified)
{ {
if (iconified) CORE.Window.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified if (iconified) CORE_WINDOW.flags |= FLAG_WINDOW_MINIMIZED; // The window was iconified
else CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored else CORE_WINDOW.flags &= ~FLAG_WINDOW_MINIMIZED; // The window was restored
} }
/* /*
@ -1362,8 +1363,8 @@ static void WindowMaximizeCallback(GLFWwindow *window, int maximized)
// GLFW3 WindowFocus Callback, runs when window get/lose focus // GLFW3 WindowFocus Callback, runs when window get/lose focus
static void WindowFocusCallback(GLFWwindow *window, int focused) static void WindowFocusCallback(GLFWwindow *window, int focused)
{ {
if (focused) CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // The window was focused if (focused) CORE_WINDOW.flags &= ~FLAG_WINDOW_UNFOCUSED; // The window was focused
else CORE.Window.flags |= FLAG_WINDOW_UNFOCUSED; // The window lost focus else CORE_WINDOW.flags |= FLAG_WINDOW_UNFOCUSED; // The window lost focus
} }
// GLFW3 Window Drop Callback, runs when drop files into window // GLFW3 Window Drop Callback, runs when drop files into window
@ -1372,24 +1373,24 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
if (count > 0) if (count > 0)
{ {
// In case previous dropped filepaths have not been freed, we free them // In case previous dropped filepaths have not been freed, we free them
if (CORE.Window.dropFileCount > 0) if (CORE_WINDOW.dropFileCount > 0)
{ {
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]); for (unsigned int i = 0; i < CORE_WINDOW.dropFileCount; i++) RL_FREE(CORE_WINDOW.dropFilepaths[i]);
RL_FREE(CORE.Window.dropFilepaths); RL_FREE(CORE_WINDOW.dropFilepaths);
CORE.Window.dropFileCount = 0; CORE_WINDOW.dropFileCount = 0;
CORE.Window.dropFilepaths = NULL; CORE_WINDOW.dropFilepaths = NULL;
} }
// WARNING: Paths are freed by GLFW when the callback returns, we must keep an internal copy // WARNING: Paths are freed by GLFW when the callback returns, we must keep an internal copy
CORE.Window.dropFileCount = count; CORE_WINDOW.dropFileCount = count;
CORE.Window.dropFilepaths = (char **)RL_CALLOC(CORE.Window.dropFileCount, sizeof(char *)); CORE_WINDOW.dropFilepaths = (char **)RL_CALLOC(CORE_WINDOW.dropFileCount, sizeof(char *));
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) for (unsigned int i = 0; i < CORE_WINDOW.dropFileCount; i++)
{ {
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); CORE_WINDOW.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
strcpy(CORE.Window.dropFilepaths[i], paths[i]); strcpy(CORE_WINDOW.dropFilepaths[i], paths[i]);
} }
} }
} }
@ -1463,7 +1464,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
// Register touch points position, only one point registered // Register touch points position, only one point registered
gestureEvent.position[0] = GetMousePosition(); gestureEvent.position[0] = GetMousePosition();
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[0] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[0].y /= (float)GetScreenHeight();
@ -1496,7 +1497,7 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y)
// Register touch points position, only one point registered // Register touch points position, only one point registered
gestureEvent.position[0] = CORE.Input.Touch.position[0]; gestureEvent.position[0] = CORE.Input.Touch.position[0];
// Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[0] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].x /= (float)GetScreenWidth();
gestureEvent.position[0].y /= (float)GetScreenHeight(); gestureEvent.position[0].y /= (float)GetScreenHeight();
@ -1522,16 +1523,16 @@ static void CursorEnterCallback(GLFWwindow *window, int enter)
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData) static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData)
{ {
// NOTE: 1. Reset the fullscreen flags if the user left fullscreen manually by pressing the Escape key // NOTE: 1. Reset the fullscreen flags if the user left fullscreen manually by pressing the Escape key
// 2. Which is a necessary safeguard because that case will bypass the toggles CORE.Window.flags resets // 2. Which is a necessary safeguard because that case will bypass the toggles CORE_WINDOW.flags resets
if (platform.ourFullscreen) platform.ourFullscreen = false; if (platform.ourFullscreen) platform.ourFullscreen = false;
else else
{ {
const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0); const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
if (!wasFullscreen) if (!wasFullscreen)
{ {
CORE.Window.fullscreen = false; CORE_WINDOW.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; CORE_WINDOW.flags &= ~FLAG_FULLSCREEN_MODE;
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE; CORE_WINDOW.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
} }
} }
@ -1553,32 +1554,32 @@ EM_JS(int, GetWindowInnerHeight, (), { return window.innerHeight; });
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData) static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData)
{ {
// Don't resize non-resizeable windows // Don't resize non-resizeable windows
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) == 0) return 1; if ((CORE_WINDOW.flags & FLAG_WINDOW_RESIZABLE) == 0) return 1;
// This event is called whenever the window changes sizes, // This event is called whenever the window changes sizes,
// so the size of the canvas object is explicitly retrieved below // so the size of the canvas object is explicitly retrieved below
int width = GetWindowInnerWidth(); int width = GetWindowInnerWidth();
int height = GetWindowInnerHeight(); int height = GetWindowInnerHeight();
if (width < CORE.Window.screenMin.width) width = CORE.Window.screenMin.width; if (width < CORE_WINDOW.screenMin.width) width = CORE_WINDOW.screenMin.width;
else if (width > CORE.Window.screenMax.width && CORE.Window.screenMax.width > 0) width = CORE.Window.screenMax.width; else if (width > CORE_WINDOW.screenMax.width && CORE_WINDOW.screenMax.width > 0) width = CORE_WINDOW.screenMax.width;
if (height < CORE.Window.screenMin.height) height = CORE.Window.screenMin.height; if (height < CORE_WINDOW.screenMin.height) height = CORE_WINDOW.screenMin.height;
else if (height > CORE.Window.screenMax.height && CORE.Window.screenMax.height > 0) height = CORE.Window.screenMax.height; else if (height > CORE_WINDOW.screenMax.height && CORE_WINDOW.screenMax.height > 0) height = CORE_WINDOW.screenMax.height;
emscripten_set_canvas_element_size("#canvas", width, height); emscripten_set_canvas_element_size("#canvas", width, height);
SetupViewport(width, height); // Reset viewport and projection matrix for new size SetupViewport(width, height); // Reset viewport and projection matrix for new size
CORE.Window.currentFbo.width = width; CORE_WINDOW.currentFbo.width = width;
CORE.Window.currentFbo.height = height; CORE_WINDOW.currentFbo.height = height;
CORE.Window.resizedLastFrame = true; CORE_WINDOW.resizedLastFrame = true;
if (IsWindowFullscreen()) return 1; if (IsWindowFullscreen()) return 1;
// Set current screen size // Set current screen size
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
// NOTE: Postprocessing texture is not scaled to new size // NOTE: Postprocessing texture is not scaled to new size
@ -1644,7 +1645,7 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent
// Register touch points position // Register touch points position
CORE.Input.Touch.position[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY}; CORE.Input.Touch.position[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY};
// Normalize gestureEvent.position[x] for CORE.Window.screen.width and CORE.Window.screen.height // Normalize gestureEvent.position[x] for CORE_WINDOW.screen.width and CORE_WINDOW.screen.height
CORE.Input.Touch.position[i].x *= ((float)GetScreenWidth()/(float)canvasWidth); CORE.Input.Touch.position[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight); CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);

View File

@ -362,6 +362,8 @@ RLAPI const char *raylib_version = RAYLIB_VERSION; // raylib version exported s
CoreData CORE = { 0 }; // Global CORE state context CoreData CORE = { 0 }; // Global CORE state context
#define CORE_WINDOW CORE.Window
#if defined(SUPPORT_SCREEN_CAPTURE) #if defined(SUPPORT_SCREEN_CAPTURE)
static int screenshotCounter = 0; // Screenshots counter static int screenshotCounter = 0; // Screenshots counter
#endif #endif
@ -610,11 +612,11 @@ void InitWindow(int width, int height, const char *title)
#endif #endif
// Initialize window data // Initialize window data
CORE.Window.screen.width = width; CORE_WINDOW.screen.width = width;
CORE.Window.screen.height = height; CORE_WINDOW.screen.height = height;
CORE.Window.eventWaiting = false; CORE_WINDOW.eventWaiting = false;
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default CORE_WINDOW.screenScale = MatrixIdentity(); // No draw scaling required by default
if ((title != NULL) && (title[0] != 0)) CORE.Window.title = title; if ((title != NULL) && (title[0] != 0)) CORE_WINDOW.title = title;
// Initialize global input state // Initialize global input state
memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0 memset(&CORE.Input, 0, sizeof(CORE.Input)); // Reset CORE.Input structure to 0
@ -629,11 +631,11 @@ void InitWindow(int width, int height, const char *title)
//-------------------------------------------------------------- //--------------------------------------------------------------
// Initialize rlgl default data (buffers and shaders) // 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 // 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); rlglInit(CORE_WINDOW.currentFbo.width, CORE_WINDOW.currentFbo.height);
// Setup default viewport // Setup default viewport
SetupViewport(CORE.Window.currentFbo.width, CORE.Window.currentFbo.height); SetupViewport(CORE_WINDOW.currentFbo.width, CORE_WINDOW.currentFbo.height);
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
// Load default font // Load default font
@ -643,7 +645,7 @@ void InitWindow(int width, int height, const char *title)
// Set font white rectangle for shapes drawing, so shapes and text can be batched together // 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 // WARNING: rshapes module is required, if not available, default internal white rectangle is used
Rectangle rec = GetFontDefault().recs[95]; Rectangle rec = GetFontDefault().recs[95];
if (CORE.Window.flags & FLAG_MSAA_4X_HINT) if (CORE_WINDOW.flags & FLAG_MSAA_4X_HINT)
{ {
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering // 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 }); SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
@ -663,7 +665,7 @@ void InitWindow(int width, int height, const char *title)
#endif #endif
#endif #endif
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) if ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0)
{ {
// Set default font texture filter for HighDPI (blurry) // Set default font texture filter for HighDPI (blurry)
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps // RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
@ -673,7 +675,7 @@ void InitWindow(int width, int height, const char *title)
#endif #endif
CORE.Time.frameCounter = 0; CORE.Time.frameCounter = 0;
CORE.Window.shouldClose = false; CORE_WINDOW.shouldClose = false;
// Initialize random seed // Initialize random seed
SetRandomSeed((unsigned int)time(NULL)); SetRandomSeed((unsigned int)time(NULL));
@ -702,68 +704,68 @@ void CloseWindow(void)
ClosePlatform(); ClosePlatform();
//-------------------------------------------------------------- //--------------------------------------------------------------
CORE.Window.ready = false; CORE_WINDOW.ready = false;
TRACELOG(LOG_INFO, "Window closed successfully"); 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)
{ {
return CORE.Window.ready; return CORE_WINDOW.ready;
} }
// Check if window is currently fullscreen // Check if window is currently fullscreen
bool IsWindowFullscreen(void) bool IsWindowFullscreen(void)
{ {
return CORE.Window.fullscreen; return CORE_WINDOW.fullscreen;
} }
// Check if window is currently hidden // Check if window is currently hidden
bool IsWindowHidden(void) bool IsWindowHidden(void)
{ {
return ((CORE.Window.flags & FLAG_WINDOW_HIDDEN) > 0); return ((CORE_WINDOW.flags & FLAG_WINDOW_HIDDEN) > 0);
} }
// Check if window has been minimized // Check if window has been minimized
bool IsWindowMinimized(void) bool IsWindowMinimized(void)
{ {
return ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0); return ((CORE_WINDOW.flags & FLAG_WINDOW_MINIMIZED) > 0);
} }
// Check if window has been maximized // Check if window has been maximized
bool IsWindowMaximized(void) bool IsWindowMaximized(void)
{ {
return ((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0); return ((CORE_WINDOW.flags & FLAG_WINDOW_MAXIMIZED) > 0);
} }
// Check if window has the focus // Check if window has the focus
bool IsWindowFocused(void) bool IsWindowFocused(void)
{ {
return ((CORE.Window.flags & FLAG_WINDOW_UNFOCUSED) == 0); return ((CORE_WINDOW.flags & FLAG_WINDOW_UNFOCUSED) == 0);
} }
// Check if window has been resizedLastFrame // Check if window has been resizedLastFrame
bool IsWindowResized(void) bool IsWindowResized(void)
{ {
return CORE.Window.resizedLastFrame; return CORE_WINDOW.resizedLastFrame;
} }
// Check if one specific window flag is enabled // Check if one specific window flag is enabled
bool IsWindowState(unsigned int flag) bool IsWindowState(unsigned int flag)
{ {
return ((CORE.Window.flags & flag) > 0); return ((CORE_WINDOW.flags & flag) > 0);
} }
// Get current screen width // Get current screen width
int GetScreenWidth(void) int GetScreenWidth(void)
{ {
return CORE.Window.screen.width; return CORE_WINDOW.screen.width;
} }
// Get current screen height // Get current screen height
int GetScreenHeight(void) int GetScreenHeight(void)
{ {
return CORE.Window.screen.height; return CORE_WINDOW.screen.height;
} }
// Get current render width which is equal to screen width*dpi scale // Get current render width which is equal to screen width*dpi scale
@ -772,9 +774,9 @@ int GetRenderWidth(void)
int width = 0; int width = 0;
#if defined(__APPLE__) #if defined(__APPLE__)
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
width = (int)((float)CORE.Window.render.width*scale.x); width = (int)((float)CORE_WINDOW.render.width*scale.x);
#else #else
width = CORE.Window.render.width; width = CORE_WINDOW.render.width;
#endif #endif
return width; return width;
} }
@ -785,9 +787,9 @@ int GetRenderHeight(void)
int height = 0; int height = 0;
#if defined(__APPLE__) #if defined(__APPLE__)
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
height = (int)((float)CORE.Window.render.height*scale.y); height = (int)((float)CORE_WINDOW.render.height*scale.y);
#else #else
height = CORE.Window.render.height; height = CORE_WINDOW.render.height;
#endif #endif
return height; return height;
} }
@ -795,13 +797,13 @@ int GetRenderHeight(void)
// Enable waiting for events on EndDrawing(), no automatic event polling // Enable waiting for events on EndDrawing(), no automatic event polling
void EnableEventWaiting(void) void EnableEventWaiting(void)
{ {
CORE.Window.eventWaiting = true; CORE_WINDOW.eventWaiting = true;
} }
// Disable waiting for events on EndDrawing(), automatic events polling // Disable waiting for events on EndDrawing(), automatic events polling
void DisableEventWaiting(void) void DisableEventWaiting(void)
{ {
CORE.Window.eventWaiting = false; CORE_WINDOW.eventWaiting = false;
} }
// Check if cursor is not visible // Check if cursor is not visible
@ -838,7 +840,7 @@ void BeginDrawing(void)
CORE.Time.previous = CORE.Time.current; CORE.Time.previous = CORE.Time.current;
rlLoadIdentity(); // Reset current matrix (modelview) rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling rlMultMatrixf(MatrixToFloat(CORE_WINDOW.screenScale)); // Apply screen scaling
//rlTranslatef(0.375, 0.375, 0); // HACK to have 2D pixel-perfect drawing on OpenGL 1.1 //rlTranslatef(0.375, 0.375, 0); // HACK to have 2D pixel-perfect drawing on OpenGL 1.1
// NOTE: Not required with OpenGL 3.3+ // NOTE: Not required with OpenGL 3.3+
@ -864,14 +866,14 @@ void EndDrawing(void)
// Get image data for the current frame (from backbuffer) // Get image data for the current frame (from backbuffer)
// NOTE: This process is quite slow... :( // NOTE: This process is quite slow... :(
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
unsigned char *screenData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y)); unsigned char *screenData = rlReadScreenPixels((int)((float)CORE_WINDOW.render.width*scale.x), (int)((float)CORE_WINDOW.render.height*scale.y));
#ifndef GIF_RECORD_BITRATE #ifndef GIF_RECORD_BITRATE
#define GIF_RECORD_BITRATE 16 #define GIF_RECORD_BITRATE 16
#endif #endif
// Add the frame to the gif recording, given how many frames have passed in centiseconds // Add the frame to the gif recording, given how many frames have passed in centiseconds
msf_gif_frame(&gifState, screenData, gifFrameCounter/10, GIF_RECORD_BITRATE, (int)((float)CORE.Window.render.width*scale.x)*4); msf_gif_frame(&gifState, screenData, gifFrameCounter/10, GIF_RECORD_BITRATE, (int)((float)CORE_WINDOW.render.width*scale.x)*4);
gifFrameCounter -= 1000/GIF_RECORD_FRAMERATE; gifFrameCounter -= 1000/GIF_RECORD_FRAMERATE;
RL_FREE(screenData); // Free image data RL_FREE(screenData); // Free image data
@ -881,8 +883,8 @@ void EndDrawing(void)
// Display the recording indicator every half-second // Display the recording indicator every half-second
if ((int)(GetTime()/0.5)%2 == 1) if ((int)(GetTime()/0.5)%2 == 1)
{ {
DrawCircle(30, CORE.Window.screen.height - 20, 10, MAROON); // WARNING: Module required: rshapes DrawCircle(30, CORE_WINDOW.screen.height - 20, 10, MAROON); // WARNING: Module required: rshapes
DrawText("GIF RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); // WARNING: Module required: rtext DrawText("GIF RECORDING", 50, CORE_WINDOW.screen.height - 25, 10, RED); // WARNING: Module required: rtext
} }
#endif #endif
@ -942,7 +944,7 @@ void EndDrawing(void)
gifFrameCounter = 0; gifFrameCounter = 0;
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
msf_gif_begin(&gifState, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y)); msf_gif_begin(&gifState, (int)((float)CORE_WINDOW.render.width*scale.x), (int)((float)CORE_WINDOW.render.height*scale.y));
screenshotCounter++; screenshotCounter++;
TRACELOG(LOG_INFO, "SYSTEM: Start animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter)); TRACELOG(LOG_INFO, "SYSTEM: Start animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter));
@ -978,7 +980,7 @@ void EndMode2D(void)
rlLoadIdentity(); // Reset current matrix (modelview) rlLoadIdentity(); // Reset current matrix (modelview)
if (rlGetActiveFramebuffer() == 0) rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required if (rlGetActiveFramebuffer() == 0) rlMultMatrixf(MatrixToFloat(CORE_WINDOW.screenScale)); // Apply screen scaling if required
} }
// Initializes 3D mode with custom camera (3D) // Initializes 3D mode with custom camera (3D)
@ -990,7 +992,7 @@ void BeginMode3D(Camera camera)
rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection
rlLoadIdentity(); // Reset current matrix (projection) rlLoadIdentity(); // Reset current matrix (projection)
float aspect = (float)CORE.Window.currentFbo.width/(float)CORE.Window.currentFbo.height; float aspect = (float)CORE_WINDOW.currentFbo.width/(float)CORE_WINDOW.currentFbo.height;
// NOTE: zNear and zFar values are important when computing depth buffer values // NOTE: zNear and zFar values are important when computing depth buffer values
if (camera.projection == CAMERA_PERSPECTIVE) if (camera.projection == CAMERA_PERSPECTIVE)
@ -1031,7 +1033,7 @@ void EndMode3D(void)
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview) rlLoadIdentity(); // Reset current matrix (modelview)
if (rlGetActiveFramebuffer() == 0) rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required if (rlGetActiveFramebuffer() == 0) rlMultMatrixf(MatrixToFloat(CORE_WINDOW.screenScale)); // Apply screen scaling if required
rlDisableDepthTest(); // Disable DEPTH_TEST for 2D rlDisableDepthTest(); // Disable DEPTH_TEST for 2D
} }
@ -1062,9 +1064,9 @@ void BeginTextureMode(RenderTexture2D target)
// Setup current width/height for proper aspect ratio // Setup current width/height for proper aspect ratio
// calculation when using BeginMode3D() // calculation when using BeginMode3D()
CORE.Window.currentFbo.width = target.texture.width; CORE_WINDOW.currentFbo.width = target.texture.width;
CORE.Window.currentFbo.height = target.texture.height; CORE_WINDOW.currentFbo.height = target.texture.height;
CORE.Window.usingFbo = true; CORE_WINDOW.usingFbo = true;
} }
// Ends drawing to render texture // Ends drawing to render texture
@ -1075,17 +1077,17 @@ void EndTextureMode(void)
rlDisableFramebuffer(); // Disable render target (fbo) rlDisableFramebuffer(); // Disable render target (fbo)
// Set viewport to default framebuffer size // Set viewport to default framebuffer size
SetupViewport(CORE.Window.render.width, CORE.Window.render.height); SetupViewport(CORE_WINDOW.render.width, CORE_WINDOW.render.height);
// Go back to the modelview state from BeginDrawing since we are back to the default FBO // Go back to the modelview state from BeginDrawing since we are back to the default FBO
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview) rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required rlMultMatrixf(MatrixToFloat(CORE_WINDOW.screenScale)); // Apply screen scaling if required
// Reset current fbo to screen size // Reset current fbo to screen size
CORE.Window.currentFbo.width = CORE.Window.render.width; CORE_WINDOW.currentFbo.width = CORE_WINDOW.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height; CORE_WINDOW.currentFbo.height = CORE_WINDOW.render.height;
CORE.Window.usingFbo = false; CORE_WINDOW.usingFbo = false;
} }
// Begin custom shader mode // Begin custom shader mode
@ -1122,21 +1124,21 @@ void BeginScissorMode(int x, int y, int width, int height)
rlEnableScissorTest(); rlEnableScissorTest();
#if defined(__APPLE__) #if defined(__APPLE__)
if (!CORE.Window.usingFbo) if (!CORE_WINDOW.usingFbo)
{ {
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
rlScissor((int)(x*scale.x), (int)(GetScreenHeight()*scale.y - (((y + height)*scale.y))), (int)(width*scale.x), (int)(height*scale.y)); rlScissor((int)(x*scale.x), (int)(GetScreenHeight()*scale.y - (((y + height)*scale.y))), (int)(width*scale.x), (int)(height*scale.y));
} }
#else #else
if (!CORE.Window.usingFbo && ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)) if (!CORE_WINDOW.usingFbo && ((CORE_WINDOW.flags & FLAG_WINDOW_HIGHDPI) > 0))
{ {
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
rlScissor((int)(x*scale.x), (int)(CORE.Window.currentFbo.height - (y + height)*scale.y), (int)(width*scale.x), (int)(height*scale.y)); rlScissor((int)(x*scale.x), (int)(CORE_WINDOW.currentFbo.height - (y + height)*scale.y), (int)(width*scale.x), (int)(height*scale.y));
} }
#endif #endif
else else
{ {
rlScissor(x, CORE.Window.currentFbo.height - (y + height), width, height); rlScissor(x, CORE_WINDOW.currentFbo.height - (y + height), width, height);
} }
} }
@ -1813,8 +1815,8 @@ void TakeScreenshot(const char *fileName)
if (strchr(fileName, '\'') != NULL) { TRACELOG(LOG_WARNING, "SYSTEM: Provided fileName could be potentially malicious, avoid [\'] character"); return; } if (strchr(fileName, '\'') != NULL) { TRACELOG(LOG_WARNING, "SYSTEM: Provided fileName could be potentially malicious, avoid [\'] character"); return; }
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
unsigned char *imgData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y)); unsigned char *imgData = rlReadScreenPixels((int)((float)CORE_WINDOW.render.width*scale.x), (int)((float)CORE_WINDOW.render.height*scale.y));
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 }; Image image = { imgData, (int)((float)CORE_WINDOW.render.width*scale.x), (int)((float)CORE_WINDOW.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
char path[512] = { 0 }; char path[512] = { 0 };
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, GetFileName(fileName))); strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, GetFileName(fileName)));
@ -1837,7 +1839,7 @@ void SetConfigFlags(unsigned int flags)
{ {
// Selected flags are set but not evaluated at this point, // Selected flags are set but not evaluated at this point,
// flag evaluation happens at InitWindow() or SetWindowState() // flag evaluation happens at InitWindow() or SetWindowState()
CORE.Window.flags |= flags; CORE_WINDOW.flags |= flags;
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -2249,7 +2251,7 @@ bool IsFileDropped(void)
{ {
bool result = false; bool result = false;
if (CORE.Window.dropFileCount > 0) result = true; if (CORE_WINDOW.dropFileCount > 0) result = true;
return result; return result;
} }
@ -2259,8 +2261,8 @@ FilePathList LoadDroppedFiles(void)
{ {
FilePathList files = { 0 }; FilePathList files = { 0 };
files.count = CORE.Window.dropFileCount; files.count = CORE_WINDOW.dropFileCount;
files.paths = CORE.Window.dropFilepaths; files.paths = CORE_WINDOW.dropFilepaths;
return files; return files;
} }
@ -2276,8 +2278,8 @@ void UnloadDroppedFiles(FilePathList files)
RL_FREE(files.paths); RL_FREE(files.paths);
CORE.Window.dropFileCount = 0; CORE_WINDOW.dropFileCount = 0;
CORE.Window.dropFilepaths = NULL; CORE_WINDOW.dropFilepaths = NULL;
} }
} }
@ -2671,7 +2673,7 @@ void PlayAutomationEvent(AutomationEvent event)
case INPUT_GESTURE: GESTURES.current = event.params[0]; break; // param[0]: gesture (enum Gesture) -> rgestures.h: GESTURES.current case INPUT_GESTURE: GESTURES.current = event.params[0]; break; // param[0]: gesture (enum Gesture) -> rgestures.h: GESTURES.current
#endif #endif
// Window event // Window event
case WINDOW_CLOSE: CORE.Window.shouldClose = true; break; case WINDOW_CLOSE: CORE_WINDOW.shouldClose = true; break;
case WINDOW_MAXIMIZE: MaximizeWindow(); break; case WINDOW_MAXIMIZE: MaximizeWindow(); break;
case WINDOW_MINIMIZE: MinimizeWindow(); break; case WINDOW_MINIMIZE: MinimizeWindow(); break;
case WINDOW_RESIZE: SetWindowSize(event.params[0], event.params[1]); break; case WINDOW_RESIZE: SetWindowSize(event.params[0], event.params[1]); break;
@ -3114,17 +3116,17 @@ void InitTimer(void)
// Set viewport for a provided width and height // Set viewport for a provided width and height
void SetupViewport(int width, int height) void SetupViewport(int width, int height)
{ {
CORE.Window.render.width = width; CORE_WINDOW.render.width = width;
CORE.Window.render.height = height; CORE_WINDOW.render.height = height;
// Set viewport width and height // Set viewport width and height
// NOTE: We consider render size (scaled) and offset in case black bars are required and // NOTE: We consider render size (scaled) and offset in case black bars are required and
// render area does not match full display area (this situation is only applicable on fullscreen mode) // render area does not match full display area (this situation is only applicable on fullscreen mode)
#if defined(__APPLE__) #if defined(__APPLE__)
Vector2 scale = GetWindowScaleDPI(); Vector2 scale = GetWindowScaleDPI();
rlViewport(CORE.Window.renderOffset.x/2*scale.x, CORE.Window.renderOffset.y/2*scale.y, (CORE.Window.render.width)*scale.x, (CORE.Window.render.height)*scale.y); rlViewport(CORE_WINDOW.renderOffset.x/2*scale.x, CORE_WINDOW.renderOffset.y/2*scale.y, (CORE_WINDOW.render.width)*scale.x, (CORE_WINDOW.render.height)*scale.y);
#else #else
rlViewport(CORE.Window.renderOffset.x/2, CORE.Window.renderOffset.y/2, CORE.Window.render.width, CORE.Window.render.height); rlViewport(CORE_WINDOW.renderOffset.x/2, CORE_WINDOW.renderOffset.y/2, CORE_WINDOW.render.width, CORE_WINDOW.render.height);
#endif #endif
rlMatrixMode(RL_PROJECTION); // Switch to projection matrix rlMatrixMode(RL_PROJECTION); // Switch to projection matrix
@ -3132,87 +3134,87 @@ void SetupViewport(int width, int height)
// Set orthographic projection to current framebuffer size // Set orthographic projection to current framebuffer size
// NOTE: Configured top-left corner as (0, 0) // NOTE: Configured top-left corner as (0, 0)
rlOrtho(0, CORE.Window.render.width, CORE.Window.render.height, 0, 0.0f, 1.0f); rlOrtho(0, CORE_WINDOW.render.width, CORE_WINDOW.render.height, 0, 0.0f, 1.0f);
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview) rlLoadIdentity(); // Reset current matrix (modelview)
} }
// Compute framebuffer size relative to screen size and display size // Compute framebuffer size relative to screen size and display size
// NOTE: Global variables CORE.Window.render.width/CORE.Window.render.height and CORE.Window.renderOffset.x/CORE.Window.renderOffset.y can be modified // NOTE: Global variables CORE_WINDOW.render.width/CORE_WINDOW.render.height and CORE_WINDOW.renderOffset.x/CORE_WINDOW.renderOffset.y can be modified
void SetupFramebuffer(int width, int height) void SetupFramebuffer(int width, int height)
{ {
// Calculate CORE.Window.render.width and CORE.Window.render.height, we have the display size (input params) and the desired screen size (global var) // Calculate CORE_WINDOW.render.width and CORE_WINDOW.render.height, we have the display size (input params) and the desired screen size (global var)
if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height)) if ((CORE_WINDOW.screen.width > CORE_WINDOW.display.width) || (CORE_WINDOW.screen.height > CORE_WINDOW.display.height))
{ {
TRACELOG(LOG_WARNING, "DISPLAY: Downscaling required: Screen size (%ix%i) is bigger than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_WARNING, "DISPLAY: Downscaling required: Screen size (%ix%i) is bigger than display size (%ix%i)", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, CORE_WINDOW.display.width, CORE_WINDOW.display.height);
// Downscaling to fit display with border-bars // Downscaling to fit display with border-bars
float widthRatio = (float)CORE.Window.display.width/(float)CORE.Window.screen.width; float widthRatio = (float)CORE_WINDOW.display.width/(float)CORE_WINDOW.screen.width;
float heightRatio = (float)CORE.Window.display.height/(float)CORE.Window.screen.height; float heightRatio = (float)CORE_WINDOW.display.height/(float)CORE_WINDOW.screen.height;
if (widthRatio <= heightRatio) if (widthRatio <= heightRatio)
{ {
CORE.Window.render.width = CORE.Window.display.width; CORE_WINDOW.render.width = CORE_WINDOW.display.width;
CORE.Window.render.height = (int)round((float)CORE.Window.screen.height*widthRatio); CORE_WINDOW.render.height = (int)round((float)CORE_WINDOW.screen.height*widthRatio);
CORE.Window.renderOffset.x = 0; CORE_WINDOW.renderOffset.x = 0;
CORE.Window.renderOffset.y = (CORE.Window.display.height - CORE.Window.render.height); CORE_WINDOW.renderOffset.y = (CORE_WINDOW.display.height - CORE_WINDOW.render.height);
} }
else else
{ {
CORE.Window.render.width = (int)round((float)CORE.Window.screen.width*heightRatio); CORE_WINDOW.render.width = (int)round((float)CORE_WINDOW.screen.width*heightRatio);
CORE.Window.render.height = CORE.Window.display.height; CORE_WINDOW.render.height = CORE_WINDOW.display.height;
CORE.Window.renderOffset.x = (CORE.Window.display.width - CORE.Window.render.width); CORE_WINDOW.renderOffset.x = (CORE_WINDOW.display.width - CORE_WINDOW.render.width);
CORE.Window.renderOffset.y = 0; CORE_WINDOW.renderOffset.y = 0;
} }
// Screen scaling required // Screen scaling required
float scaleRatio = (float)CORE.Window.render.width/(float)CORE.Window.screen.width; float scaleRatio = (float)CORE_WINDOW.render.width/(float)CORE_WINDOW.screen.width;
CORE.Window.screenScale = MatrixScale(scaleRatio, scaleRatio, 1.0f); CORE_WINDOW.screenScale = MatrixScale(scaleRatio, scaleRatio, 1.0f);
// NOTE: We render to full display resolution! // NOTE: We render to full display resolution!
// We just need to calculate above parameters for downscale matrix and offsets // We just need to calculate above parameters for downscale matrix and offsets
CORE.Window.render.width = CORE.Window.display.width; CORE_WINDOW.render.width = CORE_WINDOW.display.width;
CORE.Window.render.height = CORE.Window.display.height; CORE_WINDOW.render.height = CORE_WINDOW.display.height;
TRACELOG(LOG_WARNING, "DISPLAY: Downscale matrix generated, content will be rendered at (%ix%i)", CORE.Window.render.width, CORE.Window.render.height); TRACELOG(LOG_WARNING, "DISPLAY: Downscale matrix generated, content will be rendered at (%ix%i)", CORE_WINDOW.render.width, CORE_WINDOW.render.height);
} }
else if ((CORE.Window.screen.width < CORE.Window.display.width) || (CORE.Window.screen.height < CORE.Window.display.height)) else if ((CORE_WINDOW.screen.width < CORE_WINDOW.display.width) || (CORE_WINDOW.screen.height < CORE_WINDOW.display.height))
{ {
// Required screen size is smaller than display size // Required screen size is smaller than display size
TRACELOG(LOG_INFO, "DISPLAY: Upscaling required: Screen size (%ix%i) smaller than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height); TRACELOG(LOG_INFO, "DISPLAY: Upscaling required: Screen size (%ix%i) smaller than display size (%ix%i)", CORE_WINDOW.screen.width, CORE_WINDOW.screen.height, CORE_WINDOW.display.width, CORE_WINDOW.display.height);
if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0)) if ((CORE_WINDOW.screen.width == 0) || (CORE_WINDOW.screen.height == 0))
{ {
CORE.Window.screen.width = CORE.Window.display.width; CORE_WINDOW.screen.width = CORE_WINDOW.display.width;
CORE.Window.screen.height = CORE.Window.display.height; CORE_WINDOW.screen.height = CORE_WINDOW.display.height;
} }
// Upscaling to fit display with border-bars // Upscaling to fit display with border-bars
float displayRatio = (float)CORE.Window.display.width/(float)CORE.Window.display.height; float displayRatio = (float)CORE_WINDOW.display.width/(float)CORE_WINDOW.display.height;
float screenRatio = (float)CORE.Window.screen.width/(float)CORE.Window.screen.height; float screenRatio = (float)CORE_WINDOW.screen.width/(float)CORE_WINDOW.screen.height;
if (displayRatio <= screenRatio) if (displayRatio <= screenRatio)
{ {
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = (int)round((float)CORE.Window.screen.width/displayRatio); CORE_WINDOW.render.height = (int)round((float)CORE_WINDOW.screen.width/displayRatio);
CORE.Window.renderOffset.x = 0; CORE_WINDOW.renderOffset.x = 0;
CORE.Window.renderOffset.y = (CORE.Window.render.height - CORE.Window.screen.height); CORE_WINDOW.renderOffset.y = (CORE_WINDOW.render.height - CORE_WINDOW.screen.height);
} }
else else
{ {
CORE.Window.render.width = (int)round((float)CORE.Window.screen.height*displayRatio); CORE_WINDOW.render.width = (int)round((float)CORE_WINDOW.screen.height*displayRatio);
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.renderOffset.x = (CORE.Window.render.width - CORE.Window.screen.width); CORE_WINDOW.renderOffset.x = (CORE_WINDOW.render.width - CORE_WINDOW.screen.width);
CORE.Window.renderOffset.y = 0; CORE_WINDOW.renderOffset.y = 0;
} }
} }
else else
{ {
CORE.Window.render.width = CORE.Window.screen.width; CORE_WINDOW.render.width = CORE_WINDOW.screen.width;
CORE.Window.render.height = CORE.Window.screen.height; CORE_WINDOW.render.height = CORE_WINDOW.screen.height;
CORE.Window.renderOffset.x = 0; CORE_WINDOW.renderOffset.x = 0;
CORE.Window.renderOffset.y = 0; CORE_WINDOW.renderOffset.y = 0;
} }
} }