@ -4,14 +4,15 @@ Fortunately raylib current design allows adding multi-window support in an easy
Those are the setps to follow to modify the raylib source code and add multi-window support:
- [core] Double the `CoreData.Window` struct into `CoreData.Window[2]` and add a `currentWindow` variable as global index to switch between the structures
- [core] Quick and dirt find/replace all for `CORE.Window` to `CORE.Window[CORE.currentWindow]`
- [rlgl] Double `rlglData RLGL` into `rlglData RLGL[2]` and add a `currentContext` variable as global index to switch between the structures
- [rlgl] Quick and dirt find/replace all for `RLGL` to `RLGL[currentContext]`
- [raylib.h] A `MAX_CONTEXTS` constant is defined to give the size of `RLGL[]` and `CoreData.Window[]`
- [core] Change the `CoreData.Window` struct into `CoreData.Window[MAX_CONTEXTS]` and add a `currentWindow` variable as global index to switch between the structures, as well as a `numWindows` variable to keep count of the total number of windows
- [core] Quick and dirty find/replace all for `CORE.Window` to `CORE.Window[CORE.currentWindow]`
- [rlgl] Change `rlglData RLGL` into `rlglData RLGL[MAX_CONTEXTS]` and add a `currentContext` variable as global index to switch between the structures, as well as a `numContexts` variable to keep count of the total number of contexts
- [rlgl] Quick and dirt find/replace all for `RLGL` to `RLGL[currentContext]` + `rlSetContext(unsigned int)`
- [core] Change the final `glfwCreateWindow()` parameter to share resources from the first context to the second
- [core] Create a new `SetWindowCurrent()` function to `glfwMakeContextCurrent()` on the current window and to set the right `RLGL[]` and `Window[]`
- Write some other few hack lines of code to glue everything together (needs more info!)
- [core] Change `BeginDrawing()` function to accept a `contextID` parameter in order to `CORE.currentWindow = contextID` and `glfwMakeContextCurrent(CORE.Window[CORE.currentWindow].handle)` on the current window and to set the right `RLGL[]` by `rlSetContext(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 `SetWindowCurrent(n)` to set current window for drawing (`BeginDrawing()`- `EndDrawing()`).
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 been tested only on Microsoft Windows for recreational purpose.