Page 1 of 1

Get OpenGLgadget() context number?

Posted: Thu Jan 22, 2026 2:51 pm
by naf
The setter

Code: Select all

#PB_OpenGL_SetContext
is useful, but there is no getter, like maybe #PB_OpenGL_GetContext.

Code: Select all

GetGadgetAttribute(openGLgadgetNum, #PB_OpenGL_SetContext )
only returns 0, not working.
The same question came when using wegGL / webView: viewtopic.php?p=636229#p636229
In practice, the first opened OpenGLgadget() gets context 0, the second one has context = 1, and so on. It works. But becomes unusable when the user has the freedom to dynamically create and and close windows and their OpenGLgadget()'s. The context number is needed after dynamic creation of an OpenGLgadget().
Is there a quick workaround by importing something from a library and skipping the standard GetGadgetAttribute() ?
Thanks. (PB v.6.21 on linux Zorin with Wayland, msi GP72 2QE Leopard Pro)

Re: Get OpenGLgadget() context number?

Posted: Fri Jan 23, 2026 8:30 am
by pjay
I've used this code, but only tested on Windows:

Code: Select all

Procedure glGetCurrentContext()
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows : ProcedureReturn wglGetCurrentContext_()
    CompilerCase #PB_OS_Linux : ProcedureReturn glxGetCurrentContext_()
    CompilerCase #PB_OS_MacOS : ProcedureReturn CGLGetCurrentContext_()
  CompilerEndSelect
EndProcedure
 
OpenWindow(0,0,0,1280,480,"")
OpenGLGadget(0,0,0,640,480) : Debug glGetCurrentContext()
OpenGLGadget(1,640,0,640,480) : Debug glGetCurrentContext()

SetGadgetAttribute(0, #PB_OpenGL_SetContext, 1) : Debug glGetCurrentContext()
SetGadgetAttribute(1, #PB_OpenGL_SetContext, 1) : Debug glGetCurrentContext()