ch02 bouncing box
maybe this is the finest and clearness version of the
bouncing box, i ever made -- althogh partial copy the super bible
should be pay attention the following code
the view port didn't corresponding the windows real pixel
they connected by the aspect ratio = window's pixels width/ window's pixels height
void ChangeSize(GLsizei w, GLsizei h) { //windowWidth = w; //windowHeight = h; GLfloat aspectRatio; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) aspectRatio = (GLfloat)w / (GLfloat)h; if (w <= h) { windowWidth = 100.; windowHeight = 100 / aspectRatio; glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0); } else { windowWidth = 100 * aspectRatio; windowHeight = 100; glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }