glortho()函数:
参数 void glOrtho(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,GLdouble near,GLdouble far);
实例:
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_LINE_STRIP);
glVertex3f(-5.0,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(5.0,5.0,0.0);
//glScalef(1.0,2.0,1.0);
glEnd();
glFlush();
}
void reshape(int w , int h)
{
glViewport(0,0,(GLfloat)w,(GLfloat)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10,10,-10,10,0,100);
glMatrixMode(GL_MODELVIEW);
}
int _tmain(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,500);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display); //必须要有
glutReshapeFunc(reshape); //必须要有 否则闪退
glutMainLoop();
return 0;
}
效果:
glFrustum()函数:在使用前 先调用 glMatrixMode(GL_PROJECTION); 并且要使用gluLookAt()设置 摄像机方向
实例:
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0,0.0,2.0,0.0,0.0,0.0,0.0,1.0,0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(-5.0,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(5.0,5.0,0.0);
glEnd();
glFlush();
}
void reshape(int w , int h)
{
glViewport(0,0,(GLfloat)w,(GLfloat)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-10,10,-10,10,2,100);
glMatrixMode(GL_MODELVIEW);
}
int _tmain(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,500);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display); //必须要有
glutReshapeFunc(reshape); //必须要有 否则闪退
glutMainLoop();
return 0;
}
效果:和上面glOrtho()函数实现的效果一致