Click here to Skip to main content
15,867,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All, I am new in Android application development but I had experience programming using C# with OpenTK

I just want to load texture 2D from bitmap (or other format) (texture mapping) image in Android OpenGL in Mono (I know it using OpenTK), and I am currently using Visual Studio

usually, I am load the bitmap for texture 2D with this code in windows form application, but I dont know how to do it in Android development (Especially bitmap constructor part):

C#
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 I am using this code on rendering part:

C#
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();


anyone can help me?
Thanks :D
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900