primo
20-12-2019, 15:07
i want to compare the FrameRate in example Uses only "TBGL" with
hWnd = TBGL_CreateWindowEx
and another same example but Uses "UI", "TBGL" with the graphics displayed on a Label, and have a button
the first example i got from official GBuffers_SimpleTriangle.tbasic
the second i adapted it from an example in the forum https://www.thinbasic.com/community/showthread.php?12412-Lorenz-4D-Lists&highlight=lorenz
it happened the first example result is about 60 fps _excellent
the second example result is about 30 fps even it is only a one triangle.
unless otherwise it seems a general phenomena in the windowed demos which have controls to have less FrameRates.
'
' Simple example of rendering colorful triangle with GBuffers
' Petr Schreiber, 2010
'
Uses "TBGL"
Function TBMAIN()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("GBuffers with triangles - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255
' -- Create 3D triangle buffer
Dim gbTriangle As DWord = TBGL_GBufferCreate(%TBGL_Triangles, %TBGL_3D)
' -- Define data for it
Dim VertexA(3) As TBGL_tVector3F
Dim ColorA(3) As TBGL_tRGB
' -- Vertices
VertexA(1).x = -1
VertexA(1).y = -1
VertexA(1).z = 0
VertexA(2).x = 1
VertexA(2).y = -1
VertexA(2).z = 0
VertexA(3).x = 0
VertexA(3).y = 1
VertexA(3).z = 0
' -- Colors
ColorA(1).r = 255
ColorA(1).g = 0
ColorA(1).b = 0
ColorA(2).r = 0
ColorA(2).g = 255
ColorA(2).b = 0
ColorA(3).r = 0
ColorA(3).g = 0
ColorA(3).b = 255
' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbTriangle, %TBGL_Dynamic, 3, VertexA(1), ColorA(1))
' -- Resets status of all keys
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle(hWnd, FrameRate)
TBGL_ClearFrame
TBGL_Camera(0, 0, 5, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/30, 0, 1, 0
' -- Render it
tbgl_GBufferRender(gbTriangle)
' -- Modify the colors
'ColorA(1).r = 128+Sin(GetTickCount/100)*127
'ColorA(2).g = 128+Sin(GetTickCount/100+1)*127
'ColorA(3).b = 128+Sin(GetTickCount/100+2)*127
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it
' -- Destroy window
TBGL_DestroyWindow
End Function
example 2: opengl rendered with a Label
Uses "UI", "TBGL"
#Include "%app_includepath%\thinbasic_gl.inc"
#Include "%app_includepath%\thinbasic_glu.inc"
TBGL_BackColor 255,255,255
' -- Create 3D triangle buffer
Global gbTriangle As DWord = TBGL_GBufferCreate(%TBGL_TRIANGLES, %TBGL_3D)
' -- Define data for it
Global VertexA(3) As TBGL_TVECTOR3F
Global ColorA(3) As TBGL_TRGB
' -- Vertices
VertexA(1).x = -1
VertexA(1).y = -1
VertexA(1).z = 0
VertexA(2).x = 1
VertexA(2).y = -1
VertexA(2).z = 0
VertexA(3).x = 0
VertexA(3).y = 1
VertexA(3).z = 0
' -- Colors
ColorA(1).r = 255
ColorA(1).g = 0
ColorA(1).b = 0
ColorA(2).r = 0
ColorA(2).g = 255
ColorA(2).b = 0
ColorA(3).r = 0
ColorA(3).g = 0
ColorA(3).b = 255
' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbTriangle, %TBGL_DYNAMIC, 3, VertexA(1), ColorA(1))
' -- ID numbers of controls
Begin ControlID
%lCanvas
%bClose
%myTimer
End ControlID
Begin Const
%MAIN_WIDTH = 640
%MAIN_HEIGHT = 480
%timeOut = 20 ' -- Determines graphics refresh rate in milliseconds
End Const
Function TBMain()
Global hDlg As DWord
Global sheep As Long
Dialog New Pixels, 0, "Use arrow keys - Pg U/D - LORENZ PEARLS",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or %WS_THICKFRAME, 0 To hDlg
' -- Place controls here
Control Add Label, hDlg, %lCanvas, "", 5, 5, %MAIN_WIDTH-10, %MAIN_HEIGHT-40
Control Set Color hDlg, %lCanvas, %BLACK, %BLACK
Control Set Resize hDlg, %lCanvas, 1, 1, 1, 1
Control Add Button, hDlg, %bClose, "Close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25
Control Set Resize hDlg, %bClose, 0, 1, 0, 1
Dialog Set Minsize hDlg, 320, 230
Dialog Show Modal hDlg, Call dlgCallback
End Function
CallBack Function dlgCallback()
Static hCtrl As DWord
Select Case CBMSG
Case %WM_INITDIALOG
'Dialog Set Timer CBHNDL, %myTimer, %timeOut, %NULL
'Control Handle CBHNDL, %lCanvas To hCtrl
Dialog Set Timer CBHNDL, %myTimer, %timeOut, %NULL
Control Handle CBHNDL, %lCanvas To hCtrl
' -- Init OpenGL
TBGL_BindCanvas(hCtrl)
Case %WM_SIZE, %WM_SIZING
'TBGL_UpdateCanvasProportions(hCtrl)
'RenderMyImage(hCtrl)
Case %WM_TIMER
RenderMyImage(hCtrl)
Case %WM_CLOSE
TBGL_ReleaseCanvas(hCtrl)
Dialog Kill Timer CBHNDL, %myTimer
Case %WM_COMMAND
Select Case CBCTL
Case %bClose
If CBCTLMSG = %BN_CLICKED Then Dialog End CBHNDL
End Select
End Select
End Function
Function RenderMyImage( hCtrl As DWord )
Static FrameRate As Double
TBGL_BackColor 255,255,255
If TBGL_CanvasBound(hCtrl) Then
TBGL_ClearFrame
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle(hDlg, FrameRate)
TBGL_ClearFrame
TBGL_Camera(0, 0, 5, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/30, 0, 1, 0
' -- Render it
TBGL_GBufferRender(gbTriangle)
TBGL_DrawFrame
' -- ESCAPE key to exit application
'If TBGL_GetWindowKeyState(hDlg, %VK_ESCAPE) Then Exit While
TBGL_DrawFrame
End If
End Function
hWnd = TBGL_CreateWindowEx
and another same example but Uses "UI", "TBGL" with the graphics displayed on a Label, and have a button
the first example i got from official GBuffers_SimpleTriangle.tbasic
the second i adapted it from an example in the forum https://www.thinbasic.com/community/showthread.php?12412-Lorenz-4D-Lists&highlight=lorenz
it happened the first example result is about 60 fps _excellent
the second example result is about 30 fps even it is only a one triangle.
unless otherwise it seems a general phenomena in the windowed demos which have controls to have less FrameRates.
'
' Simple example of rendering colorful triangle with GBuffers
' Petr Schreiber, 2010
'
Uses "TBGL"
Function TBMAIN()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("GBuffers with triangles - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255
' -- Create 3D triangle buffer
Dim gbTriangle As DWord = TBGL_GBufferCreate(%TBGL_Triangles, %TBGL_3D)
' -- Define data for it
Dim VertexA(3) As TBGL_tVector3F
Dim ColorA(3) As TBGL_tRGB
' -- Vertices
VertexA(1).x = -1
VertexA(1).y = -1
VertexA(1).z = 0
VertexA(2).x = 1
VertexA(2).y = -1
VertexA(2).z = 0
VertexA(3).x = 0
VertexA(3).y = 1
VertexA(3).z = 0
' -- Colors
ColorA(1).r = 255
ColorA(1).g = 0
ColorA(1).b = 0
ColorA(2).r = 0
ColorA(2).g = 255
ColorA(2).b = 0
ColorA(3).r = 0
ColorA(3).g = 0
ColorA(3).b = 255
' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbTriangle, %TBGL_Dynamic, 3, VertexA(1), ColorA(1))
' -- Resets status of all keys
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle(hWnd, FrameRate)
TBGL_ClearFrame
TBGL_Camera(0, 0, 5, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/30, 0, 1, 0
' -- Render it
tbgl_GBufferRender(gbTriangle)
' -- Modify the colors
'ColorA(1).r = 128+Sin(GetTickCount/100)*127
'ColorA(2).g = 128+Sin(GetTickCount/100+1)*127
'ColorA(3).b = 128+Sin(GetTickCount/100+2)*127
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it
' -- Destroy window
TBGL_DestroyWindow
End Function
example 2: opengl rendered with a Label
Uses "UI", "TBGL"
#Include "%app_includepath%\thinbasic_gl.inc"
#Include "%app_includepath%\thinbasic_glu.inc"
TBGL_BackColor 255,255,255
' -- Create 3D triangle buffer
Global gbTriangle As DWord = TBGL_GBufferCreate(%TBGL_TRIANGLES, %TBGL_3D)
' -- Define data for it
Global VertexA(3) As TBGL_TVECTOR3F
Global ColorA(3) As TBGL_TRGB
' -- Vertices
VertexA(1).x = -1
VertexA(1).y = -1
VertexA(1).z = 0
VertexA(2).x = 1
VertexA(2).y = -1
VertexA(2).z = 0
VertexA(3).x = 0
VertexA(3).y = 1
VertexA(3).z = 0
' -- Colors
ColorA(1).r = 255
ColorA(1).g = 0
ColorA(1).b = 0
ColorA(2).r = 0
ColorA(2).g = 255
ColorA(2).b = 0
ColorA(3).r = 0
ColorA(3).g = 0
ColorA(3).b = 255
' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbTriangle, %TBGL_DYNAMIC, 3, VertexA(1), ColorA(1))
' -- ID numbers of controls
Begin ControlID
%lCanvas
%bClose
%myTimer
End ControlID
Begin Const
%MAIN_WIDTH = 640
%MAIN_HEIGHT = 480
%timeOut = 20 ' -- Determines graphics refresh rate in milliseconds
End Const
Function TBMain()
Global hDlg As DWord
Global sheep As Long
Dialog New Pixels, 0, "Use arrow keys - Pg U/D - LORENZ PEARLS",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or %WS_THICKFRAME, 0 To hDlg
' -- Place controls here
Control Add Label, hDlg, %lCanvas, "", 5, 5, %MAIN_WIDTH-10, %MAIN_HEIGHT-40
Control Set Color hDlg, %lCanvas, %BLACK, %BLACK
Control Set Resize hDlg, %lCanvas, 1, 1, 1, 1
Control Add Button, hDlg, %bClose, "Close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25
Control Set Resize hDlg, %bClose, 0, 1, 0, 1
Dialog Set Minsize hDlg, 320, 230
Dialog Show Modal hDlg, Call dlgCallback
End Function
CallBack Function dlgCallback()
Static hCtrl As DWord
Select Case CBMSG
Case %WM_INITDIALOG
'Dialog Set Timer CBHNDL, %myTimer, %timeOut, %NULL
'Control Handle CBHNDL, %lCanvas To hCtrl
Dialog Set Timer CBHNDL, %myTimer, %timeOut, %NULL
Control Handle CBHNDL, %lCanvas To hCtrl
' -- Init OpenGL
TBGL_BindCanvas(hCtrl)
Case %WM_SIZE, %WM_SIZING
'TBGL_UpdateCanvasProportions(hCtrl)
'RenderMyImage(hCtrl)
Case %WM_TIMER
RenderMyImage(hCtrl)
Case %WM_CLOSE
TBGL_ReleaseCanvas(hCtrl)
Dialog Kill Timer CBHNDL, %myTimer
Case %WM_COMMAND
Select Case CBCTL
Case %bClose
If CBCTLMSG = %BN_CLICKED Then Dialog End CBHNDL
End Select
End Select
End Function
Function RenderMyImage( hCtrl As DWord )
Static FrameRate As Double
TBGL_BackColor 255,255,255
If TBGL_CanvasBound(hCtrl) Then
TBGL_ClearFrame
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle(hDlg, FrameRate)
TBGL_ClearFrame
TBGL_Camera(0, 0, 5, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/30, 0, 1, 0
' -- Render it
TBGL_GBufferRender(gbTriangle)
TBGL_DrawFrame
' -- ESCAPE key to exit application
'If TBGL_GetWindowKeyState(hDlg, %VK_ESCAPE) Then Exit While
TBGL_DrawFrame
End If
End Function