Programming and Graphics

(Kiana) #1

268 Introduction to C++ Programming and Graphics


8.1.3. Write aGlutfunction that displays a four-sided pyramid.

8.1.4. Write a code that displays a bicycle.

8.1.5. Write a code that displays two lines of text.

8.1.6. Write a code that generates a spectacular color display of your choice.

8.2 Graphicsevents............................


Once the main loop has been entered,Glutkeeps track of thex−yposition
of the cursor on the screen, the mouse buttons, and the keyboard keys. When
the window has been selectedand a key or a mouse button is pressed, an event
is registered.


Monitoring the keyboard


Consider the following slight variation of the teapot preamble and main
code:


#include<iostream>
#include<freeglut.h>
using namespace std;

void showme(void);
void quit(unsigned char, int, int);

int win;

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUTDEPTH|GLUTSINGLE|GLUTRGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(620,620);
win=glutCreateWindow("Teapot");
glutDisplayFunc(disp);
glutKeyboardFunc(quit);
glClearColor(0.2,0.5,0.2,0.2);
glutMainLoop();
return 0;
}

The integer “win” is the window identification number defined in the main code.
The user-defined functionquitreads:

Free download pdf