Exemplo n.º 1
0
        public unsafe GLTexture(string name, SDL2.SDL.SDL_Surface source)
        {
            Name   = name;
            Width  = source.w;
            Height = source.h;

            GLHelper.Texture(TextureTarget.Texture2D, name, out int gt);
            GL.BindTexture(TextureTarget.Texture2D, gt);

            GL.TextureStorage2D(gt, 1, SizedInternalFormat.Rgba16, Width, Height);

            var fmt = PixelInternalFormat.Rgb;

            var surfmt = (SDL2.SDL.SDL_PixelFormat *)(source.format.ToPointer());

            if (surfmt->BytesPerPixel == 4)
            {
                // We're in RGBA land
                fmt = PixelInternalFormat.Rgba;
            }

            GL.TexImage2D(TextureTarget.Texture2D, 0, fmt, Width, Height, 0, (PixelFormat)fmt, PixelType.UnsignedByte, source.pixels);

            GLObject = gt;

            SetMinFilter(TextureMinFilter.Nearest);
            SetMagFilter(TextureMagFilter.Nearest);
        }
Exemplo n.º 2
0
        public static Texture Texture(string path)
        {
            if (textures == null)
            {
                textures = new Dictionary <string, Texture>();
            }
            if (!textures.ContainsKey(path))
            {
                var texturePath = LoadPath(path);

                SDL2.SDL.SDL_Surface surface = System.Runtime.InteropServices.Marshal.PtrToStructure <SDL2.SDL.SDL_Surface>(SDL2.SDL_image.IMG_Load(texturePath));
                var texture = new Texture(surface.pixels, surface.w, surface.h);
                textures.Add(path, texture);
            }
            return(textures[path]);
        }
Exemplo n.º 3
0
        public static Texture Texture(string path)
        {
            if (textures == null)
            {
                textures = new Dictionary <string, Texture>();
            }
            if (!textures.ContainsKey(path))
            {
                var texturePath = LoadPath(path);

                var imgPtr = SDL2.SDL_image.IMG_Load(texturePath);

                if (imgPtr == IntPtr.Zero)
                {
                    throw new NotImplementedException("TODO: We need to be able to recover from a non-existent texture");
                }

                SDL2.SDL.SDL_Surface surface = System.Runtime.InteropServices.Marshal.PtrToStructure <SDL2.SDL.SDL_Surface>(imgPtr);
                var texture = new Texture(surface.pixels, surface.w, surface.h);
                textures.Add(path, texture);
            }
            return(textures[path]);
        }