Ejemplo n.º 1
0
        //Accessors

        //Methods

        static public TextureStruct GenerateTexture(IntPtr render, IntPtr font, string text, SDL_Color color)
        {
            TextureStruct finalTexture = new TextureStruct(IntPtr.Zero, 0, 0);
            IntPtr        textSurface  = TTF_RenderText_Solid(font, text, color);
            IntPtr        myTexture    = IntPtr.Zero;

            if (textSurface == IntPtr.Zero)
            {
                Console.Write("Unable to render text surface! SDL_ttf Error: %s\n", SDL_GetError());
            }
            else
            {
                //Create texture from surface pixels
                myTexture = SDL_CreateTextureFromSurface(render, textSurface);
                if (myTexture == IntPtr.Zero)
                {
                    Console.Write("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError());
                }
                //Create texture struct
                finalTexture.h       = ((SDL_Surface)Marshal.PtrToStructure(textSurface, typeof(SDL_Surface))).h;
                finalTexture.w       = ((SDL_Surface)Marshal.PtrToStructure(textSurface, typeof(SDL_Surface))).w;
                finalTexture.texture = myTexture;
                //Get rid of old surface
                SDL_FreeSurface(textSurface);
            }
            return(finalTexture);
        }
Ejemplo n.º 2
0
        private TextureStruct ImageTotexture(IntPtr render, string imagePath, byte r, byte g, byte b)
        {
            TextureStruct finalTexture = new TextureStruct(IntPtr.Zero, 0, 0);
            IntPtr        sprite       = IntPtr.Zero;

            sprite = SDL_LoadBMP(imagePath);
            if (sprite == IntPtr.Zero)
            {
                Console.Write("Unable to load image: ball.bmp! SDL Error:" + SDL_GetError() + " \n");
                Console.Write(imagePath + " \n");
                SDL_FreeSurface(sprite);
                return(finalTexture);
            }
            //Set Colorkey
            var format = ((SDL_Surface)Marshal.PtrToStructure(sprite, typeof(SDL_Surface))).format;

            SDL_SetColorKey(sprite, 1, SDL_MapRGB(format, r, g, b));

            IntPtr myTexture = SDL_CreateTextureFromSurface(render, sprite);

            if (myTexture == IntPtr.Zero)
            {
                Console.Write("Unable to create texture! SDL Error:" + SDL_GetError() + " \n");
                Console.Write(imagePath + " \n");
                SDL_FreeSurface(sprite);
                return(finalTexture);
            }

            finalTexture.h       = ((SDL_Surface)Marshal.PtrToStructure(sprite, typeof(SDL_Surface))).h;
            finalTexture.w       = ((SDL_Surface)Marshal.PtrToStructure(sprite, typeof(SDL_Surface))).w;
            finalTexture.texture = myTexture;

            SDL_FreeSurface(sprite);
            return(finalTexture);
        }
Ejemplo n.º 3
0
        //Constructors
        public SpriteEntity(string key, IntPtr render, string imagePath, byte r, byte g, byte b)
        {
            TextureStruct texture = ImageTotexture(render, imagePath, r, g, b);

            textureList.Add(key, texture);
            SetupSpriteEntity(key);
            //TODO: handle duplicate keys
        }
Ejemplo n.º 4
0
 public SpriteEntity(string key, TextureStruct texture)
 {
     textureList.Add(key, texture);
     SetupSpriteEntity(key);
     //TODO: handle duplicate keys or textures
 }
Ejemplo n.º 5
0
 public void ReplaceTexture(TextureStruct newtexture)
 {
     SDL_DestroyTexture(textureList[name].texture);
     textureList[name] = newtexture;
 }