3

I make game engine. The structure is as follow: There is Core class which object creates at start of program, modules(class Module) join to core and have workers(class Worker). Workers divided into two types: normal and graphical. I made it for game loop organization.

So, I create GLFWOpenGLModule, which, as the name suggests, use GLFW for creating of window and OpenGL for drawing in this window. But GLFW doesn't allow to create two windows and draw in each of them. I can make GLFWOpenGLModule singleton by adding this code:

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

in constructor and not create two windows in module, but then I can't make two windows(for example for rendering multiple cameras, each camera in each window). How should I do in this case? Maybe I should use another library instead of GLFW?

devalone
  • 535
  • 6
  • 21
  • Pretty sure glfw supports multiple windows. – Brandon Jun 18 '17 at 18:59
  • @Brandon, I can create two windows, but how to draw in each of them? I didn't find this in google. – devalone Jun 18 '17 at 19:03
  • 5
    You need a OGL context for each window and you have to make the context of a window become the current context before drawing, except you have a separate thread for each window. – Rabbid76 Jun 18 '17 at 19:06
  • @Rabbid76, thanks, I found glfwMakeContextCurrent function and it seems this is what I need – devalone Jun 18 '17 at 19:15
  • 2
    That's not how you make singletons. Instead of throwing an exception on subsequent calls to the constructor, a singleton should return the original instance. See here for an example: https://stackoverflow.com/questions/1008019/c-singleton-design-pattern – p10ben Jun 19 '17 at 02:34
  • @p10ben, I know how to make true singleton, but in my case It's not necessary, once module created, core save pointer to it and will gave it to another part of program on request. Yes, my way also bad, may be I will make control of number of instances in Core class, for easy changing modules "on fly". – devalone Jun 19 '17 at 12:06
  • @Rabbid76 you mean "unless"? please tell me if so, I really need to know if separate threads launched by the same process have different openGL state. – Matias Chara Aug 06 '20 at 22:23

0 Answers0