コード例 #1
0
ファイル: OutputManager.cs プロジェクト: polytronicgr/geogen
        public void ExportData()
        {
            Config config = this.GetConfig();

            Export export = new Export();

            export.width.Maximum  = this.heightData.Width;
            export.width.Value    = this.heightData.Width;
            export.height.Maximum = this.heightData.Height;
            export.height.Value   = this.heightData.Height;
            if (config.exportRescaleMode)
            {
                export.subzeroMode2.Checked = true;
            }

            if (export.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (this.FileDialog(this.exportHeightmapDialog, ref config.lastExportedFile))
                {
                    string path = this.exportHeightmapDialog.FileName;
                    string ext  = path.Substring(path.LastIndexOf('.'), path.Length - path.LastIndexOf('.')).ToLower();

                    //config.lastExportedFile = path;

                    config.exportRescaleMode = export.subzeroMode2.Checked;

                    HeightData toExport = Main.GetResizedHeightData(this.heightData, (int)export.width.Value, (int)export.height.Value);

                    // rescale the values if necessary
                    if (ext != ".shd" && export.subzeroMode2.Checked)
                    {
                        Main.ScaleHeightValues(ref toExport, 0, short.MaxValue - 1);
                    }

                    if (ext == ".shd")
                    {
                        System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Open(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write));
                        writer.Write(toExport.Width);
                        writer.Write(toExport.Height);

                        for (int i = 0; i < toExport.Length; i++)
                        {
                            writer.Write(toExport[i]);
                        }

                        writer.Close();
                    }
                    else
                    {
                        Main.HeightDataToBitmap(toExport).Save(path);
                    }

                    toExport.Dispose();
                }
            }
        }
コード例 #2
0
        public void ApplyTexture()
        {
            Config config = this.GetConfig();

            if (this.textureBase == null) return;

                try{
                if (this.textureHandle != 0)
                {
                    GL.DeleteTexture(this.textureHandle);
                }

                string selected = (string)this.texture.Items[this.texture.SelectedIndex];
                     
                string path = "";

                System.Drawing.Bitmap bitmap = null;

                if (selected == "[Import External]")
                {
                    try{
                        if (this.FileDialog(this.importTextureDialog, ref config.lastImportedTexture))
                        {
                            bitmap = new System.Drawing.Bitmap(config.lastImportedTexture);

                            if(bitmap.Width > 4096 || bitmap.Height > 4096)
                            {
                                MessageBox.Show("The texture is too big.");
                                bitmap.Dispose();
                                this.viewport.Invalidate();
                                return;
                            }
                        }
                        else
                        {
                            this.viewport.Invalidate();
                            return;
                        }
                    }
                    catch{
                        System.Windows.Forms.MessageBox.Show("Could not load external texture.");

                        this.viewport.Invalidate();
                        return;
                    }
                }

                // "Overlay: " type texture
                else if (selected[0] == 'O')
                {
                    path = config.overlayDirectory + "/" + selected.Substring(9, selected.Length - 9);
                    
                    System.Drawing.Bitmap overlay = new System.Drawing.Bitmap(path);
                    bitmap = this.ApplyOverlay(this.textureBase, overlay);

                    overlay.Dispose();
                }

                // "Map: " type texture
                else if (selected[0] == 'M')
                {
                    bitmap = Main.HeightDataToBitmap((HeightData)this.maps[selected.Substring(5, selected.Length - 5)]);
                }

                if(config.EnableBlackCompensation) Main.ApplyBlackCompensation(ref bitmap);

                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);

                System.Drawing.Bitmap convertedBitmap = new System.Drawing.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(convertedBitmap))
                {
                    gr.DrawImage(bitmap, rect);
                }

                System.Drawing.Imaging.BitmapData data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                this.textureHandle = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, this.textureHandle);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Three, data.Width, data.Height, 0,
                OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

                bitmap.UnlockBits(data);
            }
            catch (OutOfMemoryException)
            {
                this.OutOfMemory();
            }

            this.viewport.Invalidate();
        }