How to make sure the plane fills the viewing area perfectly in OpenGL ES

I'm trying to create a flat plane so that it perfectly fills the viewport in an OpenGL ES application. I can achieve this effect by creating a plane and then experimentally moving it back and forth until I get the right effect, but I'm sure it should be possible to pinpoint how far it should be from the camera. I would welcome any pointers!

I need to be precise, because the plane has a texture superimposed on it that I want to fill, and not be cropped at all.

Thank!

+3
source share
2 answers

glFrustum gluPerspective, . glFrustum , . :

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)
+1

/ .

0

Source: https://habr.com/ru/post/1764747/


All Articles