문제

질문이 있습니다. 누군가가 나를 도울 수있을 것입니다. OpenGL을 사용하여 거울 효과를 만들려고합니다. 나는 투명한 비행기, 스텐실에 의해 자른 "반사 된"장면을 그립니다. 그러나 나는 거울 대신에 완전히 비교적이지 않은 "벽"을 가지고 있습니다. 첫 번째 미러 평면 렌더링 (스텐실 버퍼를 얻기 위해) 때문에 발생합니다. 그러나 나는 이것으로 무엇을 해야할지 모르겠다 :( 여기 코드가있다 :

  void CMirror::draw(CSceneObject * curscene)
{
    glPushMatrix();
    glClearStencil(0.0f);

    glClear(GL_STENCIL_BUFFER_BIT);
    //Draw into the stencil buffer
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glStencilFunc(GL_ALWAYS, 1, 0);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
    glEnable(GL_STENCIL_TEST);
    glPushMatrix();
    glTranslatef(this->coords[0], this->coords[1], this->coords[2]);
    glScalef(this->size, this->size, this->size);
    glColor4f(1, 0, 1, 0);
    glBegin(GL_QUADS);
        glVertex3f(0.0f, this->height / 2.0f, this->width / 2.0f);
        glVertex3f(0.0f, this->height / -2.0f, this->width / 2.0f);
        glVertex3f(0.0f, this->height / -2.0f, this->width / -2.0f);
        glVertex3f(0.0f, this->height / 2.0f, this->width / -2.0f);
    glEnd();
    glPopMatrix();
    glDisable(GL_STENCIL_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
    //glClear(GL_COLOR_BUFFER_BIT);
    //Draw the scene
    glEnable(GL_STENCIL_TEST);  
    glStencilFunc(GL_EQUAL, 1, 255);
    glPushMatrix();
    glTranslatef( 2*this->coords[0], 2*this->coords[1], 2*this->coords[2]);
    glScalef(-1.0f, 1.0f, 1.0f);
    ((CScene*)curscene)->draw();
    glColor4f(0.0f, 0.30f, 0, 0.9); 
    ((CScene*)curscene)->spline->draw();
    ((CScene*)curscene)->morph->draw();


    glPopMatrix();
    glDisable(GL_STENCIL_TEST);
    //the mirror itself:
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glPushMatrix();
    glTranslatef(this->coords[0], this->coords[1], this->coords[2]);
    glScalef(this->size, this->size, this->size);
    glColor4f(0, 0, 0, 0.9);
    glBegin(GL_QUADS);
        glVertex3f(0.0f, this->height / 2.0f, this->width / 2.0f);
        glVertex3f(0.0f, this->height / -2.0f, this->width / 2.0f);
        glVertex3f(0.0f, this->height / -2.0f, this->width / -2.0f);
        glVertex3f(0.0f, this->height / 2.0f, this->width / -2.0f);
    glEnd();
    glPopMatrix();
    glDisable(GL_BLEND);

    glPopMatrix();
}
도움이 되었습니까?

해결책

마지막 드로우를하지 않으면 어떻게됩니까 (예 : 문제가 아직 존재하는 경우 예제를 복잡하게하므로 제거하십시오)?

분명한 한 가지는 Z- 버퍼 관련 항목을 처리하지 않는 것입니다.

Z-Write가 켜져 있다고 가정하면 첫 번째 쿼드를 스텐실을 설정하면 z- 값을 거울 Z로 설정합니다. 거울에 반영되어야 할 장면을 그리는 것은 z 재사용됩니다.

화면의 해당 영역의 z 버퍼를 어떻게 든 지우야합니다. 분명히, 전체 Clear(DEPTH_BIT) 작동 할 수는 있지만 이미 화면에서 그린 내용에 따라 다릅니다.

마찬가지로, 스텐실을 업데이트 할 때 Z- 버퍼를 업데이트하지 않으면 이전에 어떤 것이 그려 졌는지 여부에 따라 작동 할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top