Results 1 to 8 of 8

Thread: Canvas-Window- how to bind TBGL?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170

    Canvas-Window- how to bind TBGL?

    I want to use canvas-windows to display different TBGL-stuff. But how do i get the correct handle to bind the canvas?

    Edit:
    found out
    '...
    DWord hCanvas = Canvas_Attach hWnd, 0, TRUE
    Control Handle hWnd, hCanvas To hCanvas
      
    TBGL_BindCanvas( hCanvas )
    '...
    
    Last edited by ReneMiner; 19-02-2015 at 17:21.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    it crashes - not always - and i don't know why.
    Mostly if moving one of the windows .

    Uses "UI", "TBGL"
    
    Type TBGL_CanWin      ' canvas-window to display tbgl
      hWnd As DWord
      hCanvas As DWord
      
      ClientW As Long
      ClientH As Long
      
      MouseX  As Long
      MouseY  As Long
      
      Backcolor As TBGL_TRGB
      Forecolor As TBGL_TRGBA
      
      
      Create       As Function 
      Proceed      As Function
      
      SetForecolor As Function
      SetBackcolor As Function
      
    End Type
    
    ' -----------------------------------------------------------------
    Function TBGL_CanWin.Create(ByVal sCaption As String, _
                                ByVal X        As Long,   _
                                ByVal Y        As Long,   _
                                ByVal W        As Long,   _
                                ByVal H        As Long    _
                                ) As DWord
    ' -----------------------------------------------------------------
    
    Local hCanvas As DWord At VarPtr(Me.hCanvas)
    Local screenW, screenH, screenD As Long
    
      TBGL_GetDesktopInfo( screenW, screenH, screenD )
    
    
      If X < 0 Or X + W > screenW Then
        X = screenW * 0.5 - W * 0.5 
      EndIf
      If Y < 0 Or Y + H > screenH Then
        Y = screenH * 0.5 - H * 0.5 
      EndIf
    
      Me.hWnd = Canvas_Window(sCaption, X, Y, W, H)
      Me.hCanvas = Canvas_Attach Me.hWnd, 0, TRUE 
      Control Handle Me.hWnd, Me.hCanvas To hCanvas
    
      Me.clientW = W
      Me.ClientH = H
    
      Function = Me.hWnd
        
    End Function    
    
    ' -----------------------------------------------------------------
    Function TBGL_CanWin.Proceed() As Boolean
    ' -----------------------------------------------------------------
      
      If Not IsWindow(Me.hWnd) Then Return FALSE
      
      TBGL_BindCanvas( Me.hCanvas )
    
      TBGL_RenderMatrix2D(0, Me.clientH, Me.clientW, 0)  ' set the fitting matrix 
      TBGL_DepthFunc( %TBGL_ALWAYS )               ' draw from back to front
      
      Me.MouseX = TBGL_MouseGetPosX
      Me.MouseY = TBGL_MouseGetPosY
      
      TBGL_BackColor(Me.Backcolor.R, Me.Backcolor.G, Me.Backcolor.B)
      
      TBGL_ClearFrame
      
        
        If All( _
               Between(Me.MouseX, 0, Me.clientW), _     
               Between(Me.MouseY, 0, Me.clientH)  _
               ) Then 
       ' draw a haircross at mouse-pos
          TBGL_Color(Me.Forecolor.R, Me.Forecolor.G, Me.Forecolor.B) 
             
          TBGL_Line(Me.MouseX - 5, Me.MouseY, Me.MouseX + 5, Me.MouseY)
          TBGL_Line(Me.MouseX, Me.MouseY - 5, Me.MouseX, Me.MouseY + 5)
           
        EndIf
               
      TBGL_DrawFrame
        
      If TBGL_GetWindowKeyOnce(Me.hWnd, %VK_ESCAPE) Then 
        Canvas_Window End Me.hWnd 
        Return FALSE
      EndIf
      
      Function = TRUE
      
    End Function  
    
    ' -----------------------------------------------------------------
    Function TBGL_CanWin.SetForecolor(ByVal R As Byte, _
                                      ByVal G As Byte, _
                                      ByVal B As Byte, _
                             Optional ByVal A As Byte  ) 
    ' -----------------------------------------------------------------
                                      
      Me.Forecolor.R = R
      Me.Forecolor.G = G
      Me.Forecolor.B = B
      If Function_CParams = 4 Then
        Me.Forecolor.A = A
      EndIf
        
      
                                 
    End Function  
    
    ' -----------------------------------------------------------------
    Function TBGL_CanWin.SetBackcolor(ByVal R As Byte, _
                                      ByVal G As Byte, _
                                      ByVal B As Byte  )                                      
    ' -----------------------------------------------------------------
    
      Me.Backcolor.R = R
      Me.Backcolor.G = G
      Me.Backcolor.B = B
      
    End Function  
    
    
    
    '-------------------------------------------------------------------
    ' the unit is the code above
    '#INCLUDE Once "TBGL_CanWin.tBasicU"
    
    
    
    
    
    Function TBMain()
    
    Dim window1, window2 As TBGL_CanWin
    
    With window1
      .Create("Window 1, esc to close", 200, 200, 320, 240 )
      .setForecolor(255,255,0)
      .setBackcolor(0, 50, 150)
    End With
    
    With window2
      .Create("Window 2, esc to close", 300, 300, 240, 320 )  
      .setForecolor(20,40,50)
      .setBackcolor(200, 250, 250)
    End With
    
    TBGL_ResetKeyState()
    
    Do
    
    Loop While Window1.proceed() Or Window2.proceed()
    
    End Function
    
    Last edited by ReneMiner; 19-02-2015 at 17:43.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Rene,

    I would recommend to take the classic canvas approach as demonstrated in TBGL_InDialog templates - it will allow you resizing.
    If you are interested in fixed size window, why not use classic TBGL window then?

    Canvas_Window does some dark magic behind to be double buffered, I think it can clash with TBGL in some way. I would not recommend to try to make these two like each other


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    i thought it were nice and easy to use and if setting the refreshing of canvas to manual mode the canvas-backbuffer will never be flipped

    TBGL-Window does not have anything alike TBGL_BindWindow(hWnd) to use another output-surface and only TBGL_BindCanvas is available in that directions so i'm forced to use a canvas - else i'd like to avoid using the huge UI-module just for opening some additional windows too.
    Last edited by ReneMiner; 20-02-2015 at 09:20.
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Rene,

    the Canvas_Window is already part of UI module, so you include it anyway

    I tried to replicate the crash here, but no luck so far.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    it does not crash immediately - but after activating or often while moving/after moving one of the windows.

    Ain't there no way - no hack? - for TBGL to have multiple windows to render on?
    Can i open some plain windows in TB without using UI - some API-call perhaps? and tell tbgl to render on it?
    I think there are missing some Forum-sections as beta-testing and support

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Rene,

    of course it is possible. The only problem I have with this approach is how to share resources - models, textures... they are often context bound.
    I don't want to feed you with false promises, but I have something in mind in this area...


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    i think the context-binding mostly because of screen-resolution.
    Since it's windowed it means the same resolution as long the windows are displayed on the same device/desktop.

    Btw.
    What will happen if i had multiple displays with different resolutions and i move the full initialized TBGL_Window from one desktop to the other?
    Is that possible? Will it cause failure?
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. UI & TBGL -- active window
    By RobbeK in forum TBGL General
    Replies: 9
    Last Post: 16-11-2013, 16:37
  2. Q on dragging the mouse in a Canvas Window
    By dcromley in forum UI (User Interface)
    Replies: 2
    Last Post: 12-09-2010, 17:04
  3. TBGL window resizing demo
    By efly2020 in forum TBGL General
    Replies: 1
    Last Post: 03-04-2009, 08:13
  4. tbgl window to a given handle
    By kryton9 in forum TBGL General
    Replies: 2
    Last Post: 04-07-2007, 01:23
  5. TBGL window
    By Reinking in forum TBGL General
    Replies: 15
    Last Post: 16-01-2006, 19:02

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •