Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

[OpenTK] Texture Mapping

$
0
0

Hi all, I am quite new in Android development but I have a little bit experience about using OpenTK in C#.. I just want to render the 2D Image from Bitmap file that stored in Asset using Texture Mapping method

But I was realized, there aren't BitmapData class, usually, I am using LockBits method to Texture Mapping here the code to Bind the texture that working on Windows Forms Application:

        Bitmap bitmap = new Bitmap("logo.jpg");
        int texture;

        GL.ClearColor(Color.White);
        GL.Enable(EnableCap.Texture2D);

        GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

        GL.GenTextures(1, out texture);
        GL.BindTexture(TextureTarget.Texture2D, texture);

        BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
            ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
            OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

        bitmap.UnlockBits(data);

        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

and to draw it, I am using this code (that working smoothly in Windows Form Application) :

        GL.Clear(ClearBufferMask.ColorBufferBit);

        GL.MatrixMode(MatrixMode.Modelview);
        GL.LoadIdentity();
        GL.BindTexture(TextureTarget.Texture2D, texture);

        GL.Begin(BeginMode.Quads);

        GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-0.6f, -0.4f);
        GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(0.6f, -0.4f);
        GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(0.6f, 0.4f);
        GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-0.6f, 0.4f);

        GL.End();

        SwapBuffers();

As you can see, at the binding code it using LockBits and UnlockBits

but back to the question.. how I can do texture mapping? (can you provide the code too? XD )

Thanks and sorry for my bad English


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>