// Computer Graphics - Amir Hesami // This program shows the effect of the reshape function. // The result is the aspect ratio of the object will be changed. // reshape2.cpp #include #pragma comment(lib, "opengl32.lib") // Link OpenGL32.lib #pragma comment(lib, "glu32.lib") // Link Glu32.lib #pragma comment(lib, "glut32.lib") // Link Glut32.lib #pragma comment(linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main() #pragma comment(linker, "/subsystem:\"Windows\"" ) // set the entry point to be main() void display(); void init(); void reshape(GLsizei , GLsizei ); int wh,ww;// for further use. int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow("The effect of reshape"); glutDisplayFunc(display); glutReshapeFunc(reshape); init(); glutMainLoop(); return 0; } void display() { //Clear the window glClear(GL_COLOR_BUFFER_BIT); //Set the drawing color to red glColor3f(1.0,0.0,0.0); //draw unit square polygon glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); //Flush the buffer glFlush(); } void init() { //Set the background color glClearColor(1.0,1.0,1.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0,1.0,-1.0,1.0); } void reshape(GLsizei w, GLsizei h) { //adjust clipping box glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-2.0,2.0,-2.0,2.0); glMatrixMode(GL_MODELVIEW); //adjust the viewport glViewport(0,0,w,h); //set global size for use by drawing routine ww = w; wh = h; }