PDA

View Full Version : Cool and Clean, safe to use?



kryton9
04-05-2017, 21:20
I was experimenting today and tried out the templates in thinAir when creating a new project. Really nice job Eros and Petr on those templates!

After awhile, I used the tbgl skeleton template and started changing, well seeing what I could get away with. This runs fine and bundles fine too to an exe file.
Is it safe to code in this style these days even though it works fine in latest thinBasic?


Uses "TBGL"

' Create and show window
DWord hWnd = TBGL_CreateWindowEx "TBGL script - press ESC to quit", 640, 480, 32,
%TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX
TBGL_ShowWindow

' Initialize lighting
TBGL_UseLighting %TRUE
TBGL_UseLightSource %GL_LIGHT0, %TRUE

TBGL_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1

' Resets status of all keys
TBGL_ResetKeyState

' Main loop
While TBGL_IsWindow hWnd
TBGL_ClearFrame
TBGL_Camera 15, 15, 15, 0, 0, 0

TBGL_Color 255, 128, 0
TBGL_Box 1, 1, 1

TBGL_DrawFrame
' ESCAPE key to exit application
If TBGL_GetWindowKeyState hWnd, %VK_ESCAPE Then Exit While
Wend

TBGL_DestroyWindow

Petr Schreiber
04-05-2017, 23:27
Yep! Perfectly valid.

Regarding those states, hmm... I tend to use the push/pop style, as it is more maintainable.
You can read about the concept here: State-safe-TBGL-programming (http://www.thinbasic.com/community/content.php?37-State-safe-TBGL-programming).

Also - for building scene in more structured way, I kind of like the Scene based syntax maybe a bit more, as demonstrated by TBGL_EntitySkeleton template.

Plus... maybe I would wrap the code in function TBMain().

Templates are another part of thinBASIC which could be maintained at gitHub, so we could keep them fresh better :)


Petr

kryton9
04-05-2017, 23:43
Thanks Petr, will check out the template you recommended next.

kryton9
05-05-2017, 14:01
I really love how nicely thinBasic bundle to an executable works. I am happy to report that my small test bundled to 410K.

For comparison using Processing and doing a similar bundle export without Java embedded comes out to over 4MB

With Java embedded, which would be a fairer comparison to thinBasic bundle, it was near 67MB!