什么是glMatrixMode(GL_PROJECTION)之间的区别; 和glMatrixMode(GL_MODELVIEW);
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>
#define KEY_ESCAPE 27
void display();
void keyboard(unsigned char,int,int);
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH );
glutInitWindowSize(600,400);
glutCreateWindow("Opengl Test");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
void display() {
float x,y,z;
int i;
x=0;
y=-0.8;
z=0;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,0);
glBegin(GL_POINTS);
for(i=0;i<98;i++) {
glVertex3f(x,y,z);
x=x+0.01;
}
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int mousePositionX, int mousePositionY) {
switch ( key ) {
case KEY_ESCAPE:
exit ( 0 );
break;
default:
break;
}
}
实施例-2:
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>
#define KEY_ESCAPE 27
void display();
void keyboard(unsigned char,int,int);
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH );
glutInitWindowSize(600,400);
glutCreateWindow("Opengl Test");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
void display() {
float x,y,z;
int i;
x=0;
y=-0.8;
z=0;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,0);
glBegin(GL_POINTS);
for(i=0;i<98;i++) {
glVertex3f(x,y,z);
x=x+0.01;
}
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int mousePositionX, int mousePositionY) {
switch ( key ) {
case KEY_ESCAPE:
exit ( 0 );
break;
default:
break;
}
}
对于这两个代码,我得到同样的结果。 谁能告诉这些glMatrixMode(GL_MODELVIEW)的差异; 和glMatrixMode(GL_PROJECTION); 改变这种代码?