예제 #1
0
        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);
        }
예제 #2
0
		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 = new NSDictionary (GLKTextureLoader.OriginBottomLeft, true);

			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);
		}