Why does calling the perspective function leave me with a black screen?

haskell, opengl

Solution

The default projection/viewing volume is orthographic (actually a cube), with the centre at the origin. In a perspective projection, all viewing rays converge to the origin, which is behind the near plane. Since you're origin is on the plane your're drawing, all the vertices will form a line on the screen and won't produce any fragments. As KarolisJuodelė says, adjust the `lookAt` function so that the camera is not on the plane...

Problem

I am using Haskell and OpenGL to construct a 3D terrain. The terrain and lighting are fine, but I am running into some difficulties adjusting the camera / view. When I run the following code in my `display` function: ``` matrixMode $= Projection loadIdentity -- perspective 45 1 0.1 100 matrixMode $= ModelView 0 loadIdentity lookAt (Vertex3 0 0 0) (Vertex3 0 1 2) (Vector3 0 1 0) ``` I receive the following image: But when I uncomment the line ``` perspective 45 1 0.1 100 ``` I just get a black screen. My point array is quite large but here are the last few points copied from `ghci`: (1.0,0.0,0.76), (1.0,0.0,0.8), (1.0,0.0,0.84), (1.0,0.0,0.88), (1.0,0.0,0.92), (1.0,0.0,0.96), (1.0,0.0,1.0) I feel as though: - I specify the perspective planes incorrectly? or... - I should not be repeatedly calling one or more of these functions?

Original source