| Lesson #1
Initializing TBGL window, displaying triangle
In this lesson you will learn the basics of setup of TBGL OpenGL window, and you will make your first polygon !
Lessons on this site are based on the idea of commented source code.
You can obtain the complete source by downloading it from the bottom of the article.
So get ready, here comes TBGL coding...
As you can see, every TBGL source code should start with the definition of the used libraries.
The TBGL library provides the 3D functions, UI is module for handling user interface. We will need it to manage the TBGL window
Here we display informative message before the show starts :)
the tbgl_CreateWindow functions initializes all necessary for work with OpenGL, tbgl_ShowWindow just displays it
This is the most important piece of code.
We will use ESCAPE key to exit program, so we must reset its status before checking it using GetAsyncKeyState(%VK_ESCAPE)
Then begins the main 3D code loop.
tbgl_ClearFrame must be used on every start of the painting of scene
tbgl_Camera function is important function, which says to the TBGL, that we want to look from one place in 3D to another. In this case we will look from 0, 0, 5 to the origin of the coordenates.
tbgl_BeginPoly and tbgl_EndPoly are something like "parenthesis" for declaring polygon. In this case we are using %GL_TRIANGLES polygon style. So we will need 3 vertexes to create one triangle.
Vertexes are defined using the tbgl_Vertex
The last line in the loop tests, if ESCAPE is pressed. If yes, it will exit the loop and then ...
... destroy the window and end the application.
Congratulations, you have passed the first lesson. I hope you have at least some idea how it works :)
To test it just download this source code: Lesson 1 source code
It should produce this image
© Petr Schreiber, 2006