Get OpenGL Context Handle?

Everything related to 3D programming
MGD
User
User
Posts: 16
Joined: Wed Jul 27, 2022 8:31 pm

Get OpenGL Context Handle?

Post by MGD »

Is it possible to get the OpenGL context handle for a given OpenGlGadget? Is this what is returned by GadgetID() for an OpenGLGadget? I want to pass the context's handle for a specific OpenGLGadget to OpenGL code in a DLL (in a different language).
pjay
Enthusiast
Enthusiast
Posts: 251
Joined: Thu Mar 30, 2006 11:14 am

Re: Get OpenGL Context Handle?

Post by pjay »

if you're on Windows then you can use:

Code: Select all

SetGadgetAttribute(myGLgadget, #PB_OpenGL_SetContext, #True)
myContext = wglGetCurrentContext_()
MGD
User
User
Posts: 16
Joined: Wed Jul 27, 2022 8:31 pm

Re: Get OpenGL Context Handle?

Post by MGD »

Thanks! I had seen that in various places; was wondering if I was missing something. Any cross-platform (or even platform-specific) code for the others anyone is aware of.
Anyone an OpenGL expert? Is it even necessary if the PB code and foreign (DLL) code are executing in the same thread? Seems contexts are specific to a thread, and only one can be current at a time? Can I just make the gadget's context current and then call the DLL function that will generate a frame?
pjay
Enthusiast
Enthusiast
Posts: 251
Joined: Thu Mar 30, 2006 11:14 am

Re: Get OpenGL Context Handle?

Post by pjay »

I've not used it, but linux uses a glx prefix, so glxGetCurrentContext would be my guess.

The article here: https://www.khronos.org/opengl/wiki/Ope ... ithreading is on opengl & multi-threading that may be of some use.
MGD
User
User
Posts: 16
Joined: Wed Jul 27, 2022 8:31 pm

Re: Get OpenGL Context Handle?

Post by MGD »

Thanks again! Browsing the khronos site, my understanding is that any OpenGL calls made in the current thread, regardless of whether the code is called in a DLL, will act on the current context, so I shouldn't need the handle. I'll give it a try.
Post Reply