/********************************************************************************************************** * * * * Textures configuration function. * * * **********************************************************************************************************/ public void GenerateTextures(int texture) { GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glGenTextures(6, Textures); string[] imagesName = { "front" + texture + ".bmp", "back" + texture + ".bmp", "left" + texture + ".bmp", "right" + texture + ".bmp","top" + texture + ".bmp", "bottom" + texture + ".bmp", }; for (int i = 0; i < 6; i++) { Bitmap image = new Bitmap(imagesName[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[i]); //2D for XYZ GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); image.UnlockBits(bitmapdata); image.Dispose(); } }
void InitTexture(Bitmap i_Bitmap) { GL.glEnable(GL.GL_TEXTURE_2D); m_Texture = new uint[1]; // storage for texture Bitmap image = new Bitmap(i_Bitmap); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glGenTextures(1, m_Texture); GL.glBindTexture(GL.GL_TEXTURE_2D, m_Texture[0]); // VN-in order to use System.Drawing.Imaging.BitmapData Scan0 I've added overloaded version to // OpenGL.cs // [DllImport(GL_DLL, EntryPoint = "glTexImage2D")] // public static extern void glTexImage2D(uint target, int level, int internalformat, int width, int height, int border, uint format, uint type, IntPtr pixels); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); // Linear Filtering GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); // Linear Filtering image.UnlockBits(bitmapdata); image.Dispose(); }
void GenerateTextures() { Bitmap[] images = { myOpenGL.Properties.Resources.sea, myOpenGL.Properties.Resources.land, myOpenGL.Properties.Resources.wall, myOpenGL.Properties.Resources.whitewall, myOpenGL.Properties.Resources.horizon, myOpenGL.Properties.Resources.window, myOpenGL.Properties.Resources.lightbeam }; Textures = new uint[images.Length]; GL.glGenTextures(images.Length, Textures); for (int i = 0; i < images.Length; i++) { Bitmap image = images[i]; image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[i]); //2D for XYZ //The level-of-detail number. Level 0 is the base image level //The number of color components in the texture. //Must be 1, 2, 3, or 4, or one of the following // symbolic constants: // GL_ALPHA, GL_ALPHA4, // GL_ALPHA8, GL_ALPHA12, GL_ALPHA16, GL_LUMINANCE, GL_LUMINANCE4, // GL_LUMINANCE8, GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, // GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, // GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, // GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, // GL_INTENSITY16, GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, // GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, // GL_RGBA8, GL_RGB10_A2, GL_RGBA12, or GL_RGBA16. GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, //The width of the border. Must be either 0 or 1. //The format of the pixel data //The data type of the pixel data //A pointer to the image data in memory 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); image.UnlockBits(bitmapdata); image.Dispose(); } }
void GenerateTextures() { GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glGenTextures(9, Textures); string[] imagesName = { "kalahk.jpg", "divingsuit.jpg", "Wall_Texture_1_by_Insan_Stock.jpg", "stock-photo-old-brick-wall-texture-66007105.jpg", "stock-photo-old-brick-wall-texture-73022833.jpg", "Concrete_Basement_Wall_Texture_by_FantasyStock.jpg", "top.bmp", "stock-photo-185015-floor-texture-6.jpg", "Scared_face.jpg" }; GL.glGenTextures(6, Textures); //monster = new Milkshape.Character("kalahk.ms3d"); //diver = new Milkshape.Character("diver.ms3d"); //skip on the first two images for (int i = 2; i < 9; i++) { Bitmap image = new Bitmap(imagesName[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[i]); //2D for XYZ GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); if (i == 5) { GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_SPHERE_MAP); } else { GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); } image.UnlockBits(bitmapdata); image.Dispose(); } }
void InitTexture(string imageBMPfile) { GL.glEnable(GL.GL_TEXTURE_2D); Bitmap image = new Bitmap(imageBMPfile); image.RotateFlip(RotateFlipType.RotateNoneFlipY); System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glGenTextures(1, texture); GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0]); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); image.UnlockBits(bitmapdata); image.Dispose(); }
void InitTexture() { GL.glEnable(GL.GL_TEXTURE_2D); m_textureList = new uint[4]; // storage for texture string[] bmpFilesPath = new string[m_textureList.Length]; bmpFilesPath[0] = "../../Resources/noon.bmp"; bmpFilesPath[1] = "../../Resources/gimel.bmp"; bmpFilesPath[2] = "../../Resources/hei.bmp"; bmpFilesPath[3] = "../../Resources/pei.bmp"; GL.glGenTextures(m_textureList.Length, m_textureList); for (int i = 0; i < m_textureList.Length; i++) { Bitmap image = new Bitmap(bmpFilesPath[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards if (i == 0 || i == 3) // instead of drawing the texture in different way in drawSquareSurface, we flip here the texture { image.RotateFlip(RotateFlipType.RotateNoneFlipX); } Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); BitmapData bitmapData = image.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, m_textureList[i]); // VN-in order to use System.Drawing.Imaging.BitmapData Scan0 I've added overloaded version to // OpenGL.cs // [DllImport(GL_DLL, EntryPoint = "glTexImage2D")] // public static extern void glTexImage2D(uint target, int level, int internalformat, int width, int height, int border, uint format, uint type, IntPtr pixels); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapData.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); // Linear Filtering GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); // Linear Filtering image.UnlockBits(bitmapData); image.Dispose(); } }