Пример #1
0
        public void LoadPNG()
        {
            string file       = "test.png";
            IntPtr surfacePtr = VideoSetup();
            IntPtr imagePtr   = SdlImage.IMG_LoadPNG_RW(Sdl.SDL_RWFromFile(file, "rb"));

            Assert.IsFalse(imagePtr == IntPtr.Zero);
            Sdl.SDL_Rect rect1  = new Sdl.SDL_Rect(0, 0, 200, 200);
            Sdl.SDL_Rect rect2  = new Sdl.SDL_Rect(0, 0, 200, 200);
            int          result = Sdl.SDL_BlitSurface(imagePtr, ref rect1, surfacePtr, ref rect2);

            Sdl.SDL_UpdateRect(surfacePtr, 0, 0, 200, 200);
            Thread.Sleep(sleepTime);
            Assert.AreEqual(result, 0);
            this.Quit();
        }
Пример #2
0
        } //Stuff that goes before load content

        static void Init_LoadContent()
        {
            vera     = SdlTtf.TTF_OpenFont("Content/Fonts/Vera.ttf", 24);                           //Load in 12-point Vera font.
            veraData = (SdlTtf.TTF_Font)Marshal.PtrToStructure(vera, typeof(SdlTtf.TTF_Font));      //Put the font data in its place

            veraSmall     = SdlTtf.TTF_OpenFont("Content/Fonts/Vera.ttf", 10);                      //Load in 12-point Vera font.
            veraSmallData = (SdlTtf.TTF_Font)Marshal.PtrToStructure(vera, typeof(SdlTtf.TTF_Font)); //Put the font data in its place

            DrawText(veraSmall, "Pre-initialization complete", new Point2D(15, 15));
            DrawText(veraSmall, "Fonts loaded; loading images...", new Point2D(15, 30));
            Sdl.SDL_Flip(screen); //Update screen

            IntPtr rwop    = Sdl.SDL_RWFromFile("Content/Tiles/ASCII_Tileset.PNG", "rb");
            IntPtr tileSet = SdlImage.IMG_LoadPNG_RW(rwop);

            short n = 0;

            target.w = source.w = TILEWIDTH;  //I love this combination thing
            target.h = source.h = TILEHEIGHT; //It's so elegant

            for (byte y = 0; y < 16; y++)
            {
                for (byte x = 0; x < 16; x++)                                                                      //16x16 tiles
                {
                    source.x = (short)(x * 17);                                                                    //X to grab from
                    source.y = (short)(y * 17);                                                                    //Y to grab from

                    image[n] = Sdl.SDL_CreateRGBSurface(Sdl.SDL_SWSURFACE, TILEWIDTH, TILEHEIGHT, 32, 0, 0, 0, 0); //Allocate image area
                    Sdl.SDL_BlitSurface(tileSet, ref source, image[n], ref target);
                    image[n]     = Sdl.SDL_DisplayFormatAlpha(image[n]);
                    imageData[n] = (Sdl.SDL_Surface)Marshal.PtrToStructure(image[n], typeof(Sdl.SDL_Surface)); //Put the image data in its place
                    Transparencify(n, Color.Magenta);                                                          //Magenta is the transparent color
                    image[n]     = Sdl.SDL_DisplayFormatAlpha(image[n]);
                    imageData[n] = (Sdl.SDL_Surface)Marshal.PtrToStructure(image[n], typeof(Sdl.SDL_Surface)); //Put the image data in its place
                    n++;
                }
            }

            DrawText(veraSmall, "Creatures loaded. External content loading complete.", new Point2D(15, 120));
            DrawText(veraSmall, "Post-initializing...", new Point2D(15, 135));
            Sdl.SDL_Flip(screen); //Update screen
        } //Loads in the external content