Kubajzz's picture

Simple problem with z-order of faces

Hi everybody,

I'm pretty new to OpenTK and OpenGL in general, so please be patient.

I wanted to create a simple program, based on the "Building a Windows.Forms + GLControl based application" tutorial. I pretty much followed the whole tutorial, except for I set up a perspective view using Gl.Frustum().

Then I tried to add 2 polygons to the scene. One of the polygons is further from the view point and it appears smaller due to the perspective projection - everything is OK at this point. However, no matter which of the polygons is further, the one added later always appears on top (the z-order in the space is ignored). What am i doing wrong?

The polygon-building section is as simple as this:

      GL.Color3(Color.Yellow);
      GL.Begin(BeginMode.Polygon);
      GL.Vertex3(0.5, 0.5, 0);
      GL.Vertex3(-0.5, 0.5, 0);
      GL.Vertex3(-0.5, -0.5, 0);
      GL.Vertex3(0.5, -0.5, 0);
      GL.End();
      GL.Color3(Color.Red);
      GL.Begin(BeginMode.Polygon);
      GL.Vertex3(0.5, 0.5, -5);
      GL.Vertex3(-0.5, 0.5, -5);
      GL.Vertex3(-0.5, -0.5, -5);
      GL.Vertex3(0.5, -0.5, -5);
      GL.End();

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Is depth-testing enabled?

GL.Enable(EnableCap.DepthTest);
Kubajzz's picture

No, it was not enabled... But when enabled it, I can't see anything, just plain background color. Any ideas?

EDIT: I just found out why... Never mind, problem fixed. Thanks a lot!