D
D
devalone2017-06-18 21:17:22
C++ / C#
devalone, 2017-06-18 21:17:22

How to draw in two windows in OpenGL?

I am writing a game engine. The structure is approximately the following: there is a Core class, an object of which is created at the beginning of the program, modules (heirs of the Module class) are connected to it, modules have Workers that can be registered in Core for periodic processing. Modules are all equal, but Workers are divided into regular ones (they may have priority and some other settings that don’t really matter now) and graphic ones, this was done to organize the game cycle, so that Workers with physics game logic are processed first, etc. etc., and after - graphic and all this in a cycle.
So, I sketched a graphical module GLFWOpenGLModule, which, as the name implies, uses OpenGL and the GLFW library to create a window and draw on it, but GLFW is made in such a way that it can’t work in two windows at once (maybe I searched badly, but not found out how to do it).
You can make the GLFWOpenGLModule class a singleton, like so:

static int objectsCount = 0;
objectsCount++;
if (objectsCount > 1)
   throw SomeKindOfException("error message");

in the constructor.
But then it is impossible to create 2 windows, which can become a problem when expanding, for example, when it will be necessary to make each of the windows show the view from its own camera.
What is the best way to get out of this situation? Maybe you need to use some other library to create a window, or even write manually for each platform?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
devalone, 2017-06-18
@devalone

I found the glfwMakeContextCurrent function, it allows you to specify in which window to draw. And I will make the modules all the same as signaltons, and one module will be responsible for creating several windows and linking them to the cameras.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question