none
Polygon 2D RRS feed

  • Pergunta

  • Estou com um problema ao usar glStencil, usando OPenGL e MFC...

    Eis o código:

    double* vertex = reinterpret_cast<double*>(data());
    glVertexPointer(3, GL_DOUBLE, 0, vertex);
    
    // We are going to do 2-pass draw: draw to stencil buffer first then draw to color buffer.
    glEnable(GL_STENCIL_TEST);          // enable stencil test
    
    glClearStencil(0);
    //raw to stencil buffer only
    // The reference value will be written to the stencil buffer plane if test passed
    // The stencil buffer is initially set to all 0s.
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // disable writing to color buffer
    glStencilFunc(GL_ALWAYS, 0x1, 0x1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT);
    		
    //Desenha
    glDrawArrays(GL_TRIANGLE_FAN,0,size());
    
    // PASS 2: draw color buffer
    // Draw again the exact same polygon to color buffer where the stencil
    // value is only odd number(1). The even(0) area will be descarded.
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);    // enable writing to color buffer
    glStencilFunc(GL_EQUAL, 0x1, 0x1);                  // test if it is odd(1)
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    		
    glDrawArrays(GL_TRIANGLE_FAN,0,size()); 
    
    glDisable(GL_STENCIL_TEST);
    
    //Desenha contorno
    glColor3f(0,0,0);
    glDrawArrays(GL_LINE_LOOP,0,size());

    Os pontos usados são: https://docs.google.com/file/d/0B8B-NIoST12WMjVjVjBvbjBteVE/edit?usp=sharing

    A imagem está saindo com pontos aleatórios...

    Polygon

    Usando GLUT funciona corretamente.


    VC++ Programmer

    segunda-feira, 3 de junho de 2013 16:55