public void SaveAlphaToFile(string filename) { ImageWrapper image = new ImageWrapper(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { image.SetPixel(i, j, alphadata[i, j], alphadata[i, j], alphadata[i, j], alphadata[i, j]); } } image.Save(filename); this.filename = filename; this.modified = false; }
public void Save(string filename) { double[,] mesh = MetaverseClient.GetInstance().worldstorage.terrainmodel.Map; int width = mesh.GetUpperBound(0) + 1; int height = mesh.GetUpperBound(1) + 1; ImageWrapper image = new ImageWrapper(width, height); //Bitmap bitmap = new Bitmap( width, height, PixelFormat.Format24bppRgb ); //Graphics g = Graphics.FromImage(bitmap); //Pen[] pens = new Pen[256]; //for (int i = 0; i < 256; i++) //{ // pens[i] = new Pen(System.Drawing.Color.FromArgb(i, i, i)); //} double minheight = Config.GetInstance().mingroundheight; double maxheight = Config.GetInstance().maxgroundheight; double heightmultiplier = 255 / (maxheight - minheight); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int normalizedmeshvalue = (int)((mesh[i, j] - minheight) * heightmultiplier); normalizedmeshvalue = Math.Max(0, normalizedmeshvalue); normalizedmeshvalue = Math.Min(255, normalizedmeshvalue); byte normalizedmeshvaluebyte = (byte)normalizedmeshvalue; image.SetPixel(i, j, normalizedmeshvaluebyte, normalizedmeshvaluebyte, normalizedmeshvaluebyte, 255); //g.DrawRectangle(pens[ normalizedmeshvalue ], i, j, 1, 1); } } if (File.Exists(filename)) { File.Delete(filename); } image.Save(filename); //DevIL.DevIL.SaveBitmap(filename, bitmap); //bitmap.Save(filename, ImageFormat.Bmp); MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightmapFilename = filename; MetaverseClient.GetInstance().worldstorage.terrainmodel.OnTerrainModified(); MainTerrainWindow.GetInstance().InfoMessage("Heightmap saved"); }
void LoadImageToOpenGl(ImageWrapper image) { width = image.Width; height = image.Height; LogFile.WriteLine("loading texture " + filename + " width: " + width + " height: " + height); alphadata = new byte[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { alphadata[x, y] = image.GetAlpha(x, y); } } LogFile.WriteLine("glreference: " + GlReference); Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlReference); Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA8, width, height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.data); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); image.Save("out2.jpg"); }
public void Save(string filename) { double[,] mesh = MetaverseClient.GetInstance().worldstorage.terrainmodel.Map; int width = mesh.GetUpperBound(0) + 1; int height = mesh.GetUpperBound(1) + 1; ImageWrapper image = new ImageWrapper( width, height ); //Bitmap bitmap = new Bitmap( width, height, PixelFormat.Format24bppRgb ); //Graphics g = Graphics.FromImage(bitmap); //Pen[] pens = new Pen[256]; //for (int i = 0; i < 256; i++) //{ // pens[i] = new Pen(System.Drawing.Color.FromArgb(i, i, i)); //} double minheight = Config.GetInstance().mingroundheight; double maxheight = Config.GetInstance().maxgroundheight; double heightmultiplier = 255 / (maxheight - minheight); for (int i = 0; i < width; i++) { for( int j = 0; j < height; j++ ) { int normalizedmeshvalue = (int)( (mesh[i, j] - minheight) * heightmultiplier ); normalizedmeshvalue = Math.Max( 0,normalizedmeshvalue ); normalizedmeshvalue = Math.Min( 255,normalizedmeshvalue ); byte normalizedmeshvaluebyte = (byte)normalizedmeshvalue; image.SetPixel(i, j, normalizedmeshvaluebyte, normalizedmeshvaluebyte, normalizedmeshvaluebyte, 255); //g.DrawRectangle(pens[ normalizedmeshvalue ], i, j, 1, 1); } } if (File.Exists(filename)) { File.Delete(filename); } image.Save(filename); //DevIL.DevIL.SaveBitmap(filename, bitmap); //bitmap.Save(filename, ImageFormat.Bmp); MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightmapFilename = filename; MetaverseClient.GetInstance().worldstorage.terrainmodel.OnTerrainModified(); MainTerrainWindow.GetInstance().InfoMessage("Heightmap saved"); }
public void SaveBlendTextureToFile(string filepath) { blendtexturefilename = filepath; blendtexture.Save(filepath); // note to self: Is this right??? }
public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds) { if (thistexture != null && maptexturestage != null) { double timemultiplier = milliseconds * speed; double directionmultiplier = 1.0; if (!israising) { directionmultiplier = -1.0; } int mapx = (int)(brushcentrex); int mapy = (int)(brushcentrey); int mapwidth = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1; int mapheight = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight - 1; int texturex = (int)(texturewidth * mapx / mapwidth); int texturey = (int)(textureheight * mapy / mapheight); int texturebrushwidth = (int)(texturewidth * brushsize / mapwidth); int texturebrushheight = (int)(textureheight * brushsize / mapheight); for (int i = -texturebrushwidth; i <= texturebrushwidth; i++) { for (int j = -texturebrushheight; j <= texturebrushheight; j++) { double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth, (double)j / texturebrushheight); if (brushshapecontribution > 0) { int thisx = texturex + i; int thisy = texturey + j; // Console.WriteLine(thisx + " " + thisy); if (thisx >= 0 && thisy >= 0 && thisx < texturewidth && thisy < textureheight) { // we update our double array then set the int array iwthin ITexture itself //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution ); alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution; if (alphadata[thisx, thisy] >= 255) { alphadata[thisx, thisy] = 255; } else if (alphadata[thisx, thisy] < 0) { alphadata[thisx, thisy] = 0; } thistexture.SetPixel(thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255); //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] ); //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy]; // Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]); } } } } thistexture.Save("editedblend.jpg"); //thistexture.ReloadAlpha(); maptexturestage.onChanged(); //thistexture.Modified = true; MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize); } }