Use multiple windows - raysan5/raylib GitHub Wiki
raylib does not support multiple Windows by default, it was designed with simplicity in mind and multi-window option was not considered as a core feature. Multiple windows break some of the core concepts and APIs in raylib.
Multiple windows are possible with modifications to raylib and the understanding that some simple things may not work in as simple of a way as they did before.
support for raylib 5.0+
Adding support for multiple windows is somewhat complicated to support in raylib versions 5.0+. The platform split means that each platform needs to have information about all the windows. Also the older instructions did not handle events properly on multiple windows.
Experimental multi-window branch
The branch of raylib has been modified to support multiple windows https://github.com/JeffM2501/raylib/tree/multi-monitor_50
The changes are similar to what is listed below, but more detailed and go into a lot of different platform code.
Old info for raylib V4.5 and below.
These instructions will not work for Raylib 5.0 or above, they are here for historical purposes only.
The rough steps to follow to modify the raylib source code and add multi-window support are as follows:
- [raylib.h] A
MAX_CONTEXTS
constant is defined to give the size ofRLGL[]
andCoreData.Window[]
- [core] Change the
CoreData.Window
struct intoCoreData.Window[MAX_CONTEXTS]
and add acurrentWindow
variable as global index to switch between the structures, as well as anumWindows
variable to keep count of the total number of windows - [core] Quick and dirty find/replace all for
CORE.Window
toCORE.Window[CORE.currentWindow]
- [rlgl] Change
rlglData RLGL
intorlglData RLGL[MAX_CONTEXTS]
and add acurrentContext
variable as global index to switch between the structures, as well as anumContexts
variable to keep count of the total number of contexts - [rlgl] Quick and dirt find/replace all for
RLGL
toRLGL[currentContext]
+rlSetContext(unsigned int)
- [core] Change the final
glfwCreateWindow()
parameter to share resources from the first context to the second - [core] Change
BeginDrawing()
function to accept acontextID
parameter in order toCORE.currentWindow = contextID
andglfwMakeContextCurrent(CORE.Window[CORE.currentWindow].handle)
on the current window and to set the rightRLGL[]
byrlSetContext(contextID)
- [git] Checkout https://github.com/vb-mich/raylib/tree/multiple-contexts-hack and https://github.com/vb-mich/raylib/commit/6ddc54cdde86136e07da69d3323aeb73e2ee11af to see the changes
That's it. To use it just call InitWindow()
twice to get two windows. Then, just call BeginDrawing(n)
to set current window for drawing (BeginDrawing(n)
- EndDrawing()
).
NOTE: This has only been tested on Microsoft Windows for recreational purposes.