O
O
OlegTar2012-12-22 23:05:28
3D
OlegTar, 2012-12-22 23:05:28

z-order not working in opengl?

I am writing a program in C #, where there is a certain cube. I am using the opentk library for opengl.
The problem is that which edge I draw later, that one will be visible to the user. That is, as if there is no z-order.
Here are the pieces of code:

/*определение переменных*/
int zNear = 1;
int zFar = 500;

float viewX = 61;
float viewY = 61;
float viewZ = 61;

...
/*настройка opengl*/
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

Matrix4 p = Matrix4.CreatePerspectiveFieldOfView((float)(viewAngle * Math.PI / 180), 1, zNear, zFar);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref p);

Matrix4 look = Matrix4.LookAt(viewX, viewY, viewZ, 0, 0, 0, 0, 1, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref look);

...
/*рисование кубика*/
GL.PushMatrix();
/*разные вращения кубика*/
GL.Translate(offset, offset, offset);
GL.Rotate(angle.X, Vector3.UnitX);
GL.Translate(-offset, -offset, -offset);

/*рисование граней*/
GL.Begin(BeginMode.Polygon);
GL.Vertex3(0, 0, 0);
GL.Vertex3(0, 0, w);
GL.Vertex3(w, 0, w);
GL.Vertex3(w, 0, 0);
GL.End();
//и т.д.

GL.PopMatrix();

What is wrong? Googling didn't help.
The solution needs to be added:
GL.Enable(EnableCap.DepthTest);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Matrozov, 2012-12-22
@OlegTar

As far as I remember, you need to dig towards GL.Enable(DepthTest);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question