void setupGL()
        {
            EAGLContext.SetCurrentContext(context);

            effect = new GLKBaseEffect();
            effect.LightingType = GLKLightingType.PerPixel;

            effect.Light0.Enabled      = true;
            effect.Light0.DiffuseColor = new Vector4(1.0f, 0.4f, 0.4f, 1.0f);

            GL.Enable(EnableCap.DepthTest);

            GL.Oes.GenVertexArrays(1, out vertexArray);
            GL.Oes.BindVertexArray(vertexArray);

            GL.GenBuffers(1, out vertexBuffer);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Monkey.MeshVertexData.Length * sizeof(float)),
                          Monkey.MeshVertexData, BufferUsage.StaticDraw);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.Position);
            GL.VertexAttribPointer((int)GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float,
                                   false, 8 * sizeof(float), 0);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.Normal);
            GL.VertexAttribPointer((int)GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float,
                                   false, 8 * sizeof(float), 12);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.TexCoord0);
            GL.VertexAttribPointer((int)GLKVertexAttrib.TexCoord0, 2, VertexAttribPointerType.Float,
                                   false, 8 * sizeof(float), 24);

            GL.ActiveTexture(TextureUnit.Texture0);
            string path = NSBundle.MainBundle.PathForResource("monkey", "png");

            NSError      error;
            NSDictionary options = NSDictionary.FromObjectAndKey(NSNumber.FromBoolean(true),
                                                                 GLKTextureLoader.OriginBottomLeft);

            texture = GLKTextureLoader.FromFile(path, options, out error);

            if (texture == null)
            {
                Console.WriteLine(String.Format("Error loading texture: {0}", error.LocalizedDescription));
            }

            GLKEffectPropertyTexture tex = new GLKEffectPropertyTexture();

            tex.Enabled = true;
            tex.EnvMode = GLKTextureEnvMode.Decal;
            tex.GLName  = texture.Name;

            effect.Texture2d0.GLName = tex.GLName;

            GL.Oes.BindVertexArray(0);
        }
Esempio n. 2
0
        void setupGL()
        {
            EAGLContext.SetCurrentContext(context);

            effect = new GLKReflectionMapEffect();
            effect.LightingType = GLKLightingType.PerPixel;

            skyboxEffect = new GLKSkyboxEffect();

            effect.Light0.Enabled       = true;
            effect.Light0.DiffuseColor  = new Vector4(1f, 1f, 1f, 1f);
            effect.Light0.Position      = new Vector4(-1f, -1f, 2f, 1f);
            effect.Light0.SpecularColor = new Vector4(1f, 1f, 1f, 1f);
            effect.Light0.AmbientColor  = new Vector4(0.2f, 0.2f, 0.2f, 1f);

            effect.Light1.Enabled       = true;
            effect.Light1.DiffuseColor  = new Vector4(0.4f, 0.4f, 0.4f, 1f);
            effect.Light1.Position      = new Vector4(15f, 15f, 15f, 1f);
            effect.Light1.SpecularColor = new Vector4(1f, 0f, 0f, 1f);

            effect.Material.DiffuseColor  = new Vector4(1f, 1f, 1f, 1f);
            effect.Material.AmbientColor  = new Vector4(1f, 1f, 1f, 1f);
            effect.Material.SpecularColor = new Vector4(1f, 0f, 0f, 1f);
            effect.Material.Shininess     = 320f;
            effect.Material.EmissiveColor = new Vector4(0.4f, 4f, 0.4f, 1f);

            GL.Enable(EnableCap.DepthTest);

            GL.Oes.GenVertexArrays(1, out vertexArray);
            GL.Oes.BindVertexArray(vertexArray);

            GL.GenBuffers(1, out vertexBuffer);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Monkey.MeshVertexData.Length * sizeof(float)),
                          Monkey.MeshVertexData, BufferUsage.StaticDraw);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.Position);
            GL.VertexAttribPointer((int)GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float,
                                   false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray((int)GLKVertexAttrib.Normal);
            GL.VertexAttribPointer((int)GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float,
                                   false, 6 * sizeof(float), 12);

            string[] cubeMapFiles =
            {
                NSBundle.MainBundle.PathForResource("cubemap1", "png"),
                NSBundle.MainBundle.PathForResource("cubemap2", "png"),
                NSBundle.MainBundle.PathForResource("cubemap3", "png"),
                NSBundle.MainBundle.PathForResource("cubemap4", "png"),
                NSBundle.MainBundle.PathForResource("cubemap5", "png"),
                NSBundle.MainBundle.PathForResource("cubemap6", "png")
            };

            NSError      error;
            NSDictionary options = new NSDictionary(GLKTextureLoader.OriginBottomLeft, false);

            cubemap = GLKTextureLoader.CubeMapFromFiles(cubeMapFiles, options, out error);

            effect.TextureCubeMap.GLName       = cubemap.Name;
            skyboxEffect.TextureCubeMap.GLName = cubemap.Name;

            GL.Oes.BindVertexArray(0);
        }