如何在OpenGL中使用glOrtho()? [英] How to use glOrtho() in OpenGL?

查看:263
本文介绍了如何在OpenGL中使用glOrtho()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不了解glOrtho的用法.有人可以解释它的用途吗?

I can't understand the usage of glOrtho. Can someone explain what it is used for?

是否用于设置x y和z坐标限制的范围?

Is it used to set the range of x y and z coordinates limit?

glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

这意味着x,y和z范围是-1到1?

It means that the x, y and z range is from -1 to 1?

推荐答案

看看这张图片: glOrtho命令产生一个"Oblique"投影,您可以在底行看到它.无论顶点在z方向上有多远,它们都不会退缩到该距离中.

The glOrtho command produces an "Oblique" projection that you see in the bottom row. No matter how far away vertexes are in the z direction, they will not recede into the distance.

每次需要在OpenGL中进行2D图形处理时(例如健康栏,菜单等),我都会使用glOrtho 每次调整窗口大小时,使用以下代码:

I use glOrtho every time I need to do 2D graphics in OpenGL (such as health bars, menus etc) using the following code every time the window is resized:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, windowWidth, windowHeight, 0.0f, 0.0f, 1.0f);

这会将OpenGL坐标重新映射为等效的像素值(X从0到windowWidth,Y从0到windowHeight).请注意,由于OpenGL坐标是从窗口的左下角开始的,所以我已经翻转了Y值.因此,通过翻转,我从窗口的左上角开始获得了更常规的(0,0).

This will remap the OpenGL coordinates into the equivalent pixel values (X going from 0 to windowWidth and Y going from 0 to windowHeight). Note that I've flipped the Y values because OpenGL coordinates start from the bottom left corner of the window. So by flipping, I get a more conventional (0,0) starting at the top left corner of the window rather.

请注意,Z值从0剪切到1.因此,当为顶点位置指定Z值时,请小心,如果Z值超出该范围,则会被剪切.否则,如果它在该范围内,则除Z测试外,对位置无影响.

Note that the Z values are clipped from 0 to 1. So be careful when you specify a Z value for your vertex's position, it will be clipped if it falls outside that range. Otherwise if it's inside that range, it will appear to have no effect on the position except for Z tests.

这篇关于如何在OpenGL中使用glOrtho()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆