Some explanation about a simple code

Hello, im reading a book about OpenGL programming and i’ve made a little app now that shows a blue screen with a red rectangle in the middle. Only i dont get some explanations of the book and i was hoping to get some better explanations about it here.
Im gonna post the whole code, but the part i dont understand is in the function “ChangeSize()” I commented everyline i dont understand or that i think i understand and try to explain what could happen. Can someone please tell me how and what the lines mean and do that i dont understand or where im wrong.
Thanks for any help.

#include <glut.h>

void RenderScene(void)
	glColor3f(1.0f, 0.0f, 0.0f);
	glRectf(10.0f, 10.0f, 0.0f, 0.0f);

void SetupRC()
	glClearColor(-25.0f, 25.0f, 25.0f, -25.0f);

void ChangeSize(GLsizei w, GLsizei h) //define 2 vars (w and h) for widht and height
	GLfloat aspectRatio;  //Dont know what happends here


	glViewport(0, 0, w, h);  //the first two numbers (0 and 0) are the values for
							 //the top and left placement in the window. (0,0) is a center posistion?
							 //the (w and h) are the values for (in this case) the width and height of the current window

	glMatrixMode(GL_PROJECTION);	//Dont know
	glLoadIdentity();				//Has something to do with the glMatrixMode

	aspectRatio = (GLfloat)w / (GLfloat)h;  //Dont know what aspectRatio is for but it devides the window width with the window height(?) but for what reason? 

	if(w <= h)  //if width is smaller or equals the heigth
		glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);  //Dont know what happends here exactly
		glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);  //same here, for what does glOrtho uses 6 parameters

	glMatrixMode(GL_MODELVIEW);  //Dont know why this is used again
	glLoadIdentity();			 //Same here

void main(void)
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);



hi, that change size function, defines the dimensions for the window, sets up the perspective, its just some code to set up the window and the view, that function wont change as your code grows

Yes i know that. Its just that i dont understand everyline of the code fully.

oh, then:
GLfloat aspectratio; declares a floating point variable called aspecratio.
the if(h==0) h=1; is to prevent a divide by zero.
the glViewPort line is to reset the current viewport.
glMatrixMode(GL_PROJECTION); sets the projection matrix.
glLoadIdentity(); is to reset the matrix.
to get a full description of every gl function go
[here]( rence-GL.xml) hope it helps


Thanks for the link. That is really helpful.
Your link didnt work so here is the working one for people who want to see the site too.

or for the index page