It is currently Mon Jun 18, 2018 12:43 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: OpenGLGadget context
PostPosted: Thu Dec 07, 2017 12:29 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 211
Hi,

I'm not sure if I completely understand the OpenGLGadget, but is it possible to two or more of them to share the same context, so as to have access to the same data? Imagine a game where each OpenGLGadget is a level and each needs access to the sprite images, etc.

Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Thu Dec 07, 2017 5:53 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 29, 2012 10:33 pm
Posts: 721
Location: United States
Multiple contexts usually isn't the most efficient way to go. I'd recommend creating one large context and then use glviewport_() to specify which regions to render to.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Thu Dec 07, 2017 6:27 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 211
Thanks for the reply.

My application is an editor. The OpenGLGadget is used as the editing area - the CanvasGadget was too slow. It has a tabbed interface, so I was using one OpenGLGadget per document. I tried using just one and switching it between the tabs by replacing gadgets in a SplitterGadget with it, but that caused all kinds of weirdness - sometimes the gadget would be destroyed for no reason.

So what I want is for each OpenGLGadget to be able to show the same things without duplicating them in memory for each tab.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Thu Dec 07, 2017 7:12 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 29, 2012 10:33 pm
Posts: 721
Location: United States
If you're putting the OpenGL gadget within the tabs of the panel gadget. Then I believe you have no choice but to have multiple contexts. There is such a thing as sharing data between contexts, but I'm not very familiar with it.

If the OpenGL gadget is the only thing within the panel gadget. Then you could try making a custom tab system within the OpenGLGadget itself. That way there would be no need for other OpenGL gadgets.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Thu Dec 07, 2017 7:42 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 211
There are a couple of other types of tabs that use standard GUI controls, which makes it a bit tricky.

I have a feeling that shared contexts would need to be added in by the PB team since I think each OpenGLGadget creates its own. I'm not that familiar with OpenGL, though.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Thu Dec 07, 2017 9:23 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 1978
Location: USA
Create your own button/tabs and you can do whatever you want. I created my own buttons for my SpriteMonkey v2 app and they work great. ;)

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.9.5 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: XP SP3 / AMD 64 4000+ / 1GB DDR / ATI 9250


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Mon Dec 11, 2017 2:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 211
J. Baker wrote:
Create your own button/tabs and you can do whatever you want. I created my own buttons for my SpriteMonkey v2 app and they work great. ;)

I used the TabBarGadget by STARGÅTE, and it works alright except for a very annoying flash when the tab is changed to an OpenGL one. I can't work out how to stop it doing that.
Code:
XIncludeFile("TabBarGadget.pbi")

Enumeration
  #Window
  #Menu
  #MenuAddStringTab
  #MenuAddOpenGLTab
  #TabGadget
  #OpenGLGadget
  #TabTypeString
  #TabTypeGL
  #OGLTimer
EndEnumeration

#GL_TEXTURE_RECTANGLE_NV = $84F5

Structure TabData
  type.i
  *container
  color.i
EndStructure

Global *OpenGLContainer

Procedure AddTab(type)
  Protected *tabData.TabData, text.s, position
 
  *tabData = AllocateStructure(TabData)
  *tabData\color = RGB(Random(255), Random(255), Random(255))
 
  If type = 1
    *tabData\type = #TabTypeString
    *tabData\container = ContainerGadget(#PB_Any, 10, GadgetY(#TabGadget) + GadgetHeight(#TabGadget), GadgetWidth(#TabGadget),
                                         WindowHeight(#Window) - (MenuHeight() + GadgetY(#TabGadget) + GadgetHeight(#TabGadget) + 10), #PB_Container_Single)
    Define gadget = StringGadget(#PB_Any, 0, 0, GadgetWidth(*tabData\container), GadgetHeight(*tabData\container), "String...")
    SetGadgetColor(gadget, #PB_Gadget_BackColor, *tabData\color)
    CloseGadgetList()
    text = "String Tab"
  ElseIf type = 2
    *tabData\type = #TabTypeGL
    *tabData\container = *OpenGLContainer
    text = "OpenGL Tab"
  EndIf
 
  position = AddTabBarGadgetItem(#TabGadget, #PB_Default, text, #Null, *tabData)
  SetTabBarGadgetState(#TabGadget, position)
  PostEvent(#PB_Event_Gadget, #Window, #TabGadget, #TabBarGadget_EventType_Change, position)
EndProcedure

Procedure RenderGL()
  Protected item, *tabData.TabData, r, g, b
  item = GetTabBarGadgetState(#TabGadget)
  If item > -1
    *tabData = GetTabBarGadgetItemData(#TabGadget, item)
    r = Red(*tabData\color) : g = Green(*tabData\color) : b = Blue(*tabData\color)
    If *tabData\type = #TabTypeGL
      SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_SetContext, #True)
      glClearColor_(r/255.0, g/255.0, b/255.0, 1.0)
      glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
      glDisable_(#GL_TEXTURE_RECTANGLE_NV)
      glBegin_(#GL_QUADS)
      Define x0, y0, x1, y1
      glColor4ub_(0, 0, 0, 1)
      x0 = 32
      y0 = 32
      x1 = 200
      y1 = 200
      glVertex2f_(x0, y0)
      glVertex2f_(x1, y0)
      glVertex2f_(x1, y1)
      glVertex2f_(x0, y1)
      glEnd_()
      SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
    EndIf
  EndIf
EndProcedure

If OpenWindow(#Window, 0, 0, 640, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  If CreateMenu(#Menu, WindowID(#Window))
    MenuTitle("Tab")
    MenuItem(#MenuAddStringTab, "Add String Tab")
    MenuItem(#MenuAddOpenGLTab, "Add OpenGL Tab")
  EndIf
 
  TabBarGadget(#TabGadget, 10, 10, WindowWidth(#Window) - 20, 32, #TabBarGadget_CloseButton, #Window)
 
  *OpenGLContainer = ContainerGadget(#PB_Any, 10, GadgetY(#TabGadget) + GadgetHeight(#TabGadget), GadgetWidth(#TabGadget),
                                     WindowHeight(#Window) - (MenuHeight() + GadgetY(#TabGadget) + GadgetHeight(#TabGadget) + 10), #PB_Container_Single)
  OpenGLGadget(#OpenGLGadget, 0, 0, GadgetWidth(*OpenGLContainer), GadgetHeight(*OpenGLContainer))
  CloseGadgetList()
 
  HideGadget(*OpenGLContainer, 1)
 
  glViewport_(0, 0, GadgetWidth(#OpenGLGadget), GadgetHeight(#OpenGLGadget))
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  glOrtho_(0, GadgetWidth(#OpenGLGadget), GadgetHeight(#OpenGLGadget), 0, -1, 1)
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  glTranslatef_(-0.375, -0.375, 0.0)
 
  AddWindowTimer(#Window, #OGLTimer, 16)
 
  Repeat
   
    Define Event
   
    Event = WaitWindowEvent()
   
    Select Event
       
      Case #PB_Event_Timer
        RenderGL()
       
      Case #PB_Event_Menu
       
        Select EventMenu()
          Case #MenuAddStringTab : AddTab(1)
          Case #MenuAddOpenGLTab : AddTab(2)
        EndSelect
       
      Case #PB_Event_Gadget
       
        Select EventType()
           
          Case #TabBarGadget_EventType_Change
           
            Define item, *tabData.TabData, i, *otherTabData.TabData
            item = EventData();GetTabBarGadgetItemPosition(#TabGadget, #TabBarGadgetItem_Event)
            If item > -1
              *tabData = GetTabBarGadgetItemData(#TabGadget, item)
              If *tabData
                HideGadget(*tabData\container, 0)
                For i = 0 To CountTabBarGadgetItems(#TabGadget) - 1
                  *otherTabData = GetTabBarGadgetItemData(#TabGadget, i)
                  If *otherTabData
                    If *otherTabData <> *tabData
                      If *otherTabData\type <> #TabTypeGL
                        HideGadget(*otherTabData\container, 1)
                      Else
                        If *tabData\type <> #TabTypeGL
                          HideGadget(*OpenGLContainer, 1)
                        EndIf
                      EndIf
                    EndIf
                  EndIf
                Next
              EndIf
            EndIf
           
        EndSelect
       
    EndSelect
   
  Until Event = #PB_Event_CloseWindow
 
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLGadget context
PostPosted: Sun Jan 21, 2018 9:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 211
Sorry to bring up an old topic, but I'm still struggling to get rid of the flash that occurs when changing between a String tab and an OpenGL tab. Does anyone have any ideas?

The OpenGLGadget is giving me such a headache, unfortunately: http://www.purebasic.fr/english/viewtopic.php?f=23&t=68980


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye