Hello

I have been trying to develop a simple OpenGL ES1.1 application using Mono
for Android. While building upon the template OpenGL application available
in Visual Studio, I came across some weird behaviour in OpenGL, the
GL.Translate function doesnt seem to do any translation in Z axis and I
cannot setup a perspective using GL.Frustum, I have tried code given below
on Samsung Galaxy S2 and Galaxy Tablet and the results were the same; No
translation available in Z axis. Translation in X and Y axises work fine
though. the only problem I can think of is something is wrong in OpenTK or
it is a mono for android related problem

Can anybody help me with solving this GL.Translate and Perspective problems
I have?

Thanks you very much
Batu Akan


-------------------------------------------
using System;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.ES11;
using OpenTK.Platform;
using OpenTK.Platform.Android;

using Android.Views;
using Android.Content;

namespace OpenGLTest
{
    class GLView1 : AndroidGameView
    {
        public GLView1(Context context)
            : base(context)
        {
        }

        // This gets called when the drawing surface is ready
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Run the render loop
            Run();
        }


        float z = 0;
        // This gets called on each frame render
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            MakeCurrent();

            GL.MatrixMode(All.Projection);
            GL.LoadIdentity();
            GL.Ortho(-1.0f, 1.0f, -1.5f, 1.5f, -10.0f, 10.0f);
            //If I disable the Ortho Command and enable the Perspective
command I should get
            //perspective but nothing really changes
            //Perspective(50.0f, (float)(Width)/(float)(Height), -0.1f,
300.0f);
            GL.MatrixMode(All.Modelview);
            GL.LoadIdentity();
            GL.PushMatrix();
            //With the two lines below the cube should move away from the
viewer,
            //but nothing happens until z reaches -10.0 and then the cube
disappears alltogether
            GL.Translate(0.0f, 0.0f, z);
            z = z - 0.05f;
            GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            GL.Clear((uint)All.ColorBufferBit);

            GL.VertexPointer(3, All.Float, 0, CubeVertices);
            GL.EnableClientState(All.VertexArray);
            GL.ColorPointer(4, All.UnsignedByte, 0, square_colors);
            GL.EnableClientState(All.ColorArray);

            GL.DrawElements(All.LineStrip, 36, All.UnsignedShort,
CubeElements);
            GL.PopMatrix();
            SwapBuffers();
        }


        public void Perspective(float fovy, float aspect, float zNear, float
zFar)
        {
            float xmin, xmax, ymin, ymax;

            ymax = zNear * (float)Math.Tan(fovy * Math.PI / 360.0);
            ymin = -ymax;
            xmin = ymin * aspect;
            xmax = ymax * aspect;
            GL.Frustum(xmin, xmax, ymin, ymax, zNear, zFar);
            GL.MatrixMode(All.Modelview);
            GL.Hint(All.PerspectiveCorrectionHint, All.Nicest);
            GL.DepthMask(true);
        }

        float[] CubeVertices = new float[]
        {
                -1.0f, -1.0f,  1.0f,
                1.0f, -1.0f,  1.0f,
                1.0f,  1.0f,  1.0f,
                -1.0f,  1.0f,  1.0f,
                -1.0f, -1.0f, -1.0f,
                1.0f, -1.0f, -1.0f,
                1.0f,  1.0f, -1.0f,
                -1.0f,  1.0f, -1.0f
        };

        ushort[] CubeElements = new ushort[]
        {
            0, 1, 2, 2, 3, 0, // front face
            3, 2, 6, 6, 7, 3, // top face
            7, 6, 5, 5, 4, 7, // back face
            4, 0, 3, 3, 7, 4, // left face
            0, 1, 5, 5, 4, 0, // bottom face
            1, 5, 6, 6, 2, 1, // right face
        };

        byte[] square_colors = {
            255, 255,   0, 255,
            0,   255, 255, 255,
            0,     0,    0,  0,
            255,   0,  255, 255,
            255, 255,   0, 255,
            0,   255, 255, 255,
            0,     0,    0,  0,
            255,   0,  255, 255,
        };
    }
}
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to