Hi Lydia,
I am happy it worked! I also recognize somebody can be confused by the amount of sample code, available on multiple places. The direction for future will be to have everything on one place, carefully labeled and divided to various interest areas (something like Bonus Pack sections of different areas).
Displaying frame rate is simple, you have multiple options:
- 1) As your example is rendered in dialog, you could simply print the info to some of the controls or dialog title
- 2) Use TT font rendered inside TBGL window
- 3) Use bitmap font rendered inside TBGL window ( hint -> you can create bitmap fonts easily using TBGL Font Creator )
Ad 1)
To set frameRate to control, you can do it like:
[code=thinbasic]
control set text hDlg, %control, format$(frameRate, "#.00") ' -- 2 decimals
[/code]
To set frameRate to dialog, you can do similar:
[code=thinbasic]
dialog set text hDlg, format$(frameRate, "#.00") ' -- 2 decimals
[/code]
Ad 2)
To use TT fonts inside TBGL, you do the following:
- build the font ( that means, create set of OpenGL compatible character primitives )
[code=thinbasic]
TBGL_BuildFont TBGL_FontHandle("Arial", 9)
[/code]
- print it at any 3D location
[code=thinbasic]
TBGL_PrintFont format$(frameRate, "#.00"), 0, 0, 0
[/code]
- you could also print it in "2D mode", but you have to set such a mode first using TBGL_RenderMatrix2D
Ad 3)
- you create the BMP file using mentioned font tool
- you load it
[code=thinbasic]
TBGL_LoadBmpFont "myFont.bmp"
[/code]
- you can print it on the screen later like:
[code=thinbasic]
TBGL_BeginPrintBMP
TBGL_PrintBMP "Information on frame rate:", 1, 1 ' -- Column = 1, Row = 1
TBGL_PrintBMP format$(frameRate, "#.00"), 1, 2 ' -- Column = 1, Row = 2
TBGL_EndPrintBMP
[/code]
So you can see the options are multiple each having its advantages. The control/dialog way is simple, but not very stylish and also little slower, TT font provides best quality and you can use it for both 2D and 3D positioned printing and latest BMP font allows you to position text like in console applications - using column/row.
To see example of #2 and #3, please have a look at:
SampleScripts/TBGL/TBGL_0220_Samples/4n4Fonts/TBGL022_MultipleFonts.tbasic.
It shows that you can use 4 TTF and 4 BMP different fonts at the same time ( dangerous mix ).
Regarding collision - TBGL provides some basic functions to be used for collision, but I am currently working on more comfortable system, providing bounding boxes and bouding spheres attachable to entities directly.
Still, if you need at least approximate collision now, you can try few interesting approaches:
- measure distance of 2 entities, and if it is too small consider it "collision"
- track "points of interest" on the entities using TBGL_EntityTrackPos and do the similar distance based test
I attach for you modified code showing how to print in 3D and how to do very elemental collision check.
If you are not in hurry, please wait for a while before I develop more advanced collision functions, it is already work in progress and it should save you some time coding.
Petr
P.S. Side note on frame rate. In your example, it won't be very high, because the display is pumped using timer.
This is approach I recommend - you let the PC breathe a bit. Of course, you can code tight loops in ThinBASIC to get maxximum out of the GPU and CPU performance too, when you need it.
Bookmarks