So I have a bunch of meshes, materials, etc and then all of a sudden the window needs to be torn down and then recreated (such as switching on fullscreen with GLFW) which means I will get a new OpenGL context and my old OpenGL data is invalid.

What is the best way to reload all my OpenGL assets - do I save all the mesh and material data in system RAM (which is quite a waste isn't it? if you do not recreate the window during the game, it does absolutely nothing for alot of RAM) -OR- do you map the filepaths to all assets, and then re-read from disk when you reload them? (could lead to alot of file i/o)

Or is there a better alternative? What is the best-practice here?


1 Answer 1


The best practice is to create the new window first, sharing the resources with the old window's context, and then destroy the old window.

However, it doesn't seem like GLFW (even v3.0) supports resource sharing yet. For now, you may have to retain the data in RAM and then just recreate the OpenGL objects in the new window's context.

To accomplish this in GLFW, you pass an existing GLFWwindow * object to glfwCreateWindow(). (Thanks @tecu for the clarification!)

  • 3
    \$\begingroup\$ GLFW 3 does allow resource sharing: you have to pass an existing GLFWwindow* (the existing context you wish to share resources with) as the last argument to glfwCreateWindow (the new replacement window you intend to use). See the docs here. \$\endgroup\$
    – tecu
    Jul 20, 2013 at 15:39
  • 1
    \$\begingroup\$ @tecu Thanks for contributing. But please don't abuse the answer system to get comments posted. I've converted this comment for you, but will not do that again. Go out, ask questions, answer questions. You'll get enough rep to comment where ever you like. \$\endgroup\$
    – House
    Jul 20, 2013 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .