2

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++;
}

}
Tcz
  • 661
  • 5
  • 18

1 Answers1

7

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

Community
  • 1
  • 1
Andreas Haferburg
  • 5,189
  • 3
  • 37
  • 63
  • gluPerspective(fov,ratio,0.1f,20000); to gluPerspective(fov,ratio,5.0f,20000); solved the problem,thank you a lot – Tcz Jun 23 '13 at 00:48
  • 2
    @nicolagenesin: I would suggest to reduce your `200000` too, seems a rather high value, but of course it depends on the size of your object in OpenGL units. The question you have to answer is: "is it any useful in your application to see that far?" – Boris Dalstein Jun 24 '13 at 04:24
  • 1
    I've downloaded some .3ds files from internet and 2 of them are large like 10k.So,if i want to see them entirely I've to be like 15k far from origin.B ut what you said is a smart thing : I could dinamycally arrange the zFar during scene loading (I know how large the model is -> set zFar with some algorithm). Thank you – Tcz Jun 24 '13 at 10:21