/// <summary> /// Loads the sprite into memory. /// </summary> /// <param name="_logMsgs">True if messages should be logged to console, false otherwise</param> public void Create(bool _logMsgs = true) { int newId; GL.GenTextures(1, out newId); Id = newId; if (Id <= 0) { if (_logMsgs || (mLogMessageOverride)) { TackConsole.EngineLog(EngineLogType.Error, string.Format("Error with generating sprite texture. Sprite. TextureId cannot be set to 0 or below. (Current Id = {0})", Id)); } return; } GL.Enable(EnableCap.Texture2D); GL.ActiveTexture(TextureUnit.Texture0); SpriteManager.AddSprite(this, _logMsgs); if (_logMsgs || (mLogMessageOverride)) { TackConsole.EngineLog(EngineLogType.Message, string.Format("Generated Sprite texture with TextureId '{0}'", Id)); } }
public static Sprite LoadFromFile(string path) { Sprite newSprite = new Sprite(); Bitmap newBp; try { newBp = new Bitmap(Directory.GetCurrentDirectory() + "\\" + path); } catch (FileNotFoundException) { TackConsole.EngineLog(EngineLogType.Error, string.Format("Failed to load image data. No file found at path: '{0}'", path)); return(newSprite); } catch (Exception e) { TackConsole.EngineLog(EngineLogType.Error, string.Format("'{0}'", e.ToString())); return(newSprite); } newSprite.Width = newBp.Width; newSprite.Height = newBp.Height; BitmapData bmpData = newBp.LockBits(new System.Drawing.Rectangle(0, 0, newBp.Width, newBp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); newSprite.PixelFormat = bmpData.PixelFormat; newSprite.m_stride = bmpData.Stride; newSprite.Data = new byte[Math.TackMath.AbsVali(bmpData.Stride) * newBp.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, newSprite.Data, 0, newSprite.Data.Length); newBp.UnlockBits(bmpData); newBp.Dispose(); return(newSprite); }
internal static void LoadDefaultSprite() { Bitmap defaultBitmap = new Bitmap(32, 32); Graphics g = Graphics.FromImage(defaultBitmap); g.Clear(Color.White); DefaultSprite = LoadFromBitmap(defaultBitmap); DefaultSprite.Create(); defaultBitmap.Dispose(); TackConsole.EngineLog(EngineLogType.Message, "Loaded the default sprite into Sprite.DefaultSprite"); }
public void Create() { for (int i = 0; i < mSpriteCount; i++) { /* * mSingleSpriteTextures[i] = Sprite.LoadFromBitmap(mSpriteSheetTexture.GetBitmap().Clone( * new System.Drawing.RectangleF(i * mSingleSpriteWidth, 0, mSingleSpriteWidth, mSingleSpriteHeight), mSpriteSheetTexture.GetBitmap().PixelFormat)); * * mSingleSpriteTextures[i].Width = mSingleSpriteWidth; * mSingleSpriteTextures[i].Height = mSingleSpriteHeight; * * mSingleSpriteTextures[i].Create(); */ } TackConsole.EngineLog(EngineLogType.Message, string.Format("Created {0} Sprites from a SpriteSheet. SingleWidth: {1}, SingleHeight{2}", mSpriteCount, mSingleSpriteWidth, mSingleSpriteHeight)); }