PDA

View Full Version : Canvas-Window- how to bind TBGL?



ReneMiner
19-02-2015, 15:24
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 :D


'...
DWord hCanvas = Canvas_Attach hWnd, 0, TRUE
Control Handle hWnd, hCanvas To hCanvas

TBGL_BindCanvas( hCanvas )
'...

ReneMiner
19-02-2015, 17:02
it crashes - not always - and i don't know why.
Mostly if moving one of the windows :tears:.



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

Petr Schreiber
19-02-2015, 20:25
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

ReneMiner
20-02-2015, 09:16
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.

Petr Schreiber
21-02-2015, 19:16
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

ReneMiner
21-02-2015, 21:49
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?

Petr Schreiber
22-02-2015, 11:01
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

ReneMiner
23-02-2015, 13:35
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?