如何确保平面完美填充OpenGL ES中的视口 [英] How to ensure that a plane perfectly fills the viewport in OpenGL ES

查看:80
本文介绍了如何确保平面完美填充OpenGL ES中的视口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个平面,以使其完全填充OpenGL ES应用程序中的视口.我可以通过创建平面,然后实验性地将其前后移动,直到获得正确的效果,来实现这种效果,但是我敢肯定,必须有可能精确计算出它应该与相机相距多远.我欢迎任何指点!

I'm trying to create a flat plane such that it perfectly fills the viewport in an OpenGL ES application. I can achieve this effect by creating the plane and then experimentally moving it forwards and backwards until I get the right effect, but I'm certain that it must be possible to work out exactly how far away from the camera it should be. I would welcome any pointers!

我需要准确,因为飞机上已应用了纹理,我想填充窗口而不是完全剪裁.

I need to be accurate because the plane has a texture applied to it, which I want to fill the window and not be clipped at all.

谢谢!

推荐答案

使用glFrustum代替gluPerspective来设置透视投影.使用glFrustum,您可以根据要显示视口填充的平面来定义投影.伪代码:

Use glFrustum instead of gluPerspective to set the perspective projection. With glFrustum you define the projection in terms of a plane you want to display viewport-filling. Pseudocode:

aspect = win.width/win.height
bt = tan( fov/2 ) 
lr = bt * aspect

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum( -lr * zclip.near,
            lr * zclip.near,
           -bt * zclip.near,
            bt * zclip.near,
            zclip.near, zclip.far)

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

vertices = [
    (-lr * planedist, -bt * planedist, -planedist),
    ( lr * planedist, -bt * planedist, -planedist),
    ( lr * planedist,  bt * planedist, -planedist),
    (-lr * planedist,  bt * planedist, -planedist)
]
draw_vertices(vertices)

这篇关于如何确保平面完美填充OpenGL ES中的视口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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