在OpenGL中,如何调整要调整大小的窗口? [英] In OpenGL, how can I adjust for the window being resized?

查看:448
本文介绍了在OpenGL中,如何调整要调整大小的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制从窗口高度&宽度.由于窗口始终以给定的大小开始,因此可以正确绘制它们,但是当调整窗口大小时,会弄乱纵横比.

I am drawing several shapes (such as circles) that are keyed off of the window height & width. Since the window always starts at a given size, they are drawn correctly, but when the window is resized, it messes the aspect ratio up.

无论窗口大小如何,如何正确绘制形状?

How can I draw the shapes properly, regardless of window size?

推荐答案

您绝对不想使对象的大小明确取决于窗口的大小.

You definitely don't want to make the size of your objects explicitly dependent on the window size.

正如genpfault所建议的那样,只要窗口大小发生变化,就调整投影矩阵.

As already suggested by genpfault, adjust your projection matrix whenever the window size changes.

关于调整窗口大小的事情:

Things to do on window resize:

  1. 调整视口

glViewport(0, 0, width, height)

  • 调整剪刀矩形(仅在启用了GL_SCISSOR_TEST的情况下)

  • Adjust scissor rectangle (only if you have GL_SCISSOR_TEST enabled)

    glScissor(0, 0, width, height)
    

  • 调整投影矩阵

    在使用旧版(固定功能管道)OpenGL的情况下,您可以通过以下方式进行操作:

    In case of legacy (fixed function pipeline) OpenGL, you can do it the following ways:

    glFrustum(left * ratio, right * ratio, bottom, top, nearClip,farClip)
    

    glOrtho(left * ratio, right * ratio, bottom, top, nearClip,farClip)
    

    gluOrtho2D(left * ratio, right * ratio, bottom, top)
    

    (假设left, right, bottomtop都等于且ratio=width/height)

    这篇关于在OpenGL中,如何调整要调整大小的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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