2
votes

I'm working on a very simple program that draws 2 planes. A ground plane and a back ground plane.

I'm attempting to draw both planes using these points ordered in X, Y, Z coordinates.

background plane

  • point 1 100.000002 100.000002 100.000002
  • point 2 -100.000002 100.000002 100.000002
  • point 3 -50.000001 -23.000001 100.000002
  • point 4 50.000001 -23.000001 100.000002

ground plane

  • point 1 -50.000001 -23.000001 100.000002
  • point 2 50.000001 -23.000001 100.000002
  • point 3 0.352941 -0.352941 0.352941
  • point 4 -0.352941 -0.352941 0.352941

My GL Setup:

  • OpenGL lighting is off.
  • I'm drawing with GL_QUAD in the order the points are listed.
  • I have not assigned surface normals to the quads.
  • Camera is centered at (0,0,0) with the Y+ as "up" and the Z axis as depth.

The ground plane renders perfectly (just a sheet of gray), but the background plane isn't rendering at all. So I have to ask:

  • Should I turn on lighting and compute surface normals?
  • Do I need to fiddle with the camera and/or view frustrum to see the back plane (does OpenGL "drop off" at a distance of Z = 100+)?

Any help is appreciated. I'm using libSDL with OpenGL.

My OpenGL initialization code looks like this:

if(SDL_Init(SDL_INIT_VIDEO) < 0) {
    return false;
}

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);   

screenptr = SDL_SetVideoMode(swidth, sheight, sbpp, VIDEO_MODE_OPTIONS);

if( screenptr == NULL) {
    return false;
}

glEnable(GL_TEXTURE_2D);

glClearColor(0,0,0,0);
glClearDepth(1.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); 
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(45.0f, SCREEN_WIDTH/SCREEN_HEIGHT, 0.1f, 500.0f);
//gluPerspective( 45.0f, 1.0, 0.1f, 100.0f );
//glFrustum(-500.0f, 500.0f, -500.0f, 500.f, 0.1f, 500.f);
//glFrustum(-1.0, 1.0, -1.0, 1.0, 5, 400);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

if(glGetError() != GL_NO_ERROR) {
    return false;
}
2
I would guess that your far clipping plane is set at 100? - Bart

2 Answers

4
votes

You need to take a look at where you create your camera matrix (a call to glPerspective or something similar, I haven't used SDL) and set the near and far-plane to a value such that everything that you want a user to see is further away as the near plane, but closer as the far plane. Everything that is not in between the near and far plane is clipped.

Edit I looked it up, in SDL you create the view matrix like this:

/* Create our projection matrix with a 45 degree field of view
 * a width to height ratio of 1.0 and view from .1 to 100 infront of us */
perspective(projectionmatrix, 45.0, 1.0, 0.1, 100.0);

Don't ever set the near plane to 0 (will result in a devision by zero exception) or the far plane to Float.Max (might cause weird problems)

Also take a look at this view frustum picture for a perspective projection: view frustum

2
votes

How are you setting up your projection matrix? It should include some information about how far aware things can be rendered (often called the far plane distance), in your case you need this to be more than 100.

The second problem it could be is that if you are only rendering front-facing quads, then if your quad is back-facing it won't be rendered.