-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use multiple windows
These instructions will not work for Raylib 5.0 or above, they are here for historical purposes only.
raylib does not support multiple Windows by default, it was designed with simplicity in main and multi-window option was not considered as a core feature.
Fortunately raylib's current design allows adding multi-window support in an easy way, in case some user requires this functionality.
the 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.
www.raylib.com | itch.io | GitHub | Discord | YouTube
- Architecture
- Syntax analysis
- Data structures
- Enumerated types
- External dependencies
- GLFW dependency
- libc dependency
- Platforms and graphics
- Input system
- Default shader
- Custom shaders
- Coding conventions
- Integration with other libs
- Working on Windows
- Working on macOS
- Working on GNU Linux
- Working on Chrome OS
- Working on FreeBSD
- Working on Raspberry Pi
- Working for Android
- Working for Web (HTML5)
- Working on exaequOS Web Computer
- Creating Discord Activities
- Working anywhere with CMake
- CMake Build Options
- raylib templates: Get started easily
- How To: Quick C/C++ Setup in Visual Studio 2022, GCC or MinGW
- How To: C# Visual Studio Setup
- How To: VSCode
- How To: Eclipse
- How To: Sublime Text
- How To: Code::Blocks