刚开始学opengl,先贴一段代码,说明一下我的理解,能不能按照我的说明,指出有什么问题?
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //start with an identity matrix
glPushMatrix();
//push the current identity matrix onto the stack, and start with a new identity matrix as
the transformation matrix
glPushMatrix();
//copy the current matrix which is the identity as the new transformation matrix and then push the current transformation matrix onto stack
glScalef(10, 10, 1.0);
**Question 1**
//I feels like the order which the image is built is kinda reversed
//It's like drawSquare happens first, then color, then scale
//can anyone clarify?
//Second, the drawsquare defines the 4 vertices around the origin(+/-0.5,+/-0.5)
//is the origin located at the center of the window by default?
//what happen when it is scaled? does point (0.5,0.5) scaled to (5,5)?
glColor3f(0.0, 1.0, 0.0);
drawSquare(1.0);
glPopMatrix();
//forget the current transformation matrix, pop out the one on top of the stack
//which is the identity matrix
//In the code below:
//my understanding is 4 vertices is defined around origin, but is this the same origin?
//then the unit square is moved just below the X-axis
//and the 4 vertices are scaled one by one?
//ex: (0.5,0) -> (1,0) (0.5,-1) -> (1,-2)
glScalef(2, 2, 1.0);
glTranslatef(0.0, -0.5, 0.0);
glColor3f(1.0, 0.0, 0.0);
drawSquare(1.0);
//last question, if I want to make the second square rotate at a point along z-axis
//do I have to specify it here?
//for example: add glRotatef(rotate_degree, 0.0, 0.0, 1.0); above the glScalef(2, 2, 1.0);
//such that later i can change the value in the rotate_degree?
glPopMatrix(); //forget about the current transformation matrix, pop out the top matrix on the stack.