| Lesson #2
In this lesson you will learn how to bind color to vertexes and how to change background color
It's good to have read lesson 1, because this one is based on its code, and introduces just few modifications.
The following code samples are just parts of all program, which can be downloaded from the end of the page
If you are disappointed by the just black and white output of the lesson 1, here you will see splash of colors.
The black background of the scene could be sometimes inconvenient. What about making it ... dark blue ? It's quite straightforward.
Just use this:
Using this function with color coded in RGB as parameter will cause change of the default color of the background.
Well, TBGL module allows you to assign unique color to the each vertex too. For this you can use tbgl_Color function. It takes 3 parameters in range 0 - 255. In other words, just RGB again.
This simple code will produce triangle with red, green and blue vertices. The colors will melt each other, so it will look really nice.
But to add some juice to the scene, let's make it more dynamic ! What about pulsing colors?
SIN function is well known periodical function, which can return value from -1 to 1.
TIMER function returns numbers of seconds, which elapsed since midnight, so it changes.
Now the triangle vertexes will almost independently "glow".
To test it just download this source code: Lesson 2 source code
It should produce this image
© Petr Schreiber, 2006