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

问题描述



在场景A

中,

我正在做一个 glOrtho(0,100,0,100,-100,100)和 glViewPort(0,0, 50,50)当glOrtho被定义为(left,right,bottom,top,zNear,zFar)并且glViewPort被定义为
时(左下角x,左下角y,在场景B中

我正在使用一个 glOrtho(0,height)。

50,0,50,-100,100)和 glViewPort(0,0,100,100)
当 glOrthois 定义为(left,right,bottom,top,zNear,zFar),glViewPort定义为
(左下角x,左下角y,宽度,高度)

这基本上意味着在场景A中,图像将渲染到比它所需要的更低的宽度和高度(即将每两个像素渲染一次)。原始图像将被映射到目标表面中的一个,但仍然会看到整个图像。然而,在场景B中,图像将被剪切所以只有左上角的四分之一才可见。我对么? - 只是要清楚,这是来自CG测试的一个问题,我有tommorow,并且我想确保我得到了正确的openGL ...(已经读取了API ... = \

解决方案

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



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



修改视口不会改变视锥体,实际上相同的图像只会被拉伸以适合新的视口。



显示图像:



图片1:视口为半窗口



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



所以唯一的解决方案,保持一个(比如在这种情况下,我是左右两个值)



图3:最终结果(注意现在3D世界的一个更大的部分是可见的):





更多详情可在。


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.

In scenario A

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).

In scenario B

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)

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.

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 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 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.

Explicative Images:

Picture 1: viewport is half window

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)

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

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

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

10-30 08:11