private Mogre.Image SystemtoMogreImage(System.Drawing.Image image) { Stream oStream = new MemoryStream(); image.Save(oStream, System.Drawing.Imaging.ImageFormat.Png); /* Back to the start of the stream */ oStream.Position = 0; /* read all the stream in a buffer */ BinaryReader oBinaryReader = new BinaryReader(oStream); byte[] pBuffer = oBinaryReader.ReadBytes((int)oBinaryReader.BaseStream.Length); oStream.Close(); /*No more needed */ Mogre.Image oMogreImage = new Mogre.Image(); unsafe { System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(pBuffer, System.Runtime.InteropServices.GCHandleType.Pinned); byte *pUnsafeByte = (byte *)handle.AddrOfPinnedObject(); void *pUnsafeBuffer = (void *)handle.AddrOfPinnedObject(); MemoryDataStream oMemoryStream = new MemoryDataStream(pUnsafeBuffer, (uint)pBuffer.Length); DataStreamPtr oPtrDataStream = new DataStreamPtr(oMemoryStream); oMogreImage = oMogreImage.Load(oPtrDataStream, "png"); handle.Free(); } return(oMogreImage); }
// //ORIGINAL LINE: Ogre::TexturePtr createTexture(Ogre::String name, Ogre::String group = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME) const // public TexturePtr createTexture(string name, string group) { Mogre.TexturePtr texture = TextureManager.Singleton.CreateManual(name, group, TextureType.TEX_TYPE_2D, mWidth, mHeight, 0, PixelFormat.PF_R8G8B8A8, (int)TextureUsage.TU_DEFAULT); Mogre.Image image = getImage(); texture.LoadImage(image); image.Dispose(); return(texture); }
/// Create a new image from buffer. // //ORIGINAL LINE: Ogre::Image* getImage() const public unsafe Mogre.Image getImage() { Mogre.Image image = new Mogre.Image(); fixed(byte *buf = mPixels) { image.LoadDynamicImage(buf, mWidth, mHeight, 1, PixelFormat.PF_R8G8B8A8); } return(image); }
public int Add(string pathRelFile) { string pathAbsImg = path_cache + pathRelFile; Mogre.Image image = new Mogre.Image(); FileStream fs = new FileStream(pathAbsImg, FileMode.Open); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(fs)); image.Load(fs2); TexturePtr texturePtr = TextureManager.Singleton.LoadImage(pathRelFile, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image); fs2.Close(); fs.Close(); lock (allTextures) { return allTextures.Add(texturePtr); } }
//public unsafe void Replace3(Mogre.Image image, string textureName) //{ // if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); // TexturePtr pTexture = this[textureName]; // HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer(); // texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD); // PixelBox pb = texBuffer.CurrentLock; // PixelBox imagBox = image.GetPixelBox(); // imagBox.data // Marshal.Copy(bytes, 0, pb.data, bytes.Length); // texBuffer.Unlock(); // texBuffer.Dispose(); //} public byte[] ConvertImageToRgbValues(byte[] inBytes) { Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(inBytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); uint bytes = imagBox.GetConsecutiveSize(); byte[] rgbValues = new byte[bytes]; Marshal.Copy(imagBox.data, rgbValues, 0, (int)bytes); image.Dispose(); fs2.Close(); ms.Close(); return(rgbValues); }
public int Add(string pathRelFile) { string pathAbsImg = path_cache + pathRelFile; Mogre.Image image = new Mogre.Image(); FileStream fs = new FileStream(pathAbsImg, FileMode.Open); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(fs)); image.Load(fs2); TexturePtr texturePtr = TextureManager.Singleton.LoadImage(pathRelFile, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image); fs2.Close(); fs.Close(); lock (allTextures) { return(allTextures.Add(texturePtr)); } }
public void Replace(byte[] bytes, string textureName) { if (this.IndexOf(textureName) < 0) { throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); } Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(bytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); TexturePtr pTexture = this[textureName]; TextureManager lTextureManager = TextureManager.Singleton; HardwarePixelBuffer buffer = pTexture.GetBuffer(); unsafe { buffer.BlitFromMemory(imagBox); } image.Dispose(); fs2.Close(); ms.Close(); }
public Material createStateSet(Mogre.Image image);
// * // \brief Save the image from the buffer to a file. // \param filename Name (and path) of the image file where to save the buffer. // // //ORIGINAL LINE: void saveImage(Ogre::String filename) const public void saveImage(string filename) { Mogre.Image image = getImage(); image.Save(filename); image.Dispose(); }
private void CreateTerrain() { mTMgr = new MET.TerrainManager(OgreEngine.mMgr, "MET"); mTMgr.SetLodErrorMargin(2, OgreEngine.mWin.Height); mTMgr.SetUseLodMorphing(true, 0.2f, "morphFactor"); mTInfo = new MET.TerrainInfo(); Mogre.Image image = new Mogre.Image(); image.Load("heightmap.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); MET.TerrainInfo.LoadHeightmapFromImage(mTInfo, image); //mTInfo.Extents = new Mogre.AxisAlignedBox(0, 0, 0, land.SizeX + stepWidth, land.SizeZ, land.SizeY + stepHeight); mTInfo.Extents = new Mogre.AxisAlignedBox(Vector3.ZERO, Size); //lightmap Mogre.Image lmImage = new Mogre.Image(); MET.TerrainInfo.CreateTerraingLightmap(mTInfo, lmImage, Constants.Land.LightmapSize, Constants.Land.LightmapSize, new Vector3(-1, -1, -1), new ColourValue(1, 1, 1), new ColourValue(0.2f, 0.2f, 0.2f), true); //lmImage.Save("lightmapa" + land.Id + ".png"); TexturePtr lightmapTex = TextureManager.Singleton.CreateManual( "ETLightmap", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D, Constants.Land.LightmapSize, Constants.Land.LightmapSize, 1, Mogre.PixelFormat.PF_BYTE_RGB); TexturePtr tex = TextureManager.Singleton.GetByName("ETLightmap"); tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0)); mTMgr.CreateTerrain(mTInfo); mTInfo.Dispose(); mTInfo = mTMgr.TerrainInfo; image = new Image(); image.Load("textureMap0.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); TextureSize = image.Width; mSMgr = new MET.SplattingManager("ETSplatting", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image.Width, image.Width, 3); mSMgr.NumTextures = 6; mSMgr.LoadMapFromImage(0, image); image = new Image(); image.Load("textureMap1.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); mSMgr.LoadMapFromImage(1, image); mTMgr.Material = MaterialManager.Singleton.GetByName("ETTerrainMaterial"); // lightmapa Pass pass = mTMgr.Material.GetTechnique(0).CreatePass(); pass.LightingEnabled = false; pass.SetSceneBlending(SceneBlendType.SBT_MODULATE); pass.SetVertexProgram("ET/Programs/VSLodMorph2"); pass.SetFragmentProgram("ET/Programs/PSLighting"); pass.CreateTextureUnitState("ETLightmap"); pass = mTMgr.Material.GetTechnique(1).CreatePass(); pass.LightingEnabled = false; pass.SetSceneBlending(SceneBlendType.SBT_MODULATE); pass.SetVertexProgram("ET/Programs/VSLodMorph2"); pass.SetFragmentProgram("ET/Programs/PSLighting"); pass.CreateTextureUnitState("ETLightmap"); //base texture for non shader graphics lmImage = new Mogre.Image(); //TODO: replace by real bic texture lmImage.Load("baseTexture.jpg", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); //lmImage.Save("lightmapa" + land.Id + ".png"); lightmapTex = TextureManager.Singleton.CreateManual( "ETBasemap", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D, Constants.Land.LightmapSize, Constants.Land.LightmapSize, 1, Mogre.PixelFormat.PF_BYTE_RGB); tex = TextureManager.Singleton.GetByName("ETBasemap"); tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0)); Technique tech = mTMgr.Material.CreateTechnique(); pass = tech.CreatePass(); pass.CreateTextureUnitState("ETBasemap"); }
public void UpdateLightMap() { try { Mogre.Image lmImage = new Mogre.Image(); MET.TerrainInfo.CreateTerraingLightmap(mTInfo, lmImage, Constants.Land.LightmapSize, Constants.Land.LightmapSize, new Vector3(-1, -1, -1), new ColourValue(1, 1, 1), new ColourValue(0.5f, 0.5f, 0.5f), true); TexturePtr tex = TextureManager.Singleton.GetByName("ETLightmap" + "0"); tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0)); } catch (Exception e) { LogManager.Singleton.LogMessage("Lightmap exception: " + e.StackTrace); // in some cases lightmap crashes...never mind } /// }
public void SetEditingBrush(ushort size) { if (size < 1) size = 1; Mogre.Image image2 = new Mogre.Image(); image2.Load("brushsmooth1.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); image2.Resize(size, size, Image.Filter.FILTER_BICUBIC); EditingBrush = MET.Brush.LoadBrushFromImage(image2); }
/** * Assembles an osg::Image from the raster data and applies it to a state set * as a 2D texture map. * * @param state_set * State set to which to apply the texture containing the extracted image * @param aoi * Region of the raster to extract into the image * @param max_pixels * Maximum width or height of the image to extract * @param image_name * Name to assign to the extracted image * @param out_image * Store the image pointer to this variable upon success * * @return true upon success, false upon failure */ public bool applyToStateSet( Material state_set, GeoExtent aoi, uint max_pixel_span, out Mogre.Image out_image);
public void Replace(byte[] bytes, string textureName) { if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(bytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); TexturePtr pTexture = this[textureName]; TextureManager lTextureManager = TextureManager.Singleton; HardwarePixelBuffer buffer = pTexture.GetBuffer(); unsafe { buffer.BlitFromMemory(imagBox); } image.Dispose(); fs2.Close(); ms.Close(); }
//public unsafe void Replace3(Mogre.Image image, string textureName) //{ // if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); // TexturePtr pTexture = this[textureName]; // HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer(); // texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD); // PixelBox pb = texBuffer.CurrentLock; // PixelBox imagBox = image.GetPixelBox(); // imagBox.data // Marshal.Copy(bytes, 0, pb.data, bytes.Length); // texBuffer.Unlock(); // texBuffer.Dispose(); //} public byte[] ConvertImageToRgbValues(byte[] inBytes) { Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(inBytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); uint bytes = imagBox.GetConsecutiveSize(); byte[] rgbValues = new byte[bytes]; Marshal.Copy(imagBox.data, rgbValues, 0, (int)bytes); image.Dispose(); fs2.Close(); ms.Close(); return rgbValues; }
// * // Run image generation // \return Pointer to image buffer which has been set in the constructor. // public override TextureBuffer process() { Mogre.Image img = new Mogre.Image(); img.Load(mFile, mGroup); if (img.Height < mBuffer.getHeight() || img.Width < mBuffer.getWidth()) return mBuffer; for (int y = 0; y < mBuffer.getHeight(); y++) { for (int x = 0; x < mBuffer.getWidth(); x++) { mBuffer.setPixel(x, y, img.GetColourAt(x, y, 0)); } } Utils.log("Create texture from image"); return mBuffer; }