Ejemplo n.º 1
0
        /// <summary>
        /// Creates a static texture from an existing surface.
        /// </summary>
        /// <param name="surface">Surface to create texture from</param>
        /// <param name="quality">Filtering quality when texture is scaled</param>
        /// <remarks>
        /// The surface is not modified or disposed by this function.
        /// <see cref="TextureAccess" /> is static.
        /// The pixel format of the created texture may be different from the
        /// pixel format of the surface.
        /// </remarks>
        public Texture CreateTextureFromSurface(Surface surface,
                                                TextureScalingQuality quality = TextureScalingQuality.Nearest)
        {
            Try(() =>
                SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, quality.AsHint()),
                "SDL_SetHint");
            var texture = SDL_CreateTextureFromSurface(Handle, surface.Handle);

            if (texture == IntPtr.Zero)
            {
                throw new ImaginiException($"Could not create texture: {SDL_GetError()}");
            }
            return(new Texture(texture, this));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a texture with the specified dimensions, format and access
        /// type.
        /// </summary>
        /// <param name="w">Width in pixels</param>
        /// <param name="h">Height in pixels</param>
        /// <param name="quality">Filtering quality when texture is scaled</param>
        /// <param name="format">Pixel format</param>
        /// <param name="access">Texture access type</param>
        public Texture CreateTexture(int w, int h,
                                     TextureScalingQuality quality = TextureScalingQuality.Nearest,
                                     PixelFormat format            = PixelFormat.Format_ARGB8888,
                                     TextureAccess access          = TextureAccess.Static)
        {
            Try(() =>
                SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, quality.AsHint()),
                "SDL_SetHint");
            var texture = SDL_CreateTexture(Handle, (uint)format, (int)access, w, h);

            if (texture == IntPtr.Zero)
            {
                throw new ImaginiException($"Could not create texture: {SDL_GetError()}");
            }
            return(new Texture(texture, this));
        }