Tcz
Tcz

Reputation: 701

OpenGL strange Rendering behaviour (flickering faces)

PRE: I'm using Assimp (Open Asset Import) library to import a .3ds file. Meshes are rendered with normals and materials. Using Qt. Drivers up to date on all the computers we tried.

POST: When I rotate around the objects,using camera,I can see that some mesh' faces flickering.

The same happens using Assimp' render() method (sample code downloaded from A. wsite).

1)The strange thing is that it usually happens with small size .3ds,while never happens with big ones.

2)If I am really close there are no artifacts.The furthest I am,the more artifacts I see.

Is it a .3ds problem or mine?

Example of big .3ds (20MB) e

Example of small .3ds (3MB) enter image description here

I paste here my Draw() function (uses glLists but i can't get rid of them):

void Preview::BuildObjectsLists(Scene *sc,GLenum mode){             
QHash<QString, SceneObject*>& hash=sc->getObj();
int counter =0;

for (QHash<QString,SceneObject*>::ConstIterator i = hash.begin();i!=hash.end();++i) {
    glNewList(index-counter, GL_COMPILE);                       
    Mesh* p = dynamic_cast<Mesh*>(i.value());
    if(p){
        Matrix4x4& a=p->getTrasformation();
        a.transpose();
        if(mode==GL_SELECT){                                  
            glPushName(counter);
        }
        glPushMatrix();
        glMultMatrixf((float*) &(a.values));
        applyMaterial(p->getMat());
        QList<Face>& faccie=p->getFaces();
        int numerofacce=faccie.count();
        QList<Vector3D>& normals =p->getNormals();
        bool hasNormals=(!(normals.isEmpty()));
        if(hasNormals)  glEnable(GL_LIGHTING);
        else glDisable(GL_LIGHTING);
        for (int t = 0; t < numerofacce; ++t) {
            Face& f = faccie[t];
            GLenum face_mode;
            Vector3D* lista=f.arrayVertici;
            int* listaNorm=f.normalIndex;
            switch(f.numVertici) {
            case 1:
                face_mode = GL_POINTS;
                glBegin(face_mode);
                if(hasNormals)
                    glNormal3fv(&((normals[listaNorm[0]]).pos[0]));
                glVertex3fv(&lista[0].pos[0]);
                break;
            case 2:
                face_mode = GL_LINES;
                glBegin(face_mode);
                if(hasNormals){
                    glNormal3fv(&((normals[(f.normalIndex)[0]]).pos[0]));
                    glVertex3fv(&lista[0].pos[0]);
                    glNormal3fv(&((normals[(f.normalIndex)[1]]).pos[0]));
                    glVertex3fv(&lista[1].pos[0]);
                }
                else{
                    glVertex3fv(&lista[0].pos[0]);
                    glVertex3fv(&lista[1].pos[0]);
                }
                break;
            case 3:
                face_mode = GL_TRIANGLES;
                glBegin(face_mode);
                if(hasNormals){
                    glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
                    glVertex3fv(&lista[0].pos[0]);
                    glNormal3fv(&normals[(f.normalIndex)[1]].pos[0]);
                    glVertex3fv(&lista[1].pos[0]);
                    glNormal3fv(&normals[(f.normalIndex)[2]].pos[0]);
                    glVertex3fv(&lista[2].pos[0]);
                }
                else{
                    glVertex3fv(&lista[0].pos[0]);
                    glVertex3fv(&lista[1].pos[0]);
                    glVertex3fv(&lista[2].pos[0]);
                }
                break;
            default: face_mode = GL_POLYGON; break;
            }
            glEnd();
        }
        glPopMatrix();
    }
    if(mode==GL_SELECT) glPopName();
    glEndList();
    counter++;
}

}

Upvotes: 3

Views: 2308

Answers (1)

Andreas Haferburg
Andreas Haferburg

Reputation: 5510

12.040 Depth buffering seems to work, but polygons seem to bleed through polygons that are in front of them. What's going on?

You may have configured your zNear and zFar clipping planes in a way that severely limits your depth buffer precision. Generally, this is caused by a zNear clipping plane value that's too close to 0.0.

http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm

Upvotes: 9

Related Questions