Programming and Graphics

(Kiana) #1

8.1 Glut 265


The graphics display is shown in Figure 8.1.2(a). In this code, we have intro-
duced theglRasterPos2ifunction to move the pen to a specified position, and
theglutBitmapCharacterfunction to draw a character on the screen using a
specified font.


The following function also contained in the filetheend.ccprints a char-
acter array using a different method:


void write1()
{
glClear(GLCOLORBUFFERBIT);
char * ps = "The End";
int x = 35, y=50;

while(*ps)
{
glRasterPos2i(x,y);
glutBitmapCharacter(GLUTBITMAP 8 BY13,*ps);
x=x+4;
ps = ps+1;
}

glFlush();
}

The graphics display is shown in Figure 8.1.2(b). In the second method, the
individual characters of the array are identified by the pointerpswhose value is
sequentially increased by one unit until the end of the array has been reached.


Available fonts include the following:


GLUT_BITMAP_8_BY_13
GLUT_BITMAP_9_BY_15
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12
GLUT_BITMAP_HELVETICA_18
GLUT_BITMAP_TIMES_ROMAN_10
GLUT_BITMAP_HELVETICA_18
GLUT_BITMAP_TIMES_ROMAN_24

Spectacular designs


OpenGL allows us to manipulate the color with spectacular results seen
in professional designs. The following function generates the design shown in
Figure 8.1.3:


void spectacular()
{
Free download pdf