本文介绍了openGL中glOrtho和glViewPort的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力找出一些东西,比如说我正在渲染一些高度为 100 和宽度为 100 的图像.

I am struggling to figure out something let's say im rendering some image that has a height of 100 and a width of 100.

当 glOrthois 定义为 (left,right,底部、顶部、zNear、zFar) 和 glViewPort 已定义as(左下角x,左下角y,宽度,高度).

I am taking a glOrtho(0,100,0,100,-100,100) and glViewPort(0,0,50,50) when glOrthois defined as (left,right,bottom,top,zNear,zFar) and glViewPort is defined as (lower left corner x, lower left corner y, width, height).

我正在使用 glOrtho(0,50,0,50,-100,100)glViewPort(0,0,100,100)glOrthois 定义为 (left,right,bottom,top,zNear,zFar) 并且定义了 glViewPortas(左下角x,左下角y,宽度,高度)

I am taking a glOrtho(0,50,0,50,-100,100) and glViewPort(0,0,100,100)when glOrthois defined as (left,right,bottom,top,zNear,zFar) and glViewPort is defined as (lower left corner x, lower left corner y, width, height)

这基本上意味着在场景 A 中,图像将被渲染为比它需要的更低的宽度和高度(即将每两个像素渲染一次).原始图像将映射到目标表面"中的一个,但仍然可以看到整个图像.

That basically means that in scenario A the image will be rendered to a lower width and height than it requires (i.e will be rendered s.t every two pixels). In the original image will be mapped to one in the destination "surface" but still the entire image will be seen.

然而,在场景 B 中,图像将被裁剪,因此只有左上角的四分之一是可见的.我对么?- 需要说明的是,这是我明天要进行的 CG 测试中的一个问题,我想确保我正确地获得了 openGL...(已经阅读了 API...=)

In scenario B, however, the image will be clipped and so only the upper left quarter of it will be visible. Am I correct? - just to be clear, it's a question from a CG test im having tommorow and I want to make sure I got openGL correctly... (already read the API... =)

推荐答案

glViewPort以屏幕像素为单位:就是这样,它与显卡内部"的 3D 世界无关.它只是告诉窗口的哪一部分将用于渲染(或者只是可见).

glViewPort is in screen pixel units:that's it, it has nothing to do with the 3D world "inside" your graphics card. It just tells wich part of the window will be used for rendering (or just will be visible).

glOrtho而是改变内部"世界并且是 OpenGL 单位:更多的 OpenGL 单元将适合屏幕的可见部分,因此如果增加正射尺寸,更大"的对象将很容易放入可见区域.

glOrtho instead changes the "inner" world and is OpenGL units:More OpenGL units will fit into the visible part of the screen, so "bigger" objects will fit easily into viewable area if you increase the ortho size.

修改视口不会改变视锥,事实上相同的图像只会被拉伸以适应新的视口.

Modifying the viewport does not change the frustum, infact the same image will just be stretched to fit the new viewport.

说明性图片:

图一:视口是半窗

图片 2:如果我只是将视口加倍,图像就会被拉伸(填充不同表面的相同截锥体)

Picture 2: If I just double the viewport, the image becomes stretched (same frustum that fill a different surface)

因此,保持纵横比的唯一解决方案也是将正射尺寸加倍(在这种情况下,我将左右值加倍)

So the only solution to keep aspect ratio is to double ortho size too (in this case i double left and right values)

图片 3: 最终结果(请注意,现在 3d 世界的更大部分是可见的):

Picture 3: final result (note that now a bigger part of the 3d world is visible):

非常熟悉的 OpenGL NeHe 制作网站上提供了更多详细信息.

Further details are available at quite familiar site on OpenGL NeHe productions.

这篇关于openGL中glOrtho和glViewPort的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:12