#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL\glut.h>
#include <GL\gl.h>
#include <math.h>
static int WIN_H = 800;
static int WIN_W = 800;
static int WIN_POS_X = 200;
static int WIN_POS_Y = 0;
float xAngle;
float yAngle;
float xAngle2;
float yAngle2;
void drawTeapot()
{
glColor3f(150.0,200.0,100.0);
glutWireTeapot(0.5);
glFlush ();
}
void display()
{
glClearColor(0.0,1.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,WIN_W/2,WIN_H);
gluPerspective(45.0,1.0* WIN_W/WIN_H,1.0,100.0);
glTranslatef(0.0,0.0,-10.0);
glRotatef(xAngle,1.0,0.0,0.0);
glRotatef(yAngle,0.0,1.0,0.0);
drawTeapot();
glLoadIdentity();
glOrtho(0.0,WIN_W,0.0,WIN_H,0.0,0.0);
glMatrixMode(GL_MODELVIEW);
glViewport(WIN_W/2,0,WIN_W/2,WIN_H);
glRotatef(xAngle2,1.0,0.0,0.0);
glRotatef(yAngle2,0.0,1.0,0.0);
drawTeapot();
}
void keyboard (unsigned char key, int x, int y) {
if (key=='q' || key==27)
{
exit(1);
}
if(key == 'x')
{
xAngle = 0.0;
yAngle = 0.0;
glutPostRedisplay();
}
if(key == 'y')
{
xAngle = 90.0;
yAngle = 0.0;
glutPostRedisplay();
}
if(key == 'z')
{
xAngle = 0.0;
yAngle = 120.0;
glutPostRedisplay();
}
if(key == 'X')
{
xAngle2 = 0.0;
yAngle2 = 0.0;
glutPostRedisplay();
}
if(key == 'Y')
{
xAngle2 = 90.0;
yAngle2 = 0.0;
glutPostRedisplay();
}
if(key == 'Z')
{
xAngle2 = 0.0;
yAngle2 = 120.0;
glutPostRedisplay();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(WIN_W,WIN_H);
glutInitWindowPosition(WIN_POS_X, WIN_POS_Y);
glutCreateWindow("OPENGL PROGRAM");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
|