Petr Schreiber
01-07-2007, 17:17
TBGL FAQ
Updated 19th of January, 2008
This is list of solutions for quite common problems, I have splitted it to following categories to make search easier:
Frame rate and performance related
Texture related
Model related
Garbage collection
If you think there is something missing please tell me :)
Frame rate and performance related
Q: How to measure performance of my app ?
A: You can use built in statement to check framerate. To do this, just fill variable ( name it for example "FrameRate" ) from function once per frame:
' ...
DIM FrameRate AS NUMBER
while TBGL_IsWindow( hWnd)
FrameRate = tbgl_GetFrameRate ' <-
tbgl_ClearFrame
' -- Some rendering code here
' ...
tbgl_DrawFrame
' ...
wend
Q: All my scripts run at 60FPS ( 75FPS ) and I cannot get higher even with very basic scenes
A: Check your drivers and turn V-Sync ( vertical synchronisation ) to OFF.
Q: All my scripts run at unbelieveable low speed, what can I do ?
A: Please check this post (http://community.thinbasic.com/index.php?topic=668.msg3885#msg3885), you have probably wrong drivers
Q: As I get different FPS on different PCs, scene movements are faster/slower depending on computer
A: It is good practise to keep all movements scaled to actual performance.
Create variable "FrameRate"
At beginning of frame add following line
FrameRate = tbgl_GetFrameRate
Scale all calculations relative to FrameRate, for example to move ship by 5 m/s just add:
Ship.X += 5/FrameRate
Q: There are many ways to create geometry in TBGL, which one to use to get maximum performance
A:
"immediate mode" - ( TBGL_BeginPoly / TBGL_EndPoly ) is best to get the idea, but also slowest one
"display lists" - for static geometry it is wise to cache using display lists ( see TBGL_NewList, TBGL_EndList, TBGL_CallList in help file )
"model buffers, display lists" - for best performance for dynamic meshes ( game charcters, monsters, water surfaces ) model buffers are the right solution right now. They are continuously optimized in each release of TBGL.
For static geometry you can use model buffer too and than cache it using display lists. tbgl_m15DrawModel produces highly optimized GPU code, and it will even improve in future.
Texture related
Q: My texture looks weird!
A: You probably try to use texture which is not power of two (POT) sided. To ensure maximum compatibility and performance use just POT textures.
They can be both square sided ( 64x64, 128x128, 256x256, ... ) or rectangular ( 64x32, 512x64, ... )
Q: I loaded TGA texture but polygon is still not textured right
A: Make sure TGA is 32bit one - 24bits for RGB and 8bits for alpha
Model related
Q: I want to render points via model buffers
A: Create model as usual, but set PSTOP flag only to last vertex.
Make sure to call following function to make model look like points before rendering it:
tbgl_PolygonLook %GL_POINT
Garbage collection
Q: Do I have to delete somehow display lists and textures from memory before my application ends ?
A: No, it is done automatically.
Hope this list can help to solve classic problems,
Petr Schreiber
Updated 19th of January, 2008
This is list of solutions for quite common problems, I have splitted it to following categories to make search easier:
Frame rate and performance related
Texture related
Model related
Garbage collection
If you think there is something missing please tell me :)
Frame rate and performance related
Q: How to measure performance of my app ?
A: You can use built in statement to check framerate. To do this, just fill variable ( name it for example "FrameRate" ) from function once per frame:
' ...
DIM FrameRate AS NUMBER
while TBGL_IsWindow( hWnd)
FrameRate = tbgl_GetFrameRate ' <-
tbgl_ClearFrame
' -- Some rendering code here
' ...
tbgl_DrawFrame
' ...
wend
Q: All my scripts run at 60FPS ( 75FPS ) and I cannot get higher even with very basic scenes
A: Check your drivers and turn V-Sync ( vertical synchronisation ) to OFF.
Q: All my scripts run at unbelieveable low speed, what can I do ?
A: Please check this post (http://community.thinbasic.com/index.php?topic=668.msg3885#msg3885), you have probably wrong drivers
Q: As I get different FPS on different PCs, scene movements are faster/slower depending on computer
A: It is good practise to keep all movements scaled to actual performance.
Create variable "FrameRate"
At beginning of frame add following line
FrameRate = tbgl_GetFrameRate
Scale all calculations relative to FrameRate, for example to move ship by 5 m/s just add:
Ship.X += 5/FrameRate
Q: There are many ways to create geometry in TBGL, which one to use to get maximum performance
A:
"immediate mode" - ( TBGL_BeginPoly / TBGL_EndPoly ) is best to get the idea, but also slowest one
"display lists" - for static geometry it is wise to cache using display lists ( see TBGL_NewList, TBGL_EndList, TBGL_CallList in help file )
"model buffers, display lists" - for best performance for dynamic meshes ( game charcters, monsters, water surfaces ) model buffers are the right solution right now. They are continuously optimized in each release of TBGL.
For static geometry you can use model buffer too and than cache it using display lists. tbgl_m15DrawModel produces highly optimized GPU code, and it will even improve in future.
Texture related
Q: My texture looks weird!
A: You probably try to use texture which is not power of two (POT) sided. To ensure maximum compatibility and performance use just POT textures.
They can be both square sided ( 64x64, 128x128, 256x256, ... ) or rectangular ( 64x32, 512x64, ... )
Q: I loaded TGA texture but polygon is still not textured right
A: Make sure TGA is 32bit one - 24bits for RGB and 8bits for alpha
Model related
Q: I want to render points via model buffers
A: Create model as usual, but set PSTOP flag only to last vertex.
Make sure to call following function to make model look like points before rendering it:
tbgl_PolygonLook %GL_POINT
Garbage collection
Q: Do I have to delete somehow display lists and textures from memory before my application ends ?
A: No, it is done automatically.
Hope this list can help to solve classic problems,
Petr Schreiber