private void LoadTexture(string filename, uint texture) { if (Il.ilLoadImage(filename)) //載入影像檔 { int BitsPerPixel = Il.ilGetInteger(Il.IL_IMAGE_BITS_PER_PIXEL); //取得儲存每個像素的位元數 int Depth = Il.ilGetInteger(Il.IL_IMAGE_DEPTH); //取得影像的深度值 Ilu.iluScale(512, 512, Depth); //將影像大小縮放為2的指數次方 Ilu.iluFlipImage(); //顛倒影像 Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); //連結紋理物件 //設定紋理參數 Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR); //建立紋理物件 if (BitsPerPixel == 24) { Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB, 512, 512, 0, Il.ilGetInteger(Il.IL_IMAGE_FORMAT), Il.ilGetInteger(Il.IL_IMAGE_TYPE), Il.ilGetData()); } if (BitsPerPixel == 32) { Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, 512, 512, 0, Il.ilGetInteger(Il.IL_IMAGE_FORMAT), Il.ilGetInteger(Il.IL_IMAGE_TYPE), Il.ilGetData()); } } else { // 若檔案無法開啟,顯示錯誤訊息 string message = "Cannot open file " + filename + "."; MessageBox.Show(message, "Image file open error!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void LoadTexture(string textureId, string path) { Random rand = new Random(); int devilId = 0; Il.ilGenImages(1, out devilId); Il.ilBindImage(devilId); // set as the active texture. if (!Il.ilLoadImage(path)) { System.Diagnostics.Debug.Assert(false, "Could not open file, [" + path + "]."); } Ilu.iluFlipImage(); int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); int openGLId = Ilut.ilutGLBindTexImage(); System.Console.WriteLine(width); System.Console.WriteLine(height); System.Console.WriteLine(openGLId); System.Console.WriteLine(devilId); System.Diagnostics.Debug.Assert(openGLId != 0); Il.ilDeleteImages(1, ref devilId); _textureDatabase.Add(textureId, new Texture(openGLId, width, height)); }
public void Save(string savename) { int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); Il.ilSetString(Il.IL_PNG_AUTHNAME_STRING, "Multiverse Network"); // stuff the data into the image if (bytesPerPixel == 2 && format == Il.IL_LUMINANCE) { // special case for 16 bit greyscale Il.ilTexImage(Width, Height, depth, 1, format, Il.IL_UNSIGNED_SHORT, buffer); } else { Il.ilTexImage(Width, Height, depth, (byte)bytesPerPixel, format, Il.IL_UNSIGNED_BYTE, buffer); } // flip the image so that the mosaics produced match what L3DT produces Ilu.iluFlipImage(); // save the image to file Il.ilEnable(Il.IL_FILE_OVERWRITE); Il.ilSaveImage(savename); // delete the image Il.ilDeleteImages(1, ref imageID); }
// TODO: Fix this to be like Ogre public override void EncodeToFile(Stream input, string fileName, object codecData) { int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); byte[] buffer = new byte[input.Length]; input.Read(buffer, 0, buffer.Length); ImageData data = (ImageData)codecData; ILFormat ilfmt = ILUtil.ConvertToILFormat(data.format); // stuff the data into the image Il.ilTexImage(data.width, data.height, 1, (byte)ilfmt.channels, ilfmt.format, ilfmt.type, buffer); if (data.flip) { // flip the image Ilu.iluFlipImage(); } // save the image to file Il.ilSaveImage(fileName); // delete the image Il.ilDeleteImages(1, ref imageID); }
public void LoadTexture(string textureId, int ImageType, byte[] imageData, int size = 0) { if (imageData == null) { throw new Exception(textureId + "提供的数据为无效数据"); } int devilId = 0; Il.ilGenImages(1, out devilId); Il.ilBindImage(devilId); //作为使用的纹理 if (!Il.ilLoadL(ImageType, imageData, size)) { System.Diagnostics.Debug.Assert(false, "给予的图像数据存在问题,请核对是否给予正确的图像数组和格式,以及大小"); } //The files we'll be using need to be flipped before passing to OpenGL Ilu.iluFlipImage(); int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); int openGLId = Ilut.ilutGLBindTexImage(); System.Diagnostics.Debug.Assert(openGLId != 0); Il.ilDeleteImages(1, ref devilId); try { _textureDatabase.Add(textureId, new Texture(openGLId, width, height)); } catch (Exception e) { string s = e.ToString(); } }
public TaoImage(string filename) { FileStream s = new FileStream(filename, FileMode.Open); int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); // create a temp buffer and write the stream into it byte[] tmpBuffer = new byte[s.Length]; s.Read(tmpBuffer, 0, tmpBuffer.Length); // load the data into DevIL Il.ilLoadL(Il.IL_PNG, tmpBuffer, tmpBuffer.Length); // check for an error int ilError = Il.ilGetError(); if (ilError != Il.IL_NO_ERROR) { throw new Exception(string.Format("Error while decoding image data: '{0}'", Ilu.iluErrorString(ilError))); } // flip the image so that the mosaics produced match what L3DT produces Ilu.iluFlipImage(); format = Il.ilGetInteger(Il.IL_IMAGE_FORMAT); bytesPerPixel = Math.Max(Il.ilGetInteger(Il.IL_IMAGE_BPC), Il.ilGetInteger(Il.IL_IMAGE_BYTES_PER_PIXEL)); Width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); Height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); depth = Il.ilGetInteger(Il.IL_IMAGE_DEPTH); // get the decoded data buffer = new byte[Width * Height * bytesPerPixel]; IntPtr ptr = Il.ilGetData(); // copy the data into the byte array unsafe { byte *pBuffer = (byte *)ptr; for (int i = 0; i < buffer.Length; i++) { buffer[i] = pBuffer[i]; } } // we won't be needing this anymore Il.ilDeleteImages(1, ref imageID); }
public void LoadTexture(string textureId, string path, string path2 = null) { int devilId = 0; Il.ilGenImages(1, out devilId); Il.ilBindImage(devilId); // set as the active texture. if (!Il.ilLoadImage(path)) { System.Diagnostics.Debug.Assert(false, "Could not open file, [" + path + "]."); } Ilu.iluFlipImage(); int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); int openGLId = Ilut.ilutGLBindTexImage(); System.Diagnostics.Debug.Assert(openGLId != 0); Il.ilDeleteImages(1, ref devilId); int?width2 = null; int?height2 = null; int?openGLId2 = null; //int devilId = 0; Il.ilGenImages(1, out devilId); Il.ilBindImage(devilId); // set as the active texture. if (path2 != null) { if (!Il.ilLoadImage(path2)) { System.Diagnostics.Debug.Assert(false, "Could not open file, [" + path2 + "]."); } Ilu.iluFlipImage(); width2 = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); height2 = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); openGLId2 = Ilut.ilutGLBindTexImage(); System.Diagnostics.Debug.Assert(openGLId2 != 0); Il.ilDeleteImages(1, ref devilId); } _textureDatabase.Add(textureId, new Texture(openGLId, width, height, openGLId2, width2, height2)); }
public override void EncodeToFile(Stream input, string outFileName, Codec.CodecData codecData) { int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); var buffer = new byte[input.Length]; input.Read(buffer, 0, buffer.Length); var imgData = (ImageData)codecData; PixelBox src; using (var bufHandle = BufferBase.Wrap(buffer)) { src = new PixelBox(imgData.width, imgData.height, imgData.depth, imgData.format, bufHandle); } try { // Convert image from Axiom to current IL image ILUtil.ConvertToIL(src); } catch (Exception ex) { LogManager.Instance.Write("IL Failed image conversion :", ex.Message); } // flip the image Ilu.iluFlipImage(); // save the image to file Il.ilSaveImage(outFileName); var error = Il.ilGetError(); if (error != Il.IL_NO_ERROR) { LogManager.Instance.Write("IL Error, could not save file: {0} : {1}", outFileName, Ilu.iluErrorString(error)); } Il.ilDeleteImages(1, ref imageID); }
public void LoadTexture(string textureId, string path) //载入纹理 { int devilId = 0; Il.ilGenImages(1, out devilId); Il.ilBindImage(devilId); //作为使用的纹理 if (!Il.ilLoadImage(path)) { System.Diagnostics.Debug.Assert(false, "Could not open file,[" + path + "]."); } //The files we'll be using need to be flipped before passing to OpenGL Ilu.iluFlipImage(); int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); int openGLId = Ilut.ilutGLBindTexImage(); System.Diagnostics.Debug.Assert(openGLId != 0); Il.ilDeleteImages(1, ref devilId); _textureDatabase.Add(textureId, new Texture(openGLId, width, height)); }
public static void SaveRawL32(string savename, int width, int height, uint[] buffer) { int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); fixed(uint *pbuf = buffer) { Il.ilTexImage(width, height, 1, (byte)4, Il.IL_RGBA, Il.IL_UNSIGNED_BYTE, (IntPtr)pbuf); } // flip image since direct buffer copy gets it in the wrong y order Ilu.iluFlipImage(); // save the image to file Il.ilSaveImage(savename); // delete the image Il.ilDeleteImages(1, ref imageID); }
public static void SaveRawL16(string savename, int width, int height, ushort[] buffer) { int imageID; // create and bind a new image Il.ilGenImages(1, out imageID); Il.ilBindImage(imageID); fixed(ushort *pbuf = buffer) { // special case for 16 bit greyscale Il.ilTexImage(width, height, 1, (byte)1, Il.IL_LUMINANCE, Il.IL_UNSIGNED_SHORT, (IntPtr)pbuf); } // flip image since direct buffer copy gets it in the wrong y order Ilu.iluFlipImage(); // save the image to file Il.ilSaveImage(savename); // delete the image Il.ilDeleteImages(1, ref imageID); }
private int LoadTextureFromFile(string file, int oldId) { if (textureList.ContainsKey(file) && oldId == -1) { return(0); } int imageId = 0; Il.ilGenImages(1, out imageId); Il.ilBindImage(imageId); if (!Il.ilLoadImage(file)) { Il.ilDeleteImages(1, ref imageId); EngineLog.Get().Error("Error loading " + file + " (DevIL: " + Il.ilGetError() + ")", "Texture manager"); return(-1); } if (file.ToUpper().LastIndexOf(".TGA") == 0) { Ilu.iluFlipImage(); } Texture tex = new Texture(); tex.width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); tex.height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); tex.bpp = Il.ilGetInteger(Il.IL_IMAGE_BITS_PER_PIXEL); IntPtr Ptr = Il.ilGetData(); Gl.glPushAttrib(Gl.GL_TEXTURE_BIT); if (oldId == -1) { //Gl.glGenTextures(1, new int[] { tex.id }); int[] texture = new int[1]; Gl.glGenTextures(1, texture); tex.id = texture[0]; } else { tex.id = oldId; } Gl.glBindTexture(Gl.GL_TEXTURE_2D, tex.id); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_NEAREST); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); int texType = Gl.GL_RGB; if (file.ToUpper().LastIndexOf(".TGA") != -1) { texType = Gl.GL_BGR; } if (tex.bpp == 32) { texType = Gl.GL_RGBA; } if (file.ToUpper().LastIndexOf(".TGA") != -1 && tex.bpp == 32) { texType = Gl.GL_BGRA; } int texDestType = Gl.GL_RGB; if (tex.bpp == 32) { texDestType = Gl.GL_RGBA; } Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, texDestType, tex.width, tex.height, texType, Gl.GL_UNSIGNED_BYTE, Ptr); Gl.glPopAttrib(); if (oldId == -1) { textureList.Add(file, tex); } EngineLog.Get().Info(file + " loaded", "Texture manager"); return(0); }
private void LoadTexture(string filename, uint texture) { int TextureSizeX, TextureSizeY; if (Il.ilLoadImage(filename)) { int Width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH); int Height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT); int BitsPerPixel = Il.ilGetInteger(Il.IL_IMAGE_BITS_PER_PIXEL); //Ilu.iluImageParameter(Ilu.ILU_FILTER, Ilu.ILU_BILINEAR); //Ilu.iluImageParameter(Ilu.ILU_FILTER, Ilu.ILU_NEAREST); if (Width > 128) { TextureSizeX = 128; } else { TextureSizeX = 64; } if (Height > 128) { TextureSizeY = 128; } else { TextureSizeY = 64; } Ilu.iluScale(TextureSizeX, TextureSizeY, 1); string ext = null; int n = filename.LastIndexOf("."); if (n > 0) { ext = filename.Substring(n + 1); } if (ext.ToLower() != "bmp") { Ilu.iluFlipImage(); } // bind to our texture object we just created Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture); // set the filtering and wrap modes for the texture Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR); if (BitsPerPixel == 24) { Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB, TextureSizeX, TextureSizeY, 0, Il.ilGetInteger(Il.IL_IMAGE_FORMAT), Il.ilGetInteger(Il.IL_IMAGE_TYPE), Il.ilGetData()); } if (BitsPerPixel == 32) { Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, TextureSizeX, TextureSizeY, 0, Il.ilGetInteger(Il.IL_IMAGE_FORMAT), Il.ilGetInteger(Il.IL_IMAGE_TYPE), Il.ilGetData()); } } else { string message = "Cannot open file " + filename + "."; MessageBox.Show(message, "Image file open error!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }