private GameWindow(double fps, int gameWidth, int gameHeight, int screenWidth, int screenHeight, int executionContextId) : base(screenWidth, screenHeight) { GameWindow.instance = this; this.executionContextId = executionContextId; this.gameWidth = gameWidth; this.gameHeight = gameHeight; this.screenWidth = screenWidth; this.screenHeight = screenHeight; this.X = 50; this.Y = 50; this.TargetRenderFrequency = fps; this.UpdateFrame += (sender, e) => this.Update(); this.RenderFrame += (sender, e) => this.Render(); this.Load += (sender, e) => this.Startup(); this.Resize += (sender, e) => this.Resizing(); if (UniversalBitmap.IconSupported) { UniversalBitmap bmp = ResourceReader.ReadIconResource("icon.ico"); if (bmp != null) { this.Icon = bmp.GenerateIcon(); } } }
private GameWindow(double fps, int gameWidth, int gameHeight, int screenWidth, int screenHeight, int executionContextId) : base(screenWidth, screenHeight) { GameWindow.instance = this; this.executionContextId = executionContextId; this.gameWidth = gameWidth; this.gameHeight = gameHeight; this.screenWidth = screenWidth; this.screenHeight = screenHeight; this.X = 50; this.Y = 50; this.TargetRenderFrequency = fps; this.UpdateFrame += (sender, e) => this.Update(); this.RenderFrame += (sender, e) => this.Render(); this.Load += (sender, e) => this.Startup(); this.Resize += (sender, e) => this.Resizing(); this.Mouse.Move += (sender, e) => this.MouseMove(e.X, e.Y); this.Mouse.ButtonDown += (sender, e) => this.MouseButton(e.Button, e.X, e.Y, true); this.Mouse.ButtonUp += (sender, e) => this.MouseButton(e.Button, e.X, e.Y, false); this.Keyboard.KeyDown += (sender, e) => this.KeyEvent(e.Key, true); this.Keyboard.KeyUp += (sender, e) => this.KeyEvent(e.Key, false); if (UniversalBitmap.IconSupported) { UniversalBitmap bmp = ResourceReader.ReadIconResource("icon.ico"); if (bmp != null) { this.Icon = bmp.GenerateIcon(); } } }
public static int ForceLoadTexture(UniversalBitmap bitmap) { if (bitmap.GlTextureId != 0) { return(bitmap.GlTextureId); } bitmap = NormalizeBitmap(bitmap); int width = bitmap.Width; int height = bitmap.Height; int textureId; UniversalBitmap.BitLockSession bitlock = bitmap.GetActiveBitLockSession(); GL.GenTextures(1, out textureId); GL.BindTexture(TextureTarget.Texture2D, textureId); GL.TexImage2D( TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bitlock.GetPtr()); bitlock.Free(); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); bitmap.GlTextureId = textureId; return(textureId); }
public static void BlitImage( object targetBmp, object sourceBmp, int targetX, int targetY, int sourceX, int sourceY, int width, int height, object graphicsSession) { UniversalBitmap target = (UniversalBitmap)targetBmp; UniversalBitmap source = (UniversalBitmap)sourceBmp; ((UniversalBitmap.DrawingSession)graphicsSession).Draw(source, targetX, targetY, sourceX, sourceY, width, height); }
private static string ConvertChunksToManifest(IList <Chunk> chunks) { string currentModule = ""; string currentDirectory = null; List <string> lines = new List <string>(); int chunkId = 1; foreach (Chunk chunk in chunks) { chunk.ID = chunkId++; lines.Add("C," + chunk.ID + "," + chunk.Width + "," + chunk.Height); UniversalBitmap chunkBmp = new UniversalBitmap(chunk.Width, chunk.Height); UniversalBitmap.DrawingSession g = chunkBmp.CreateNewDrawingSession(); for (int i = 0; i < chunk.Images.Count; ++i) { Image image = chunk.Images[i]; string path = image.File.OriginalPath; string dir; string filename; int lastSlash = path.LastIndexOf('/'); if (lastSlash == -1) { dir = "/"; filename = path; } else { dir = path.Substring(0, lastSlash); filename = path.Substring(lastSlash + 1); } int x = chunk.X[i]; int y = chunk.Y[i]; g.Blit(image.File.Bitmap, x, y); if (image.Module != currentModule) { currentModule = image.Module; lines.Add("M," + currentModule); } if (dir != currentDirectory) { currentDirectory = dir; lines.Add("D," + currentDirectory); } lines.Add("F," + x + "," + y + "," + image.Width + "," + image.Height + "," + filename); } g.Flush(); chunk.FinalizedBitmap = chunkBmp; } return(string.Join('\n', lines)); }
private static bool ImageLoadSync(string filename, object[] nativeImageDataNativeData) { UniversalBitmap bmp = ResourceReader.ReadImageResource(filename); if (bmp != null) { nativeImageDataNativeData[0] = bmp; nativeImageDataNativeData[1] = bmp.Width; nativeImageDataNativeData[2] = bmp.Height; return(true); } return(false); }
private static UniversalBitmap NormalizeBitmap(UniversalBitmap bitmap) { int oldWidth = bitmap.Width; int oldHeight = bitmap.Height; int newWidth = CrayonWrapper.nextPowerOf2(oldWidth); int newHeight = CrayonWrapper.nextPowerOf2(oldHeight); if (newWidth == oldWidth && newHeight == oldHeight) { return(bitmap); } UniversalBitmap newBmp = new UniversalBitmap(newWidth, newHeight); newBmp.GetActiveDrawingSession().Draw(bitmap, 0, 0, 0, 0, oldWidth, oldHeight).Flush(); return(newBmp); }
public static void SendImageToRenderer(object frameObj, int id, object nativeImageData, int x, int y, int width, int height) { NoriFrame frame = (NoriFrame)frameObj; UniversalBitmap atlas = (UniversalBitmap)nativeImageData; UniversalBitmap cropped; if (atlas.Width == width && atlas.Height == height) { cropped = atlas; } else { cropped = new UniversalBitmap(width, height); UniversalBitmap.DrawingSession session = cropped.GetActiveDrawingSession(); session.Draw(atlas, 0, 0, x, y, width, height); session.Flush(); } byte[] pngBytes = cropped.GetBytesAsPng(); string base64Image = UniversalBitmap.ToBase64("data:image/png;base64,", pngBytes); frame.SendImageToBrowser(id, width, height, base64Image); }
private void ExportImageFile(string path, UniversalBitmap image) { image.Save(path); }