如何以这种方式设置OpenGL窗口 [英] How to setup an OpenGL window this way

查看:121
本文介绍了如何以这种方式设置OpenGL窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个OpenGL窗口设置为使其左上角为0,0,而右下角为窗口的宽度和高度(像素而不是百分比).当调整大小时,没有绘制任何缩放比例,而是放大/缩小了窗口区域.用于绘制2D图像.我正在使用Windows API.我该怎么做?

I''m trying to setup an OpenGL window to have the the top-left corner 0,0 and the bottom-right corner the width and height of the window (pixels not percentage). And when resized nothing drawn is scaled, instead the window area is enlarged/shrunk. It''s for drawing 2D images. I''m using the Windows API. How can I do this?

推荐答案

OnSize(UINT nType, int cx, int cy)
{
    // Set viewport widht as cx, and height as cy
    glViewport( 0, 0, cx, cy );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, cx, cy, 0, 0, 1 );

    m_nWidth = cx;
    m_nHeight = cy;
}



您需要重新绘制与新屏幕尺寸有关的所有框架.



You need to redraw all your frame related to new screen size.

onDrawFrame()
{
   // Draw frame relative to m_nWidth and m_nHeight.
   // Eg. glRect( 0,0, m_nWidth, m_nHeight )
}


这篇关于如何以这种方式设置OpenGL窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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