Results 1 to 5 of 5

Thread: Having a problem with depth testing.

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2007
    Location
    NH
    Posts
    5

    Having a problem with depth testing.

    HI;
    i have written a program for the graphics class i'm in. it is a sun with planets rotating around it and moons rotating around the planet. my problem is this... when the planets are go behind the sun from the camera perspective they are larger and appear to be closer than when they pass in front of the sun. any idea what the problem might be? the camera class i'm using is very similar to the one on my text book's website. here is the link to the book's source.
    thttp://www.fshilljr.com/ch7source.zip

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Having a problem with depth testing.

    Make sure you request and really get a framebuffer with depth buffer.
    Enable depth testing.

    Voilą.

    EDIT: ie. with glut, init your window like this :
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2007
    Location
    NH
    Posts
    5

    Re: Having a problem with depth testing.

    actually i am using that call. here is the code in Main()

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA |GLUT_DEPTH);
    glutInitWindowSize(ScreenWidth, ScreenHeight);
    glutInitWindowPosition(110, 0);
    glutCreateWindow("SolSys Test");
    glutKeyboardFunc(myKeyboard);
    glutDisplayFunc(RenderScene);
    glClearColor(0.0f, 0.0f, 0.0f, 01.0f);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glColor3f(0,0,0);
    glEnable(GL_DEPTH_TEST);
    glViewport(0,0,ScreenWidth, ScreenHeight);
    glutIdleFunc(RenderScene);
    l1.CreateLight();
    l2.CreateLight();
    l3.CreateLight();
    cam.Set(0,50,25,0,0,0,0,1,1);
    cam.SetShape(30.0f,1, -10,10);
    glutMainLoop();

    I have classes that handle the camera, light, planets and moons. the program is also setup to toggle the lights on and off, move the camera, change the speed application and toggle between alpha blending and depth testing. here is my RenderScene method.

    void RenderScene(void)
    {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//

    //draw the sun
    glPushMatrix();
    {
    glRotated(-SolarDay, 0,0,1);
    glTranslated(0,0,0);
    glutSolidSphere(2,20,20);
    }
    glPopMatrix();

    //apply the time multiplier to the planets and moons
    p1.SetTimeMulti(nSpeedMultiplier);
    p2.SetTimeMulti(nSpeedMultiplier);
    p3.SetTimeMulti(nSpeedMultiplier);
    p4.SetTimeMulti(nSpeedMultiplier);
    m1.SetTimeMulti(nSpeedMultiplier);
    m2.SetTimeMulti(nSpeedMultiplier);
    m3.SetTimeMulti(nSpeedMultiplier);
    m4.SetTimeMulti(nSpeedMultiplier);
    m5.SetTimeMulti(nSpeedMultiplier);

    //draw the planets and moons++
    m1.Draw();
    m2.Draw();
    m3.Draw();
    m4.Draw();
    m5.Draw();
    p1.Draw();
    p2.Draw();
    p3.Draw();
    p4.Draw();

    SolarDay += .004 * nSpeedMultiplier; //25 earth day = 1 solar day
    glFlush();
    glutSwapBuffers();
    }

  4. #4
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Having a problem with depth testing.

    Code :
    cam.SetShape(30.0f,1, -10,10);
    Based on your camera code this call will send negative near plane distance to gluPerspective which expects the value to always be positive.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2007
    Location
    NH
    Posts
    5

    Re: Having a problem with depth testing.

    Thanks That did the trick.

Similar Threads

  1. Depth testing problem using glOrtho
    By Tranqui in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-05-2012, 11:07 AM
  2. Stencil-op depth fail with depth testing disabled
    By AvCol in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-22-2011, 09:48 PM
  3. Problem with depth-testing
    By dunken69 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-17-2002, 03:59 AM
  4. Depth Testing Problem
    By plates in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-02-2002, 12:37 AM
  5. Depth Testing Problem
    By Chris Brown in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-30-2001, 04:39 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