Using an existing OpenGL context with GLFW

Hi All,

As you probably know Raylib uses GLFW as its backend.
I am interested in using Raylib to draw onto a canvas.
My programming language of choice (Racket) has a very nice cross platform window and event
system - so I want to use that.

My plan was to create a window containing a canvas.
Get the OpenGL context from the canvas.
Then pass the OpenGL context to Raylib.
Which then passes the OpenGL context to GLFW.

Alas, the plan stopped there. I can’t see a way to use an existing OpenGL context with Raylib.
No problem I thought, I can add that my self.

But I can’t find what I need in the GLFW documentation.

First of all - have I missed something obvious (I hope so).

It seems I am not the only one interested in use case above - the issue below has 20 upvotes.

Is there some hidden technical challenge?
Or is it just a case, that none with the required expertise has run into the issue?

As you can see from the issue you linked to this is not currently possible with GLFW.

Multi platform window & context creation is non-trivial (which is why libraries like GLFW exist). For example you mention Then pass the OpenGL context to Raylib. Which then passes the OpenGL context to GLFW however more than a context is required - GLFW is a windowing library so GLFW needs the native window handles and it sets up the OS window event handling. Since Racket likely sets up it’s own OS window event handling this would cause problems, with either GLFW or Racket functionality not working (or other errors occurring).

Even if this functionality was present in GLFW, Raylib would also need to be altered. Indeed it would likely be easier to alter Raylib to use a provided OpenGL context for it’s graphics functionality, since the other aspects of GLFW are only needed for the events & windowing etc. and you don’t need those.

A more sensible approach from someone who is able to choose which APIs to use is choose one or the other. If you want to use Raylib, if possible just use that.