mcb_'s picture

Translate Z axis does not work as expected

Hello all,
I can translate along z axis but object looks same every time, it should be little or bigger according to its position on z axis.but its not working.

     public void RenderToPanel()
        {
            int T_NewTranslate;
            long time;
            bool countEnd = false;
            winfo = Utilities.CreateWindowsWindowInfo(windowHandle); // Similar methods exist for X11 and Carbon
            context = new GraphicsContext(GraphicsMode.Default, winfo);
            context.MakeCurrent(winfo);
            context.LoadAll();
            float alpha = 0.9f,T_MoveX;
 
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.DepthRange(0.0f, 1.0f);
 
            GL.Viewport(0, 0, Render_width, Render_height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            //GL.Ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
            GL.Frustum(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
 
            GL.Rotate(10f, 1.0f, 1.0f, 0.5f);
            time = DateTime.Now.Ticks;
            while ((!KillRenderThread)&(!countEnd))
            {
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                T_NewTranslate = NewTranslate;
                T_MoveX = MoveX;
                if (T_NewTranslate == 1)
                {
                    T_NewTranslate = 0;
                    NewTranslate = 0;
                    GL.Translate(0.0f,0.0f, T_MoveX);
                }
               // GL.Rotate(alpha, 1.0, 1.0, 0.5);
 
                GL.Begin(PrimitiveType.Quads);
 
                GL.Color3(1.0f, 0.0f, 0.0f);
                GL.Vertex3(0.2f, 0.2f, 0.2f);
                GL.Vertex3(-0.2f,0.2f, 0.2f);
                GL.Vertex3(-0.2f,0.2f, -0.2f);
                GL.Vertex3(0.2f, 0.2f, -0.2f);
 
                GL.Color3(0.0f, 1.0f, 0.0f);
                GL.Vertex3(0.2f,-0.2f, 0.2f);
                GL.Vertex3(-0.2f,-0.2f, 0.2f);
                GL.Vertex3(-0.2f,-0.2f, -0.2f);
                GL.Vertex3(0.2f, -0.2f, -0.2f);
 
                GL.Color3(1.0f, 1.0f, 0.0f);
                GL.Vertex3(0.2f, -0.2f, 0.2f);
                GL.Vertex3(-0.2f, -0.2f,0.2f);
                GL.Vertex3(-0.2f, 0.2f, 0.2f);
                GL.Vertex3(0.2f, 0.2f, 0.2f);
 
                GL.Color3(0.0f, 0.0f, 1.0f);
                GL.Vertex3( 0.2f, -0.2f, -0.2f);
                GL.Vertex3(-0.2f, -0.2f, -0.2f);
                GL.Vertex3(-0.2f, 0.2f, -0.2f);
                GL.Vertex3( 0.2f, 0.2f, -0.2f);
 
 
                GL.Color3(1.0f, 0.0f, 1.0f);
                GL.Vertex3(0.2f, 0.2f, -0.2f);
                GL.Vertex3(0.2f, 0.2f, 0.2f);
                GL.Vertex3(0.2f, -0.2f, 0.2f);
                GL.Vertex3(0.2f, -0.2f, -0.2f);
 
                GL.Color3(0.0f, 1.0f, 1.0f);
                GL.Vertex3(-0.2f, 0.2f, -0.2f);
                GL.Vertex3(-0.2f, 0.2f, 0.2f);
                GL.Vertex3(-0.2f, -0.2f, 0.2f);
                GL.Vertex3(-0.2f, -0.2f, -0.2f);
                //alpha = alpha + (float)0.1;
                GL.End();
 
                GL.Begin(PrimitiveType.Lines);
                GL.Color3(1.0f, 0.0f, 0.0f);
                GL.Vertex3(0.0f, 0.0f, -1.0f);
                GL.Vertex3(0.0f, 0.0f, 1.0f);
 
                GL.Color3(0.0f, 1.0f, 0.0f);
                GL.Vertex3(-1.0f, 0.0f, 0.0f);
                GL.Vertex3(1.0f, 0.0f, 0.0f);
 
                GL.Color3(0.0f, 0.0f, 1.0f);
                GL.Vertex3(0.0f, -1.0f, 0.0f);
                GL.Vertex3(0.0f, 1.0f, 0.0f);
                GL.End();
                GL.Flush();
 
                context.SwapBuffers();
                int iX = 20;
                Thread.Sleep(iX);
            }
            context.Dispose();
            button1.BeginInvoke(new MethodInvoker(delegate { button1.Text = time.ToString(); }));
        }

How can i solve this problem.


Comments

Comment viewing options

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

I think these two lines left, after GL.Frustum()

GL.Viewport(0, 0, Render_width, Render_height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            //GL.Ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
            GL.Frustum(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
            // I think these two lines left
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();