Here is my code. Basically it just initialsing a display list and then when I press the ‘Z’, it magnify the image by a factor of two.
void render()
{
// the function which actually generate the triangles
}
void setup()
{
alist = nlist;
glNewList(alist, GL_COMPILE);
render();
glEndList();
}
void cbRenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);
glScalef(X_Off, Y_Off, 1.0);
glCallList(alist);
glutSwapBuffers();
wait(1);
}
void cbKeyPressed(unsigned char key,
int x, int y)
{
switch (key)
{
case 113: case 81: case 27: // Q (Escape) - We’re outta here.
glutDestroyWindow(Window_ID);
exit(1);
break; // exit doesn’t return, but anyway…
case 122: // z
if(X_Off > 1 && Y_Off > 1)
{
X_Off = X_Off / 2;
Y_Off = Y_Off / 2;
}
break;
case 90: // Z, magnify it by two
X_Off = X_Off * 2;
Y_Off = Y_Off * 2;
break;
default:
printf ("KP: No action for %d.
", key);
break;
}
}
void cbResizeScene(
int Width, int Height)
{
if (Height == 0)
Height = 1;
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective((Width/8),(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
Window_Width = Width;
Window_Height = Height;
}
void ourInit( int Width,int Height
)
{
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
cbResizeScene(Width,Height);
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
Window_Width = inputw2;
Window_Height = inputh2;
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(Window_Width, Window_Height);
Window_ID = glutCreateWindow( PROGRAM_TITLE );
glutDisplayFunc(&cbRenderScene);
glutIdleFunc(&cbRenderScene);
glutReshapeFunc(&cbResizeScene);
glutKeyboardFunc(&cbKeyPressed);
ourInit(Window_Width, Window_Height);
nlist = glGenLists(1);
setup();
glutMainLoop();
glDeleteLists(nlist,1);
return 1;
}