PDA

View Full Version : TBGL - 3 things



dcromley
17-02-2016, 20:55
(maybe I should have 3 separate posts?)

These are minor things -- maybe just my misunderstanding.

1) Placing the window in the screen Using TBGL_CreateWindowEx doesn't seem to work.
Using the MoveWindow API does work.

2) When using TBGL_RenderMatrix2D,
TBGL_Line uses the coordinates in the TBGL_RenderMatrix2D statement.
TBGL_PrintFont doesn't. Does it use screen coordinates?

3) Are parentheses ever necessary or prohibited? Recommended or not?
e.g. TBGL_UseLighting(%TRUE) or TBGL_UseLighting %TRUE

The script below is commented, showing the issues
Thanks for TB/TBGL!

Uses "TBGL"

Sub TBMain()
Dim hWnd, hFont As DWord, Framerate As Long
String s1 = "ESC to quit"
'-- I want the window to be upper-left in the screen - doesn't work.
hWnd = TBGL_CreateWindowEx(s1, 600, 600, 32,
%TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX, 0, 0)
hFont = TBGL_FontHandle("Courier New", 9)
TBGL_BuildFont(hFont)
TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 100, 100, 0, 1)
TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_DIFFUSE, 1, .5, .5, 1)
TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
TBGL_UseVSync(1)
TBGL_ShowWindow
While TBGL_IsWindow(hWnd)
Framerate = TBGL_GetFrameRate
TBGL_ClearFrame
'-- A Viewport
TBGL_Viewport( 40, 30, 400, 200, %TBGL_PARAM_PIXELS )
'-- I want to print stuff in 2D mode
'-- in the bottom-left corner of the viewport.
TBGL_RenderMatrix2D(0, 0, 400, 200) ' viewport coordinates
TBGL_UseLighting(%FALSE) ' for printing
TBGL_Line(10,10,390,190) ' the 2D line gets inside the viewport (good)
TBGL_PrintFont("Framerate=" & Framerate, 0, 0) ' but the print is outside
TBGL_PrintFont2D("X=100 Y=0", 100, 0)
'-- Printing in 3D mode works as expected.
TBGL_RenderMatrix3D(%TBGL_CUSTOM, 400/200)
TBGL_Camera(0, 0, 5, 0, 0, 0)
TBGL_UseLighting(%TRUE)
TBGL_Rect(-100, -100, -1, 100, 100, -1) ' the whole viewport
TBGL_Sphere(1)
TBGL_UseLighting(%FALSE) ' for printing
TBGL_PrintFont("X=0 Y=0 Z=2", 0, 0, 2) ' print in 3D -
TBGL_DrawFrame
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
End Sub

ReneMiner
17-02-2016, 21:31
hi dcromley,

for the upper-left-thing- i discovered same issue when passing a 0, 0
you should use 1,1 as a position, else (< 1) it's centered.

To move window you could use TBGL_SetWindowed()-function...

For RenderMatrix2d use TBGL_PrintFont2D to stay on the safe side.

The RenderMatrix2d- awaits parameters in another order then usually:

TBGL_RenderMatrix2D(Left, Bottom, Right, Top)


Parenthesis can be omitted if the function does not have optional parameters in most cases... try out...

dcromley
19-02-2016, 03:38
Rene,
Thank you for the response.
I see that 0,0 centers and 1,1 does indeed put it to the upper-left.

> To move window you could use TBGL_SetWindowed()-function...
I did not get this to work. I thought it would be

String s1 = "ESC to quit"
hWnd = TBGL_CreateWindowEx(s1, 600, 600, 32, %TBGL_WS_CLOSEBOX)
TBGL_SetWindowed( hWnd, 600, 600, 32, %TBGL_WS_CLOSEBOX, 1, 1)
But, as I said, the MoveWindow API does the deed.

> For RenderMatrix2d use TBGL_PrintFont2D to stay on the safe side.
I have the 2 statements, and neither get into the viewport:

TBGL_PrintFont("Framerate=" & Framerate, 0, 0)
TBGL_PrintFont2D("X=100 Y=0", 100, 0)
But it's not that hard to add the viewport offsets to the x and y.

> Parenthesis can be omitted if the function does not have optional parameters in most cases... try out...
I'm going with using ()s. If there's a problem, I'll be back. :)

Thanks again, Dave

ReneMiner
19-02-2016, 10:02
hi Dave,

please check line 23 of your script again.

Parameters for TBGL_RenderMatrix2d are to pass counter-clockwise starting left:

TBGL_RenderMatrix2D( leftX, bottomY, rightX, topY )

but not left, top, {width|right}, {height|bottom}


have fun, keep on coding
René

dcromley
19-02-2016, 18:47
Yes, I see that since the viewport width/height is 400/200 I should have had

TBGL_RenderMatrix2D(0, 0, 399, 199)
but the TBGL_LINE still uses the viewport coordinates and the PrintFont and PrintFont2D still use screen coordinates, not viewport coordinates? I wanted 0,0 to be bottom-left.

Changing to

TBGL_RenderMatrix2D(0, 199, 399, 0)
makes 0,0 the upper-left for the TBGL_LINE, but I still have to add the viewport offsets for the TBGL_PrintFont and TBGL_PrintFont2D to get into the viewport.

Sorry if I'm being dense here. Thanks again.