|
thinBASIC TBGL Website
by Petr Schreiber |
|||||
| Home | Tutorials | Articles | Tools | Links | About |
| - Visit forum - | |||||
Welcome adventurer! I can see you can't wait to start with thinBASIC TBGL programming in honest way - from total basics...
This lesson covers the really important and basic things about TBGL, and if you'll be attentive enough, you'll manage to create your first triangle today!
So watch carefully, here we go!
TBGL principles
TBGL is module for easy 3D graphics creation using thinBASIC interpreter. To provide balance between syntax clarity and enough raw performance, I decided to build TBGL on top of OpenGL.
From this you can see your sripts will run best with some 3D card, as OpenGL is hardware accelerated API. If your target PC does not have hardware support of it, you will be able to use all TBGL functionalities, but at desperate speed.
TBGL is build on relatively old version of OpenGL. This assures you will be able to run scripts without graphical quality impact on almost any 3D card. I can recommend nVidia GeForce 2 MX 400 or ATi Radeon 7000 accelerators as lowest reasonable hardware in terms of capabilities and speed.
But using this module you will get more than "just" OpenGL, you will have access to some useful stuff, not present in classical OpenGL.
You must not care about allocating and deleting of textures and display lists, loading and handling of models and other things.
Hmm, I think this is enough said about mega-hyper-super TBGL, I can see in your eyes you are hungry for some code! So here it is -
First TBGL application
To not make things last longer than necessary, here is something which I could call "minimal" TBGL app:
'
' TBGL Script Skeleton
'
USES "TBGL"
DIM hWnd AS DWORD
hWnd = TBGL_CREATEWINDOWEX("My Demo - press ESC to quit", 640, 480, 32, 0)
TBGL_SHOWWINDOW
TBGL_GETASYNCKEYSTATE(-1) ' Resets key status before checking it
WHILE TBGL_IsWindow(hWnd)
TBGL_CLEARFRAME
TBGL_DRAWFRAME
IF TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) THEN EXIT WHILE
WEND
TBGL_DESTROYWINDOW
TBGL_BACKCOLOR 0, 128, 0Now run the script!

You should see this
WHILE TBGL_IsWindow(hWnd)
TBGL_CLEARFRAME
TBGL_CAMERA 0, 0, 5, 0, 0, 0
TBGL_BEGINPOLY %GL_TRIANGLES
TBGL_COLOR 255, 0, 0
TBGL_VERTEX -2, -1, 0
TBGL_COLOR 0, 255, 0
TBGL_VERTEX 2, -1, 0
TBGL_COLOR 0, 0, 255
TBGL_VERTEX 0, 1, 0
TBGL_ENDPOLY
TBGL_DRAWFRAME
IF TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) THEN EXIT WHILE
WEND
Lot of new stuff, huh? Don't worry, I will explain it immediately.
TBGL_CAMERA 0, 0, 5, 0, 0, 0As you can see, in camera statement there are 6 numbers - first 3 are x,y,z you are looking from ( 0, 0, 5 )and second set of 3 numbers is location you look at ( 0, 0, 0 ).
TBGL_BEGINPOLY %GL_TRIANGLES
' First
TBGL_COLOR 255, 0, 0
TBGL_VERTEX -2, -1, 0
TBGL_COLOR 0, 255, 0
TBGL_VERTEX 2, -1, 0
TBGL_COLOR 0, 0, 255
TBGL_VERTEX 0, 1, 0
' Second
TBGL_COLOR 255, 0, 0
TBGL_VERTEX -2, -1, -1
TBGL_COLOR 0, 255, 0
TBGL_VERTEX 2, -1, -1
TBGL_COLOR 0, 0, 255
TBGL_VERTEX 0, 1, -1
TBGL_ENDPOLY

Look from 5,5,5 to origin
TBGL_CAMERA 5, 5, 5, 0, 0, 0
Now it is all right, second triangle is behind the first.
| © Petr Schreiber 2008 |