Get OpenGLgadget() context number?

Just starting out? Need help? Post your questions and find answers here.
User avatar
naf
User
User
Posts: 17
Joined: Fri Aug 18, 2023 3:19 pm
Location: Europe

Get OpenGLgadget() context number?

Post 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)
pjay
Enthusiast
Enthusiast
Posts: 289
Joined: Thu Mar 30, 2006 11:14 am

Re: Get OpenGLgadget() context number?

Post 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()
Post Reply