Page 1 of 1
Get OpenGL Context Handle?
Posted: Mon Feb 24, 2025 4:50 am
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).
Re: Get OpenGL Context Handle?
Posted: Mon Feb 24, 2025 7:15 am
by pjay
if you're on Windows then you can use:
Code: Select all
SetGadgetAttribute(myGLgadget, #PB_OpenGL_SetContext, #True)
myContext = wglGetCurrentContext_()
Re: Get OpenGL Context Handle?
Posted: Mon Feb 24, 2025 10:43 pm
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?
Re: Get OpenGL Context Handle?
Posted: Fri Feb 28, 2025 8:16 am
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.
Re: Get OpenGL Context Handle?
Posted: Tue Mar 04, 2025 3:02 am
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.