解释glOrtho()的用法? [英] Explain the usage of glOrtho()?

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

问题描述

我不明白glOrtho的用法。有人可以解释它的用途吗?

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

用于设置xy的范围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 are from -1 to 1?

推荐答案

看看这张图片:图形投影

glOrtho 命令会生成一个底部两个面板。无论顶点在z方向有多远,它们都不会后退到距离。

The glOrtho command produces an "Oblique" projection that you see in the bottom two panels. 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)。注意,我已经翻转了Y值,因为OpenGL坐标从窗口的左下角开始。所以通过翻转,我得到一个更传统的(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.

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

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