Lesson 3: Cube Font
Using the code given in the last tutorial, it is easy to create a cube font. We have altered the code to display letters, but used the same principle.
Again, we have defined a matrix A of MxN but this time we have increased its with to fit in all the letters.
1
2
3
4
5
6
7
8
9
10
11
|
int maze[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,0,1,0,0,0,0,0,1,1,1,1,0,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,1,1,1,1,0,1,1,1,1,0,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,0,
0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
|
If you look very clearly, you’ll see that the letters Open are formed upside down. Of course, one could fill the matrix using a text file, but we kept it as simple as possible to implement. Finally we have used this loop to draw the matrix:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
int yc = 0;
int xc = 0;
for (yc = 0; yc 10; yc++)
{
for (xc = 0; xc 24; xc++)
{
if (maze[ xc + yc*24 ] == 1)
{
glPushMatrix();
glTranslatef( xc*2.0f, yc*2.0f, -0.0f );
drawCube();
glPopMatrix();
}
}
}
|