本文介绍了如何仅剪切剪切平面的交集(而不是并集)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 OpenGL/JOGL 中,当使用多个剪切平面时,似乎应用了所有剪切平面的并集.我想要的是要应用的所有剪裁平面的交集.这可能吗?请参阅下面的简化二维示例.

In OpenGL/JOGL, when using more than one clipping plane, the union of all clipping planes appears to be applied. What I want is instead the intersection of all clipping planes to be applied. Is this possible? See the below simplified 2-D example.

通过顶点着色器进行裁剪的示例(请参阅下面的评论).

An example of clipping by vertex shader (see comments below).

推荐答案

Multi-pass:

Multi-pass:

#include <GL/glut.h>

void scene()
{
    glColor3ub( 255, 0, 0 );
    glBegin( GL_QUADS );
    glVertex2i( -1, -1 );
    glVertex2i(  1, -1 );
    glVertex2i(  1,  1 );
    glVertex2i( -1,  1 );
    glEnd();
}

void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    double w = glutGet( GLUT_WINDOW_WIDTH );
    double h = glutGet( GLUT_WINDOW_HEIGHT );
    double ar = w / h;
    glOrtho( -2 * ar, 2 * ar, -2, 2, -1, 1);

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glEnable( GL_CLIP_PLANE0 );

    // -y plane
    GLdouble plane0[] = { -1, 0, 0, 0 };
    glClipPlane( GL_CLIP_PLANE0, plane0 );

    scene();

    // -x plane
    GLdouble plane1[] = { 0, -1, 0, 0 };
    glClipPlane( GL_CLIP_PLANE0, plane1 );

    scene();

    glutSwapBuffers();
}

int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
    glutInitWindowSize( 640, 480 );
    glutCreateWindow( "Clipping" );
    glutDisplayFunc( display );
    glutMainLoop();
    return 0;
}

这篇关于如何仅剪切剪切平面的交集(而不是并集)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:32