2009-11-26 2 views
0

질문이 있으십니까? 누군가 저를 도울 수 있습니다. OpenGL을 사용하여 거울 효과를 만들려고합니다. 나는 투명한 평면, 스텐실로 자른 "반사 된"장면, 원래의 장면을 그린다. 하지만 거울 대신 완전히 불투명 한 "벽"이 있습니다. 첫 번째 미러 플레인 렌더링 (스텐실 버퍼를 얻음) 때문에 이것이 일어난다는 것을 알고 있습니다. 이 여기 를 :(코드입니다 함께하지만 무엇을 해야할지하지 않습니다 문제가 아직 거기 경우블렌딩 문제 (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(); 
} 

답변

1

당신이 마지막으로 무승부를하지 않으면 어떻게됩니까 (즉, 그것으로 제거) 예를 복잡하게? 분명

한 가지는 당신은 아무것도 Z 버퍼가 관련 처리하지 않는 것이다.

당신은 Z-쓰기가 켜져 가정, 스텐실을 설정하는 첫 번째 쿼드를 그릴 때, 거울 Z에 Z 값을 설정하게됩니다. 거울에 반사되는 장면을 그리는 것은 Z가 거부됩니다.

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

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

+0

바바라, 감사합니다! glClear (GL_DEPTH_BUFFER_BIT) worked :)) 그리고 나는 마지막 무승부를 없앴습니다. 정말 감각이 없었습니다. :)) – Irene