using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;

using Tao.OpenGl;

namespace Ornek2020
{
    class Texture
    {
        public uint[] TextureArray = new uint[32];

        // Load Bitmaps And Convert To Textures
        public void LoadGlTexture(string filename, int TextureArray_num)
        {
            // Load Texture
            Bitmap image = new Bitmap(filename);
            Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
            BitmapData imageData = image.LockBits(rect, ImageLockMode.ReadOnly, 
                PixelFormat.Format24bppRgb);
            
            // Create Texture
            Gl.glGenTextures(1, out TextureArray[TextureArray_num]);
            
            // 2d TextureArray (x and y size)
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, TextureArray[TextureArray_num]);

            // scale linearly when image bigger than TextureArray
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);

            // scale linearly when image smalled than TextureArray
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);

            // 2d TextureArray, level of detail 0 (normal), 3 components
            // (red, green, blue), x size from image, y size from image,
            // border 0 (normal), rgb color data, unsigned byte data, and
            // finally the data itself.
            Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 3, 
                image.Width, image.Height, 0,
                Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, imageData.Scan0);
        }
    }
}
