public void set_pixel(int x, int y, Color rc) { System.Drawing.Color c = System.Drawing.Color.FromArgb(rc.alpha, rc.red, rc.green, rc.blue); bmp.SetPixel(x, y, c); OG_Graphics.deferred_action_add(syncBitmap); }
public void draw_text(Rect r, string message, int align) { Brush brush = new SolidBrush(System.Drawing.Color.FromArgb((byte)font.color.alpha, (byte)font.color.red, (byte)font.color.green, (byte)font.color.blue)); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); System.Drawing.Font f = font.get_drawing_font(); System.Drawing.Rectangle destination = new System.Drawing.Rectangle(new Point(r.x, r.y), new Size(r.width, r.height)); StringFormat stringFormat = new StringFormat(); if (align == 0) { stringFormat.Alignment = StringAlignment.Near; } if (align == 1) { stringFormat.Alignment = StringAlignment.Center; } if (align == 2) { stringFormat.Alignment = StringAlignment.Far; } stringFormat.LineAlignment = StringAlignment.Center; //increases quality and accuracy g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; if (font.outline) { Brush out_brush = new SolidBrush(System.Drawing.Color.FromArgb((byte)font.out_color.alpha, (byte)font.out_color.red, (byte)font.out_color.green, (byte)font.out_color.blue)); destination.X -= font.outline_width; //g.DrawString(message, f, out_brush, destination, stringFormat); DrawStringShrink2Fit(g, message, f, out_brush, destination, stringFormat); destination.X += font.outline_width * 2; //g.DrawString(message, f, out_brush, destination, stringFormat); DrawStringShrink2Fit(g, message, f, out_brush, destination, stringFormat); destination.X -= font.outline_width; destination.Y -= font.outline_width; //g.DrawString(message, f, out_brush, destination, stringFormat); DrawStringShrink2Fit(g, message, f, out_brush, destination, stringFormat); destination.Y += font.outline_width * 2; //g.DrawString(message, f, out_brush, destination, stringFormat); DrawStringShrink2Fit(g, message, f, out_brush, destination, stringFormat); destination.Y -= font.outline_width; out_brush.Dispose(); } //g.DrawString(message, f, brush, destination, stringFormat); DrawStringShrink2Fit(g, message, f, brush, destination, stringFormat); g.Dispose(); brush.Dispose(); OG_Graphics.deferred_action_add(syncBitmap); }
public void stretch_blt(Rect dest, Bitmap src_bitmap, Rect src_rect, int opacity) { System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; //flip to sourceover to retain old image underneath. desired? System.Drawing.Rectangle source = new System.Drawing.Rectangle(new Point(src_rect.x, src_rect.y), new Size(src_rect.width, src_rect.height)); System.Drawing.Rectangle destination = new System.Drawing.Rectangle(new Point(dest.x, dest.y), new Size(dest.width, dest.height)); g.DrawImage(src_bitmap.bmp, destination, source, GraphicsUnit.Pixel); g.Dispose(); OG_Graphics.deferred_action_add(syncBitmap); }
public void fill_rect(int ax, int ay, int aw, int ah, Color c) { System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; using (var br = new SolidBrush(System.Drawing.Color.FromArgb(c.alpha, c.red, c.green, c.blue))) { g.FillRectangle(br, new Rectangle(ax, ay, aw, ah)); } OG_Graphics.deferred_action_add(syncBitmap); g.Dispose(); }
public Bitmap(Bitmap b) { syncBitmap = this.SyncBitmap; font = b.font; name = b.name; width_ = b.width(); height_ = b.height(); bmp = (System.Drawing.Bitmap)b.bmp.Clone(); disposed = b.disposed; OG_Graphics.deferred_action_add(syncBitmap); }
public void gradient_fill_rect(int ax, int ay, int aw, int ah, Color c1, Color c2, bool vertical) { if (aw == 0) { aw = 100; } if (ah == 0) { ah = 100; } if (aw < 0) { aw = Math.Abs(aw); } if (ah < 0) { ah = Math.Abs(ah); } //return; System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; System.Drawing.Drawing2D.LinearGradientBrush br; System.Drawing.Color syscolor1 = System.Drawing.Color.FromArgb(c1.alpha, c1.red, c1.green, c1.blue); System.Drawing.Color syscolor2 = System.Drawing.Color.FromArgb(c2.alpha, c2.red, c2.green, c2.blue); System.Drawing.Drawing2D.LinearGradientMode lgm; if (vertical) { lgm = System.Drawing.Drawing2D.LinearGradientMode.Vertical; } else { lgm = System.Drawing.Drawing2D.LinearGradientMode.Horizontal; } using (br = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(ax, ay, aw, ah), syscolor1, syscolor2, lgm)) { g.FillRectangle(br, new Rectangle(ax, ay, aw, ah)); } OG_Graphics.deferred_action_add(syncBitmap); g.Dispose(); }
public void Start() { RuntimeConfiguration rtc = Program.GetRuntime(); OpenGame.Runtime.Runtime.RGSSVersion = rtc.GetRGSSVersion(); OpenGame.Runtime.Runtime.ResourcePaths = rtc.GetResourcePaths(); OpenGame.Runtime.Runtime.DefaultResolutionWidth = rtc.GetDefaultResolutionWidth(); OpenGame.Runtime.Runtime.DefaultResolutionHeight = rtc.GetDefaultResolutionHeight(); OG_Graphics.initialize(Program.Window); if (rtc.IsDebug() && rtc.IsPlayTest()) { engine.Execute("$DEBUG = $TEST = true", scope); } engine.Execute(OG_Graphics.ruby_helper(), scope); engine.Execute(OG_Input.ruby_helper(), scope); engine.Execute(Plane.ruby_helper(), scope); engine.Execute(Table.ruby_helper(), scope); engine.Execute(Window.ruby_helper(), scope); engine.Execute(CTilemap.ruby_helper(), scope); engine.Execute(Viewport.ruby_helper(), scope); engine.Execute(Rect.ruby_helper(), scope); engine.Execute(Sprite.ruby_helper(), scope); engine.Execute(Color.ruby_helper(), scope); engine.Execute(Tone.ruby_helper(), scope); engine.Execute(Bitmap.ruby_helper(), scope); Font.load_fonts(); engine.Execute(Font.ruby_helper(), scope); try { engine.Execute(@"$OPENGAME_EXE = true"); engine.Execute("$RGSS_SCRIPTS_PATH = '" + rtc.GetScriptsPath() + "'"); engine.Execute(@"rgss_start", scope); } catch (Exception e) { Program.Error(e.Message); } }
public static Bitmap snap_to_bitmap() { //generate a new bitmap Bitmap bmp = new Bitmap(Math.Max(1, width), Math.Max(1, height)); //read the screen to the bitmap's texture GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.ReadBuffer(ReadBufferMode.Front); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, bmp.txid); GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, bmp.width(), bmp.height()); GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); GL.ReadBuffer(ReadBufferMode.None); //read the bitmap's texture to the bitmap itself int fboId; GL.Ext.GenFramebuffers(1, out fboId); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboId); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, bmp.txid, 0); var bits = bmp.bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.width(), bmp.height()), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.ReadPixels(0, 0, bmp.width(), bmp.height(), OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); GL.Ext.DeleteFramebuffers(1, ref fboId); bmp.bmp.UnlockBits(bits); //flip and sync bmp.bmp.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY); OG_Graphics.deferred_action_add(bmp.syncBitmap); //return the bmp return(bmp); }
public void generate_tiles(Table map_data, Bitmap tileset, Viewport viewport) { if (viewport == null) { Console.WriteLine("Tilemap viewport is invalid!"); return; } Console.Write("Generating tilemap..."); //if not ready or needed, gtfo if (map_data == null || tileset == null) { if (map_data == null) { Console.WriteLine("Attempted to generate tilemap with null map_data"); } if (tileset == null) { Console.WriteLine("Attempted to generate tilemap with null tileset"); } return; } if (map_data.xsize == 0 || map_data.ysize == 0 || map_data.zsize == 0) { Console.WriteLine("Attempted to generate tilemap of size 0"); } if (!map_tiles_empty()) { Console.WriteLine("Attempted to generate a tilemap that is already generated"); return; } //get map dimensions in 64x tiles int tile_width = Math.Max(1, (int)((float)map_data.xsize / 64f)); int tile_height = Math.Max(1, (int)((float)map_data.ysize / 64f)); //set blank color Color c_blank = new Color(0, 0, 0, 0); //iterate through the 64x64 map tiles we intend to create for (int tile_x = 0; tile_x < tile_width; tile_x++) { for (int tile_y = 0; tile_y < tile_height; tile_y++) { //determine the map starting tile coordinates int start_x = tile_x * 64; int start_y = tile_y * 64; //calculate the map tile dimensions - normally 64x64 except close to bottom or right edges int bm_width = 64; int bm_height = 64; if (tile_x == tile_width - 1) { bm_width = (map_data.xsize - start_x); } if (tile_y == tile_height - 1) { bm_height = (map_data.ysize - start_y); } //create a bitmap for this map tile Bitmap bitmap = new Bitmap(bm_width * 32, bm_height * 32); //determine map tile ending coordinates int end_x = start_x + bm_width; int end_y = start_y + bm_height; //initialize tile image coordinates int tile_image_x = 0; int tile_image_y = 0; //open the bitmap for direct access System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap.bmp); g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; //iterate the map data and fill in the tile bitmap as needed for (int x = start_x; x < end_x; x++) { for (int y = start_y; y < end_y; y++) { //get the tile id int tile_id = map_data.get(x, y, 0) - 384; if (tile_id < 0) //if tile is empty { //fill in a blank, update the image coordinates, and continue bitmap.fill_rect(tile_image_x, tile_image_y, 32, 32, c_blank); tile_image_y += 32; continue; } //direct copy bitmap info (blt is too slow) System.Drawing.Rectangle source = new System.Drawing.Rectangle(new System.Drawing.Point((tile_id % 8) * 32, (tile_id / 8) * 32), new System.Drawing.Size(32, 32)); System.Drawing.Rectangle destination = new System.Drawing.Rectangle(new System.Drawing.Point(tile_image_x, tile_image_y), new System.Drawing.Size(32, 32)); g.DrawImage(tileset.bmp, destination, source, System.Drawing.GraphicsUnit.Pixel); //update tile coordinates and continue tile_image_y += 32; } //recycle column tile_image_x += 32; tile_image_y = 0; } //close direct access to bitmap g.Dispose(); OG_Graphics.deferred_action_add(bitmap.syncBitmap); //create the tile sprite and add it to the map Sprite sprite = new Sprite(viewport); sprite.bitmap = bitmap; sprite.x = tile_x * 2048; sprite.y = tile_y * 2048; add_map_tile(sprite); } } Console.Write(" done.\n"); }