#include <GL/glut.
h> // include GLUT library
#include <iostream>
#include <string>
using namespace std;
//********* Prototypes
**************************************************************
void myInit();
void myDisplayCallback();
void drawPoints();
void xMenuCallback(int entryId);
void yMenuCallback(int entryId);
void zMenuCallback(int entryId);
void parentMenuCallback(int entryId);
//********* Subroutines
*************************************************************
int main(int argc, char** argv)
{
glutInit(&argc, argv); // initialization
glutInitWindowSize(600, 600); // specify a window size
glutInitWindowPosition(300, 300); // specify a window position
glutCreateWindow("3D Transformation"); // create a titled window
myInit(); // specify some
settings
int xMenu = glutCreateMenu(xMenuCallback);
glutAddMenuEntry("Positive by 45 degrees", 1);
glutAddMenuEntry("Negative by 45 degrees", 2);
int yMenu = glutCreateMenu(yMenuCallback);
glutAddMenuEntry("Positive by 45 degrees", 1);
glutAddMenuEntry("Negative by 45 degrees", 2);
int zMenu = glutCreateMenu(zMenuCallback);
glutAddMenuEntry("Positive by 45 degrees", 1);
glutAddMenuEntry("Negative by 45 degrees", 2);
glutCreateMenu(parentMenuCallback);
glutAddSubMenu("Rotate around X-axes", xMenu);
glutAddSubMenu("Rotate around Y-axes", yMenu);
glutAddSubMenu("Rotate around Z-axes", zMenu);
glutAddMenuEntry("Reset to initial position", 1);
glutAddMenuEntry("Exit", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(myDisplayCallback); // register a callback
glutMainLoop(); // get into an infinite
loop
return 1; // something wrong
happened
}
//
***********************************************************************************
void drawPoints()
{
glColor3f(0, 0, 0); // change drawing color to black
glPointSize(1); // change point size to 1
glRasterPos3f(5, 240, 0);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'Y'); // 'Y' Label
glRasterPos3f(240, 5, 0);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, 'X'); // 'X' Label
glBegin(GL_POINTS); // use points to form X-/Y-axes
glColor3f(0, 0, 0); // change drawing color to black
for (int x = -250; x <= 250; x++) // draw X-axis
glVertex2i(x, 0);
for (int y = -250; y <= 250; y++) // draw Y-axis
glVertex2i(0, y);
glEnd();
}
//
***********************************************************************************
void myInit()
{
glClearColor(1, 1, 1, 0); // specify a background clor: white
gluOrtho2D(-300, 300, -300, 300); // specify a viewing area
}
//
***********************************************************************************
void myDisplayCallback()
{
glClear(GL_COLOR_BUFFER_BIT); // draw the background
drawPoints();
glFlush(); // flush out the buffer contents
}
//
***********************************************************************************
void xMenuCallback(int entryId)
{
switch (entryId) {
case 1:
myDisplayCallback();
break;
case 2:
myDisplayCallback();
break;
}
}
//
***********************************************************************************
void yMenuCallback(int entryId)
{
switch (entryId) {
case 1:
myDisplayCallback();
break;
case 2:
myDisplayCallback();
break;
}
}
//
***********************************************************************************
void zMenuCallback(int entryId)
{
switch (entryId) {
case 1:
myDisplayCallback();
break;
case 2:
myDisplayCallback();
break;
}
}
//
***********************************************************************************
void parentMenuCallback(int entryId)
{
switch (entryId) {
case 1:
myDisplayCallback();
break;
case 2:
exit(0);
break;
}
}