Results 1 to 9 of 9

Thread: Remobing Hidden Surfaces

  1. #1
    Guest

    Remobing Hidden Surfaces

    I m using glEnable(GL_DEPTH_TEST) to remove hidden faces and it doesnt work..
    If I put it before my glBegin it removes completely some pixels and if I put it after it doesnt remove the right facets...
    I tried it with a single triangle and it still bugs !!
    Can anyone help me with it?(I can send my code if someone is patient enough);

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Remobing Hidden Surfaces

    Are you clearing the depth buffer?

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    Usually I enable GL_DEPTH_TEST right after initializing the display.

    I don't quite understand what you mean when you say you tried it with a single triangle and it "still bugs." Depth test simply ensures that if you draw a triangle that is behind another, it won't get drawn. You won't get that with a single triangle.

    Perhaps you're confused about exactly what GL_DEPTH_TEST is supposed to do?
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2001
    Location
    Eastern USA
    Posts
    218

    Re: Remobing Hidden Surfaces

    If you can't get a single triangle to appear on the screen, maybe it is being culled (did you enable GL_CULL_FACE and call glCull...?) or maybe it's not inside the view volume.

    Also, remember to clear your depth buffer when redrawing, so lingering values don't queer your results.

    Perhaps you're using an incorrect depth function. glDepthFunc(GL_LEQUAL) or glDepthFunc(GL_LESS) are what you're probably going to want.

  4. #4
    Guest

    Re: Remobing Hidden Surfaces

    Originally posted by Deiussum:
    Are you clearing the depth buffer?

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    Usually I enable GL_DEPTH_TEST right after initializing the display.

    I don't quite understand what you mean when you say you tried it with a single triangle and it "still bugs." Depth test simply ensures that if you draw a triangle that is behind another, it won't get drawn. You won't get that with a single triangle.

    Perhaps you're confused about exactly what GL_DEPTH_TEST is supposed to do?
    No, when I display a single triangle with GL_DEPTH_TEST Instead of the triangle it displays "a stairs". And if I display a volume, it displays holes that are discontinuous when I move my object.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Remobing Hidden Surfaces

    I ask again... are you clearing the depth buffer? That's the only reason I can think of for a triangle to be displayed as "stairs" when depth test is enabled. Is it just when depth test is enabled that it displays like that?
    Deiussum
    Software Engineer and OpenGL enthusiast

  6. #6
    Senior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    London, England
    Posts
    160

    Re: Remobing Hidden Surfaces

    Lets see some code...
    And a screenshot of the "stairs".

  7. #7
    Guest

    Re: Remobing Hidden Surfaces

    Here you are =)I passed through the table creation.

    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here
    HDC hdc = ::GetDC(m_hWnd);
    HGLRC hglrc;


    // TODO: Add your message handler code here
    //glClearColor(0,0,0,0);
    //glColor3f(1, 1, 1);

    if (hglrc = wglCreateContext(hdc))
    {
    // try to make it the thread's current rendering context
    if(wglMakeCurrent(hdc, hglrc))
    {
    initOpengl();
    //glClearColor(0,0,0,0);
    //glColor3f(1, 1, 1);

    if(NombreFacette==3)
    {

    }//switch

    }//for(k=0;k<100;k++)
    }//for(i=0,j=0;i<u;i++)
    if(Mode==0) glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    if(Mode==1)
    {
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    }
    //if(Mode==2) glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    if(Mode==2) glPolygonMode(GL_FRONT,GL_FILL);
    glColor3d(CouleurIniR,CouleurIniV,CouleurIniB);

    //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    //glBegin(GL_TRIANGLES);

    for(i=0;i<u;i++)
    {// glBegin(GL_POLYGON);
    glBegin(GL_TRIANGLES);
    if(Couleur==2)
    {
    if(i==0&#0124; &#0124;i==1) glColor3f(1,1,0);
    if(i==2&#0124; &#0124;i==3) glColor3f(0,0,1);
    if(i==4&#0124; &#0124;i==5) glColor3f(1,0,0);
    if(i==6&#0124; &#0124;i==7) glColor3f(0,1,0);
    }
    if (Couleur==1)
    {
    if (atof(s3[atoi(s4[i])-1])<((s3max+2*s3min)/3))
    glColor3d(0,(3/(s3max-s3min))*atof(s3[atoi(s4[i])-1])-3*s3min/(s3max-s3min),1);
    if (atof(s3[atoi(s4[i])-1])>((2*s3max+s3min)/3))
    glColor3d(1,(3/(s3min-s3max))*atof(s3[atoi(s4[i])-1])+3*s3max/(s3max-s3min),0);
    else glColor3d((3/(s3min-s3max))*atof(s3[atoi(s4[i])-1])+(2*s3min+s3max)/(s3min-s3max),1,(3/(s3min-s3max))*atof(s3[atoi(s4[i])-1])+(2*s3max-s3min)/(s3max-s3min));
    }

    glVertex3d(atof(s1[atoi(s4[i])-1]),atof(s2[atoi(s4[i])-1]),atof(s3[atoi(s4[i])-1]));


    if (Couleur==1)
    {
    if (atof(s3[atoi(s5[i])-1])<((s3max+2*s3min)/3))
    glColor3d(0,(3/(s3max-s3min))*atof(s3[atoi(s5[i])-1])-3*s3min/(s3max-s3min),1);
    if (atof(s3[atoi(s5[i])-1])>((2*s3max+s3min)/3))
    glColor3d(1,(3/(s3min-s3max))*atof(s3[atoi(s5[i])-1])+3*s3max/(s3max-s3min),0);
    else glColor3d((3/(s3min-s3max))*atof(s3[atoi(s5[i])-1])+(2*s3min+s3max)/(s3min-s3max),1,(3/(s3min-s3max))*atof(s3[atoi(s5[i])-1])+(2*s3max-s3min)/(s3max-s3min));
    }
    glVertex3d(atof(s1[atoi(s5[i])-1]),atof(s2[atoi(s5[i])-1]),atof(s3[atoi(s5[i])-1]));


    if (Couleur==1)
    {
    if (atof(s3[atoi(s6[i])-1])<((s3max+2*s3min)/3))
    glColor3d(0,(3/(s3max-s3min))*atof(s3[atoi(s6[i])-1])-3*s3min/(s3max-s3min),1);
    if (atof(s3[atoi(s6[i])-1])>((2*s3max+s3min)/3))
    glColor3d(1,(3/(s3min-s3max))*atof(s3[atoi(s6[i])-1])+3*s3max/(s3max-s3min),0);
    else glColor3d((3/(s3min-s3max))*atof(s3[atoi(s6[i])-1])+(2*s3min+s3max)/(s3min-s3max),1,(3/(s3min-s3max))*atof(s3[atoi(s6[i])-1])+(2*s3max-s3min)/(s3max-s3min));
    }
    glVertex3d(atof(s1[atoi(s6[i])-1]),atof(s2[atoi(s6[i])-1]),atof(s3[atoi(s6[i])-1]));
    glEnd();
    }




    glDepthFunc(GL_LESS);

    SwapBuffers(hdc);

    }//if(NombreFacette==3)

    }

    }

    wglMakeCurrent(NULL, NULL) ;
    ::ReleaseDC (m_hWnd, hdc) ;
    wglDeleteContext(hglrc);



    }
    void COpenGL::initOpengl()
    { glClearDepth(1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(anglepersp,1,0.00000001,1000);
    gluLookAt(axex,axey,axez,objx,objy,objz,0,1,0);
    //glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Remobing Hidden Surfaces

    gluPerspective(anglepersp,1,0.00000001,1000);
    Here's your problem. With that near:far ratio, you are more or less making the depth buffer useless.

    The near:far ratio is calculated as far/near, where near and far are the last two values in the call to gluPerspective. For good depth buffer precision, the ratio should not exceed 10000 for 24-bit depth buffer, and 1000 for 16 bit ones. Your ratio is WAY too large.

    Set the near clip plane to 1 or 0.1 instead.

  9. #9
    Guest

    Re: Remobing Hidden Surfaces

    It worked=)
    Thank you very much

Similar Threads

  1. How to tell if a 3D point will be hidden
    By bigefrom84 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-22-2013, 01:36 PM
  2. 3D object draw/hidden surfaces .....
    By Irena in forum OpenGL: Basic Coding
    Replies: 26
    Last Post: 02-12-2010, 02:11 PM
  3. how to get the data of hidden-surfaces ????
    By marshallcp in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-01-2006, 11:47 AM
  4. how to get the data of hidden-surfaces from depth buffer????
    By marshallcp in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-26-2006, 11:23 PM
  5. OGL - Hidden Surfaces (Depth Buffer)
    By Spaceman in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-23-2000, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean