shi*_*bly 4 opengl math graphics
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;
}
}
Run Code Online (Sandbox Code Playgroud)
实施例-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;
}
}
Run Code Online (Sandbox Code Playgroud)
对于这两个代码,我得到相同的结果.任何人都可以显示这些glMatrixMode(GL_MODELVIEW)的区别; 和glMatrixMode(GL_PROJECTION); 改变这段代码?
当然,你没有得到不同的结果。您实际上没有对矩阵做任何事情。您将其设置为“identity...”,这是默认值。
一般来说,您应该只将投影矩阵放入GL_PROJECTION矩阵中。从模型空间到相机空间的变换应该进入矩阵GL_MODELVIEW。
如果您不知道什么是投影矩阵,或者您不确定什么是矩阵,我建议您查找适当的 OpenGL 学习材料。并避免使用固定功能GL。
| 归档时间: |
|
| 查看次数: |
19127 次 |
| 最近记录: |