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

查看:40
本文介绍了在 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.

调整窗口大小的操作:

  1. 调整视口

glViewport(0, 0, width, height)

  • 调整剪刀矩形(仅当您启用了GL_SCISSOR_TEST)

    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)

    (assuming that left, right, bottom and top are all equal and ratio=width/height)

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

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