/** * Creates a BunnyMark with a certain number of Wabbits. * * @param count * The number of wabbits. * @param rect * You can define a rectangle for the borders of the BunnyMark. If you don't specify the rectangle the complete stage will be used. */ public BunnyMarkSimple(int count = 100, Rectangle rect=null) { Touchable = false; mCount = count; if (rect != null) mRectangle = rect; mTexture = SimpleTextureLoader.LoadAndroidResource(SparrowSharp.Samples.Android.Resource.Drawable.wabbit_alpha); AddedToStage += AddedToStageHandler; }
/// <summary> /// Initializes a render texture with a certain ARGB color (0xAARRGGBB) and a scale factor. /// </summary> public RenderTexture(float width, float height, uint argbFillColor = 0x0, float scale = 1.0f) { int legalWidth = NumberUtil.NextPowerOfTwo(width * scale); int legalHeight = NumberUtil.NextPowerOfTwo(height * scale); TextureProperties properties = new TextureProperties { TextureFormat = Sparrow.Textures.TextureFormat.Rgba8888, Scale = scale, Width = legalWidth, Height = legalHeight, NumMipmaps = 0, PremultipliedAlpha = true }; Rectangle region = new Rectangle(0, 0, width, height); GLTexture glTexture = new GLTexture(IntPtr.Zero, properties); Init(glTexture, region); _renderSupport = new RenderSupport(); Clear(argbFillColor, ColorUtil.GetA(argbFillColor) / 255.0f); }
private void GenerateTexture(UIImage image) { uint name = (uint)GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, name); // GL.TexParameter(TextureTarget.Texture2D, All.TextureMaxAnisotropyExt, 1); // GL.TexParameter(TextureTarget.Texture2D, All.GenerateMipmapHint, (int)All.False); LoadTexture(image); // see https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Texture2D.cs // for how MonoGame does it _glTexture = new GLTexture(name, image.CGImage.Width, image.CGImage.Height, false, 1.0f, false); _isLoaded = true; // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. EventHandler<GLTexture> handler = ResourceLoaded; if (handler != null) { handler(this, _glTexture); } }
protected void GenerateTexture(Bitmap bitmap) { GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Fastest); uint name = (uint)GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, name); /* TODO is this needed? if (GLExtensions.TextureMaxAnisotropySupported) { float maxAniso; GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out maxAniso); GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, maxAniso); } */ GL.TexStorage2D(TextureTarget2D.Texture2D, 1, // mipmap level, min 1 SizedInternalFormat.Rgba8, bitmap.Width, bitmap.Height); if (bitmap.Width > 0 && bitmap.Height > 0) { GLUtils.TexSubImage2D(GLES20.GlTexture2d, 0, // level 0, // xOffset 0, // yOffset bitmap); } else { Console.Out.WriteLine("WARNING: empty bitmap loaded"); } // see https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Texture2D.OpenGL.cs // for how MonoGame does it _glTexture = new GLTexture(name, bitmap.Width, bitmap.Height, false, 1.0f, false); _isLoaded = true; // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. EventHandler<GLTexture> handler = ResourceLoaded; if (handler != null) { handler(this, _glTexture); } }
private void GenerateTexture(Bitmap bitmap) { _isLoaded = false; // Fix up the Image to match the expected format bitmap = RGBToBGR(bitmap); BitmapData bitmapData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); uint name = (uint)GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, name); OpenTK.Graphics.OpenGL4.GL.TexStorage2D(OpenTK.Graphics.OpenGL4.TextureTarget2d.Texture2D, 1, // mipmap level OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, bitmapData.Width, bitmapData.Height); OpenTK.Graphics.OpenGL4.GL.TexSubImage2D(OpenTK.Graphics.OpenGL4.TextureTarget.Texture2D, 0, // level 0, // xOffset 0, // yOffset bitmapData.Width, bitmapData.Height, OpenTK.Graphics.OpenGL4.PixelFormat.Rgba, OpenTK.Graphics.OpenGL4.PixelType.UnsignedByte, bitmapData.Scan0); bitmap.UnlockBits(bitmapData); _glTexture = new GLTexture(name, bitmap.Width, bitmap.Height, false, 1.0f, false); _isLoaded = true; // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. EventHandler<GLTexture> handler = ResourceLoaded; if (handler != null) { handler(this, _glTexture); } }