简体   繁体   English

OpenGL正交投影剪辑

[英]OpenGL Orthographic Projection Clipping

Assuming I use Orhographic Projection, and have a reshape function like this: 假设我使用Orhographic Projection,并具有这样的重塑功能:

void reshape(f32 width, f32 height){
    aspect = width/height;
    glViewport(0, 0, width, height);
    // guaranted 960x640 HUD canvas
    if(640*aspect>=960){
        ortho.x = 640*aspect;
        ortho.y = 640;
    }else{
        ortho.x = 960;
        ortho.y = 960/aspect;
    }
    glOrtho(0, ortho.x, ortho.y, 0, -1.0f, 1.0f);
}

How can I make sure, that all vertices >ortho.x or >ortho.y (normally offscreen) are didn't drawn? 我如何确保所有顶点> ortho.x或> ortho.y(通常在屏幕外)都没有绘制? Because if I scale the windows to something with a bigger aspect ratio than 1.5f (960/640) I see the objects, that schouldn't be full visible (because the viewport is so big like the window). 因为如果我将窗口缩放到宽高比大于1.5f(960/640)的东西,我会看到那些不完全可见的对象(因为视口像窗口一样大)。 Is there something like a clipping pane in orthographic projection? 在正投影中是否有剪裁窗格?

Use constant values for the limit parameters of glOrtho, but use glViewport and glScissor (enable with glEnable(GL_SCISSOR_TEST) ) to limit rendering to a sub-portion of your window. 对glOrtho的限制参数使用常量值,但使用glViewportglScissor (使用glEnable(GL_SCISSOR_TEST) )将渲染限制为窗口的子部分。

BTW: You should set the projection and viewport in the rendering function. BTW:您应该在渲染功能中设置投影和视口。 Doing it in the reshape handler makes not much sense. 在重塑处理程序中执行它没有多大意义。 In any serious OpenGL application you'll switch projection modes several times during a full render, so just do it that way from the very beginning. 在任何严肃的OpenGL应用程序中,您将在完整渲染期间多次切换投影模式,因此从一开始就这样做。

What you want is to use [glScissor][1] to ensure that the rendered area never goes beyond a certain size. 你想要的是使用[glScissor][1]来确保渲染区域永远不会超过一定的大小。 glScissor takes a rectangle in window coordinates (remember: window coordinates have the origin at the bottom-left). glScissor在窗口坐标中取一个矩形(请记住:窗口坐标的原点位于左下角)。 The scissor test prevents the generation of fragments outside of this area. 剪刀测试可防止在该区域外产生碎片。

To activate the scissor test, you must use glEnable(GL_SCISSOR) . 要激活剪刀测试,必须使用glEnable(GL_SCISSOR) Unless you do that, the above call won't actually do anything. 除非你这样做,否则上述调用实际上不会做任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM