Programming and Graphics

(Kiana) #1

272 Introduction to C++ Programming and Graphics


#include <freeglut.h>
using namespace std;

void blank();
void print(int);
int delay=100; // in milliseconds

//--- main:

int main(int argc, char **argv)
{
int code=-1;
glutInit(&argc, argv);
glutInitDisplayMode(GLUTDEPTH | GLUTRGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("ASCII");
glOrtho(0, 100, 0, 100, 0, 100);
glClearColor(0.5,0.0,0.8,1.0);
glutDisplayFunc(blank);
glutTimerFunc(delay, print, code);
glutMainLoop();
return 0;
}

//--- Print:

void print (int code)
{
glClear(GLCOLORBUFFERBIT);
char a = code++;
glRasterPos2i(50, 50);
glutBitmapCharacter(GLUTBITMAP 8 BY13, a);
glFlush();
glutTimerFunc(delay, print, code);
delay=delay+1;
}

//--- Blank screen:

void blank()
{
glClear(GLCOLORBUFFERBIT);
}

Note that theglutTimerFuncfunction calls the user-defined functionprint,
which in turn callsglutTimerFuncin an infinite loop. In this case,printalso
changes the delay.

Free download pdf