title: Texturing triangles
body: <p>I am trying to texture triangle with OpenTK ES with this code</p>
  
  <pre><code>using System;
  using OpenTK;
  using OpenTK.Graphics.ES11;
  using OpenTK.Platform.Android;
  using Android.Content;
  
  namespace TexturedTriangle
  {
      class GLView1  AndroidGameView
      {
          public GLView1(Context context)  base(context)
          { }
          protected override void CreateFrameBuffer()
          {
              base.CreateFrameBuffer();
          }
  
  
          Vector2[] TexCoords =
          {
              new Vector2(0, 0),
              new Vector2(1, 0),
              new Vector2(0, 1),
          };
          Vector2[] Vertices =
          {
              new Vector2(0f, 0f),
              new Vector2(1f, 0f),
              new Vector2(0f, 1f),
          };
          int[] Tex = new int[1];
          int[] VBOs = new int[2];
          protected override void OnLoad(EventArgs e)
          {
              base.OnLoad(e);
  
              GL.ClearColor(0, 0, 0, 1f);
              GL.Clear((int)All.ColorBufferBit);
  
              GL.MatrixMode(All.Projection);
              GL.LoadIdentity();
              GL.MatrixMode(All.Modelview);
              GL.LoadIdentity();
  
              GL.Enable(All.Texture2D);
  
  
              GL.GenBuffers(2, VBOs);
  
              GL.BindBuffer(All.ArrayBuffer, VBOs[0]);
              GL.BufferData(All.ArrayBuffer,
                            new IntPtr(Vertices.Length  Vector2.SizeInBytes),  
                            Vertices, All.StaticDraw);
  
              GL.BindBuffer(All.ArrayBuffer, VBOs[1]);
              GL.BufferData(All.ArrayBuffer,
                            new IntPtr(TexCoords.Length  Vector2.SizeInBytes), 
                            TexCoords, All.StaticDraw);
  
              int[] Data = new int[32  32];
  
              for (int I = 0; I  32  32; I++)
              {
                  if (I % 3 == 0) Data[I] = 255;
                  if (I % 3 == 1) Data[I] = 65280;
                  if (I % 3 == 2) Data[I] = 16711680;
              }
  
              GL.GenTextures(1, Tex);
  
              GL.BindTexture(All.Texture2D, Tex[0]);
  
              GL.TexParameter(All.Texture2D, All.TextureMinFilter, 
                              (int)All.Nearest);
              GL.TexParameter(All.Texture2D, All.TextureMagFilter,    
                              (int)All.Nearest);
  
              GL.TexImage2D(All.Texture2D, 0, 3, 32, 32, 0, All.Rgba, 
                            All.UnsignedByte, Data);
  
              GL.EnableClientState(All.VertexArray);
              GL.EnableClientState(All.TextureCoordArray);
  
              Run();
          }
          protected override void OnRenderFrame(FrameEventArgs e)
          {
              base.OnRenderFrame(e);
  
              GL.BindBuffer(All.ArrayBuffer, VBOs[0]);
              GL.VertexPointer(2, All.Float,                                                 
                               BlittableValueType.StrideOf(Vertices)  
                               IntPtr.Zero);
  
              GL.BindBuffer(All.ArrayBuffer, VBOs[1]);
              GL.TexCoordPointer(2, All.Float,                    
                                 BilittableValueType.StrideOf(TexCoords),
                                 IntPtr.Zero);
  
              GL.DrawArrays(All.Triangles, 0, 3);
  
              SwapBuffers();
          }
      }
  }
  </code></pre>
  
  <p>But there is only a white triangle</p>
  
  <p><a href="http://i.stack.imgur.com/9Gq3L.png" rel="nofollow">Textured triangle OpenGL ES</a></p>
  
  <p>Meanwhile this code:</p>
  
  <pre><code>using System;
  using OpenTK;
  using OpenTK.Graphics;
  using OpenTK.Graphics.OpenTK;
  
  namespace TexturedTriangle
  {
      class Program
      {
          static void Main()
          {
              GameWindow Window = new GameWindow(512, 512, GraphicsMode.Default, "Textured Triangle");
              int[] Tex = new int[1];
              int[] VBOs = new int[2];
  
              Vector2[] TexCoords =
              {
                  new Vector2(0, 0),
                  new Vector2(1, 0),
                  new Vector2(0, 1),
              };
  
              Vector2[] Vertices =
              {
                  new Vector2(0f, 0f),
                  new Vector2(1f, 0f),
                  new Vector2(0f, 1f),
              };
              Window.Load += (sender, e) =&gt;
              {
                  GL.ClearColor(0, 0, 0, 1f);
                  GL.Clear(ClearBufferMask.ColorBufferBit);
  
                  GL.MatrixMode(MatrixMode.Projection);
                  GL.LoadIdentity();
                  GL.MatrixMode(MatrixMode.Modelview);
                  GL.LoadIdentity();
  
                  GL.Enable(EnableCap.Texture2D);
  
  
                  GL.GenBuffers(2, VBOs);
  
                  GL.BindBuffer(BufferTarget.ArrayBuffer, VBOs[0]);
                  GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(Vertices.Length * Vector2.SizeInBytes), Vertices, BufferUsageHint.StaticDraw);
  
                  GL.BindBuffer(BufferTarget.ArrayBuffer, VBOs[1]);
                  GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(TexCoords.Length * Vector2.SizeInBytes), TexCoords, BufferUsageHint.StaticDraw);
  
                  int[] Data = new int[32 * 32];
  
                  for (int I = 0; I &lt; 32 * 32; I++)
                  {
                      if (I % 3 == 0) Data[I] = 255;       
                      if (I % 3 == 1) Data[I] = 65280;     
                      if (I % 3 == 2) Data[I] = 16711680;  
                  }
  
                  GL.GenTextures(1, Tex);
  
                  GL.BindTexture(TextureTarget.Texture2D, Tex[0]);
  
                  GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                  GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
  
                  GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Three, 32, 32, 0, PixelFormat.Rgba, PixelType.UnsignedByte, Data);
  
                  GL.EnableClientState(ArrayCap.VertexArray);
                  GL.EnableClientState(ArrayCap.TextureCoordArray);
              };
              Window.RenderFrame += (sender, e) =&gt;
              {
                  GL.Clear(ClearBufferMask.ColorBufferBit);
  
  
                  GL.BindBuffer(BufferTarget.ArrayBuffer, VBOs[0]);
                  GL.VertexPointer(2, VertexPointerType.Float, BlittableValueType.StrideOf(Vertices), IntPtr.Zero);
  
                  GL.BindBuffer(BufferTarget.ArrayBuffer, VBOs[1]);
                  GL.TexCoordPointer(2, TexCoordPointerType.Float, BlittableValueType.StrideOf(TexCoords), IntPtr.Zero);
  
                  GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
  
  
                  Window.SwapBuffers();
              };
  
              Window.Run();
          }
      }
  }
  </code></pre>
  
  <p>Works and output is</p>
  
  <p><a href="http://i.stack.imgur.com/RG6HW.png" rel="nofollow">Textured triangle OpenTK</a></p>
  
  <p>After GL.TexImage2D();</p>
  
  <p>GL.GetError(); gives InvalidValue</p>
  
  <p>Documentation: www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml</p>
  
  <p>What the problem can be?</p>