opengl glortho() 和 glFrustum()

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()函数实现的效果一致



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值