Can you make a simple example and post it here?
thanks
Mike C.
Hi guys, it's me again. Have some problem as usual:
I tried both types of fonts (TT + bmp/tga) already, but it does not work as expected:
If I use TT, the Strings get transformed to world-space and stay black and won't accept any TBGL_Color. I would like to use the same font in different colors, so it would be enough to use just one
If I use Bmp/tga, they are also really dark, unreadable, even if I use a plain white one its deep-dark-gray. Also I would need one font for each color...
And I don't get the parameters ordered the right way,
I want string1 to be flat on front of screen in the lower-left corner
string 2,3 and 4 are supposed to be aligned on top rim of screen
string1 at 0.25, string2 at 0.5 and string3 at 0.75 of clientWidth, all text-centered- so center of String meets these positions
what do I have to set up to get a readable some font on screen surface (not transformed into world-space) with desired color?
and how can I make them transformed ones (TT) accept the color?
when do I have to draw them? before or after rendering scene?
I think there are missing some Forum-sections as beta-testing and support
Can you make a simple example and post it here?
thanks
Mike C.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
I don't know how simple...
I load same font as described in TBGL_MultipleFonts.tBasic-example. When I insert there inbetween
TBGL_SetActiveFont 1
TBGL_Color 255,255,0
TBGL_PrintFont... it prints actually yellow.
if I put this font into my (entity-based) code it's just black, transformed to scene-space coordinates. But black is my background...
and I want not just font transformed into my world, I want some colored text that lays flat in front as you see in the little picture that I drew to explain this. It's not an actual screenshot.
string1,2,3 on top of the window, but text shall be centered at 25%, 50% and 75% of screen-width. So I need to figure out TextWidth in pixel somehow
string4 should be some text that might be just one letter or even over the whole width
as you see, String5 is what I have. Black letters transformed into black world-space...
Edit: I've found out, that I have to set TBGL_UseLighting False when drawing fonts.
Now, can I get them somehow to be drawn plain 2D onto the screen?
Last edited by ReneMiner; 29-10-2012 at 21:01.
I think there are missing some Forum-sections as beta-testing and support
Hi Rene,
yes, the light is the cause of such a behavior.
You can do fonts in pure 2D form, you just need to setup 2D rendering using TBGL_RenderMatrix2D, here little example:
#MINVERSION 1.9.1.0 Uses "TBGL" Begin Const ' -- Scene IDs %sScene = 1 ' -- Entity IDs %eCamera = 1 %eLight %eBox End Const Function TBMain() Local hWnd As DWord Local FrameRate As Double ' -- Create and show window hWnd = TBGL_CreateWindowEx("TT Fonts in 2D - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) TBGL_ShowWindow ' -- Create scene TBGL_SceneCreate(%sScene) ' -- Create basic entities ' -- Create camera to look from 15, 15, 15 to 0, 0, 0 TBGL_EntityCreateCamera(%sScene, %eCamera) TBGL_EntitySetPos(%sScene, %eCamera, 15, 15, 15) TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0) ' -- Create point light TBGL_EntityCreateLight(%sScene, %eLight) TBGL_EntitySetPos(%sScene, %eLight, 15, 10, 5) ' -- Create something to look at TBGL_EntityCreateBox(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 128, 0) TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0) DWord hFont = TBGL_FontHandle("Arial Black", 14, %TBGL_ITALICS) TBGL_BuildFont(hFont) ' -- Resets status of all keys TBGL_ResetKeyState() ' -- Main loop While TBGL_IsWindow(hWnd) FrameRate = TBGL_GetFrameRate TBGL_ClearFrame TBGL_RenderMatrix3D TBGL_SceneRender(%sScene) TBGL_RenderMatrix2D ' -- With math like coordinates (0,0 in bottom left) TBGL_PushStateProtect %TBGL_LIGHTING TBGL_PushColor 255, 0, 0 TBGL_PrintFont "Ciao", 20, 20 TBGL_PopColor TBGL_PopStateProtect TBGL_RenderMatrix2D(0, 480, 640, 0) ' -- With windows like coordinate (0,0 in top left) TBGL_PushStateProtect %TBGL_LIGHTING TBGL_PushColor 0, 255, 0 TBGL_PrintFont "Ciao", 20, 20 TBGL_PopColor TBGL_PopStateProtect TBGL_DrawFrame ' -- ESCAPE key to exit application If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then TBGL_EntityTurn(%sScene, %eBox, 0,-90/FrameRate, 0) ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then TBGL_EntityTurn(%sScene, %eBox, 0, 90/FrameRate, 0) End If Wend TBGL_DestroyWindow End Function
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
Here example with anchors and bmp font:
#MINVERSION 1.9.1.0 Uses "TBGL" Begin Const ' -- Scene IDs %sScene = 1 ' -- Entity IDs %eCamera = 1 %eLight %eBox End Const Function TBMain() Local hWnd As DWord Local FrameRate As Double ' -- Create and show window hWnd = TBGL_CreateWindowEx("BMP Fonts in 2D, with anchors - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) TBGL_ShowWindow ' -- Create scene TBGL_SceneCreate(%sScene) ' -- Create basic entities ' -- Create camera to look from 15, 15, 15 to 0, 0, 0 TBGL_EntityCreateCamera(%sScene, %eCamera) TBGL_EntitySetPos(%sScene, %eCamera, 15, 15, 15) TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0) ' -- Create point light TBGL_EntityCreateLight(%sScene, %eLight) TBGL_EntitySetPos(%sScene, %eLight, 15, 10, 5) ' -- Create something to look at TBGL_EntityCreateBox(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 128, 0) TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0) TBGL_LoadBMPFont2D APP_Path+"SampleScripts\TBGL\Fonts\Textures\FONT_GRAYORANGE.bmp" ' -- Resets status of all keys TBGL_ResetKeyState() ' -- Main loop While TBGL_IsWindow(hWnd) FrameRate = TBGL_GetFrameRate TBGL_ClearFrame TBGL_RenderMatrix3D TBGL_SceneRender(%sScene) TBGL_RenderMatrix2D TBGL_PushState %TBGL_BLEND TBGL_PushStateProtect %TBGL_LIGHTING TBGL_PushColor 255, 255, 255 TBGL_BeginPrintBMP TBGL_PrintBMP "Left, up", 0, 0, %TBGL_ALIGN_LEFT_UP TBGL_PrintBMP "Left, center", 0, 0, %TBGL_ALIGN_LEFT_CENTER TBGL_PrintBMP "Left, down", 0, 0, %TBGL_ALIGN_LEFT_DOWN TBGL_PrintBMP "Center, up", 0, 0, %TBGL_ALIGN_CENTER_UP TBGL_PrintBMP "Center, center", 0, 0, %TBGL_ALIGN_CENTER_CENTER TBGL_PrintBMP "Center, down", 0, 0, %TBGL_ALIGN_CENTER_DOWN TBGL_PrintBMP "Right, up", 0, 0, %TBGL_ALIGN_RIGHT_UP TBGL_PrintBMP "Right, center", 0, 0, %TBGL_ALIGN_RIGHT_CENTER TBGL_PrintBMP "Right, down", 0, 0, %TBGL_ALIGN_RIGHT_DOWN TBGL_EndPrintBMP TBGL_PopColor TBGL_PopStateProtect TBGL_PopState TBGL_DrawFrame ' -- ESCAPE key to exit application If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then TBGL_EntityTurn(%sScene, %eBox, 0,-90/FrameRate, 0) ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then TBGL_EntityTurn(%sScene, %eBox, 0, 90/FrameRate, 0) End If Wend TBGL_DestroyWindow End Function
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
Thanks, you are my hero
Can I found out somehow the width of the string in Pixels ?
Last edited by ReneMiner; 29-10-2012 at 21:49.
I think there are missing some Forum-sections as beta-testing and support
Hi Rene,
the TBGL_GetFontTextSize should do it for you.
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
Bookmarks