예제 #1
0
        void IGraphicsDriver.RenderCharacter(RenderPoint point, RenderSize size, byte flags, byte[] pixels, int pixelsHeight, int pixelsWidth)
        {
            int fontScaleX = (this.displayScaleX * size.Width) / pixelsWidth;
            int fontScaleY = (this.displayScaleY * size.Height) / pixelsHeight;

            SDL_Surface surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface));

            for (int i = 0; i < pixelsWidth; i++)
            {
                int positionX = (point.X * this.displayScaleX) + (i * fontScaleX);

                for (int j = 0; j < pixelsHeight; j++)
                {
                    int positionY = (point.Y * this.displayScaleY) + (j * fontScaleY);

                    byte pixel = pixels[(j * pixelsWidth) + i];

                    for (int deltaY = 0; deltaY < fontScaleY; deltaY++)
                    {
                        for (int deltaX = 0; deltaX < fontScaleX; deltaX++)
                        {
                            Marshal.WriteByte(new IntPtr(surface.pixels.ToInt32() + ((positionY + deltaY) * surface.pitch) + (positionX + deltaX)), pixel);
                        }
                    }
                }
            }
        }
예제 #2
0
        void IGraphicsDriver.Scroll(RenderRectangle rect, int lineCountRenderPoints)
        {
            // all these coordinates are in render buffer coordinates (320x200 or 640x400)
            SDL_Surface surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface));

            int scaledX      = rect.X * this.displayScaleX;
            int scaledY      = rect.Y * this.displayScaleY;
            int scaledWidth  = rect.Width * this.displayScaleX;
            int scaledHeight = rect.Height * this.displayScaleY;

            int targetY       = scaledY;
            int sourceYOffset = lineCountRenderPoints * this.displayScaleY;

            // Temp buffer
            byte[] buffer = new byte[scaledWidth];

            for (int j = 0; j < scaledHeight; j++)
            {
                IntPtr targetPtr = new IntPtr(surface.pixels.ToInt32() + (targetY * surface.pitch) + scaledX);
                IntPtr sourcePtr = new IntPtr(surface.pixels.ToInt32() + ((targetY + sourceYOffset) * surface.pitch) + scaledX);

                Marshal.Copy(sourcePtr, buffer, 0, scaledWidth);
                Marshal.Copy(buffer, 0, targetPtr, scaledWidth);

                targetY += lineCountRenderPoints > 0 ? 1 : -1;
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a copy of a region of this surface.
        /// </summary>
        /// <param name="region">The region of this surface to copy.</param>
        /// <returns>A new surface which is a copy of the specified region of this surface.</returns>
        public override Surface2D CreateSurface(Rectangle region)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            if (region.Left < 0 || region.Top < 0 || region.Right > Width || region.Bottom > Height || region.Width <= 0 || region.Height <= 0)
            {
                throw new ArgumentOutOfRangeException("region");
            }

            var copysurf = new SDL_Surface(region.Width, region.Height);

            var srcrect = new SDL_Rect()
            {
                x = region.X, y = region.Y, w = region.Width, h = region.Height
            };
            var dstrect = new SDL_Rect()
            {
                x = 0, y = 0, w = region.Width, h = region.Height
            };

            if (SDL.BlitSurface(nativesurf.Native, &srcrect, copysurf.Native, &dstrect) < 0)
            {
                throw new SDL2Exception();
            }

            return(new OpenGLSurface2D(Ultraviolet, copysurf));
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the OpenGLTexture2D class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="surface">The SDL surface from which to create the texture.</param>
        public OpenGLTexture2D(UltravioletContext uv, SDL_Surface surface)
            : base(uv)
        {
            Contract.Require(surface, nameof(surface));

            var mode           = gl.GL_NONE;
            var internalformat = gl.GL_NONE;

            if (surface.BytesPerPixel == 3)
            {
                mode           = gl.GL_RGB;
                internalformat = gl.IsGLES2 ? gl.GL_RGB : gl.GL_RGB;
            }
            if (surface.BytesPerPixel == 4)
            {
                mode           = gl.GL_RGBA;
                internalformat = gl.IsGLES2 ? gl.GL_RGBA : gl.GL_RGBA8;
            }

            if (mode == gl.GL_NONE)
            {
                throw new NotSupportedException(OpenGLStrings.UnsupportedImageType);
            }

            CreateNativeTexture(uv, internalformat, surface.Width, surface.Height, mode,
                                gl.GL_UNSIGNED_BYTE, surface.Native->pixels, true);
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the OpenGLSurface2D class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="nativesurf">The native SDL surface that this object represents.</param>
        public OpenGLSurface2D(UltravioletContext uv, SDL_Surface nativesurf)
            : base(uv)
        {
            if (nativesurf == null)
            {
                throw new ArgumentNullException("nativesurf");
            }

            this.nativesurf = nativesurf;
        }
예제 #6
0
        void IGraphicsDriver.Shake(byte count)
        {
            const int Offset = 3;
            const int Delay  = 100;

            int scaledOffsetX = Offset * this.displayScaleX;
            int scaledOffsetY = Offset * this.displayScaleY;

            SDL_Surface surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface));

            // Save screen
            byte[] backup = new byte[surface.pitch * this.displayHeight];
            Marshal.Copy(surface.pixels, backup, 0, surface.pitch * this.displayHeight);

            for (byte c = 0; c < count; c++)
            {
                SDL_Delay(Delay);

                // Draw black on left
                SDL_Rect leftRect = new SDL_Rect()
                {
                    x = (short)0, y = (short)0, w = (short)scaledOffsetX, h = (short)this.displayHeight
                };
                SDL_FillRect(this.surfacePtr, ref leftRect, 0);

                // Draw black on top
                SDL_Rect topRect = new SDL_Rect()
                {
                    x = (short)0, y = (short)0, w = (short)this.displayWidth, h = (short)scaledOffsetY
                };
                SDL_FillRect(this.surfacePtr, ref topRect, 0);

                // Draw screen at offset
                for (int j = 0; j < this.displayHeight - scaledOffsetY; j++)
                {
                    int x = surface.pixels.ToInt32() + ((j + scaledOffsetY) * surface.pitch) + scaledOffsetY;

                    int    length = this.displayWidth - scaledOffsetX;
                    IntPtr ptr    = new IntPtr(x);
                    Marshal.Copy(backup, j * surface.pitch, ptr, length);
                }

                SDL_UpdateWindowSurface(this.windowPtr);

                SDL_Delay(Delay);

                // Restore screen
                Marshal.Copy(backup, 0, surface.pixels, surface.pitch * this.displayHeight);

                SDL_UpdateWindowSurface(this.windowPtr);
            }
        }
예제 #7
0
        void Draw()
        {
            //while(CPUexecuting){ }
            while (owner.GPU.drawing)
            {
            }

            SDL_Surface surf = (SDL_Surface)Marshal.PtrToStructure(Surface, typeof(SDL_Surface));

            if (Pixels == null)
            {
                return;
            }

            for (int y = 0; y < 144; y++)
            {
                for (int x = 0; x < 160; x++)
                {
                    byte r, g, b;
                    if (Pixels[x, y] == 0)
                    {
                        r = Palette.blankR;
                        g = Palette.blankG;
                        b = Palette.blankB;
                    }
                    else if (Pixels[x, y] == 1)
                    {
                        r = Palette.lightR;
                        g = Palette.lightG;
                        b = Palette.lightB;
                    }
                    else if (Pixels[x, y] == 2)
                    {
                        r = Palette.darkR;
                        g = Palette.darkG;
                        b = Palette.darkB;
                    }
                    else
                    {
                        r = Palette.solidR;
                        g = Palette.solidG;
                        b = Palette.solidB;
                    }
                    var rect = new SDL_Rect {
                        x = x * Scale, y = y * Scale, w = Scale, h = Scale
                    };
                    SDL_FillRect(Surface, ref rect, SDL_MapRGBA(surf.format, r, g, b, 255));
                }
            }
            SDL_UpdateWindowSurface(Window);
        }
예제 #8
0
        /// <summary>
        /// Creates a texture from the surface.
        /// </summary>
        /// <param name="premultiplyAlpha">A value indicating whether to premultiply the surface's alpha when creating the texture.</param>
        /// <returns>The texture that was created from the surface.</returns>
        public override Texture2D CreateTexture(Boolean premultiplyAlpha)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            using (var copysurf = new SDL_Surface(Width, Height))
            {
                if (SDL.SetSurfaceBlendMode(nativesurf.Native, SDL_BlendMode.NONE) < 0)
                {
                    throw new SDL2Exception();
                }

                if (SDL.BlitSurface(nativesurf.Native, null, copysurf.Native, null) < 0)
                {
                    throw new SDL2Exception();
                }

                copysurf.PrepareForTextureExport(premultiplyAlpha);
                return(new OpenGLTexture2D(Ultraviolet, copysurf));
            }
        }
예제 #9
0
        void IGraphicsDriver.SetPalette(GraphicsColor[] colors)
        {
            //for (int i = 0; i < colors.Length; i++)
            //{
            //    this.palette[i] = (uint)(((byte)0xff << 24) | (colors[i].R << 16) | (colors[i].G << 8) | colors[i].B);
            //}
            SDL_Color[] palette = new SDL_Color[colors.Length];
            for (int i = 0; i < colors.Length; i++)
            {
                palette[i].r = colors[i].R;
                palette[i].g = colors[i].G;
                palette[i].b = colors[i].B;
                //palette[i].unused = 0;
            }

            SDL_Surface     surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface));
            SDL_PixelFormat format  = (SDL_PixelFormat)Marshal.PtrToStructure(surface.format, typeof(SDL_PixelFormat));

            SDL_SetPaletteColors(format.palette, palette, 0, palette.Length);

            this.texturePtr = SDL_CreateTextureFromSurface(this.rendererPtr, this.surfacePtr);
        }
예제 #10
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		private static extern IntPtr INTERNAL_SDL_ConvertSurfaceFormat(
			ref SDL_Surface src,
			uint pixel_format,
			uint flags
		);
예제 #11
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern IntPtr SDL_CreateTextureFromSurface(
			IntPtr renderer,
			ref SDL_Surface surface
		);
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the OpenGLSurface2D class.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="source">The surface source from which to create the surface.</param>
 public OpenGLSurface2D(UltravioletContext uv, SurfaceSource source)
     : this(uv, SDL_Surface.CreateFromSurfaceSource(source))
 {
 }
예제 #13
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_UpperBlitScaled(
			ref SDL_Surface src,
			ref SDL_Rect srcrect,
			ref SDL_Surface dst,
			ref SDL_Rect dstrect
		);
예제 #14
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern void SDL_SetWindowIcon(
			IntPtr window,
			ref SDL_Surface icon
		);
예제 #15
0
        void IGraphicsDriver.RenderToScreen(RenderBuffer buffer, int offsetYRenderPoints, RenderPoint topLeft, RenderPoint bottomRight, bool fade)
        {
            // all these coordinates are in render buffer coordinates (320x200 or 640x400)
            byte[,] bytes = buffer.GetBuffer();

            SDL_Surface surface = (SDL_Surface)Marshal.PtrToStructure(this.surfacePtr, typeof(SDL_Surface));

            if (!fade)
            {
                for (int j = topLeft.Y; j < bottomRight.Y; j++)
                {
                    int positionY = (offsetYRenderPoints + j) * this.displayScaleY;

                    for (int i = topLeft.X; i < bottomRight.X; i++)
                    {
                        byte pixel = bytes[i, j];

                        int positionX = i * this.displayScaleX;

                        for (int deltaY = 0; deltaY < this.displayScaleY; deltaY++)
                        {
                            for (int deltaX = 0; deltaX < this.displayScaleX; deltaX++)
                            {
                                Marshal.WriteByte(new IntPtr(surface.pixels.ToInt32() + ((positionY + deltaY) * surface.pitch) + (positionX + deltaX)), pixel);
                            }
                        }
                    }
                }

                var rects = new SDL_Rect[]
                {
                    new SDL_Rect()
                    {
                        x = topLeft.X * this.displayScaleX,
                        y = (topLeft.Y + offsetYRenderPoints) * this.displayScaleY,
                        w = (bottomRight.X - topLeft.X) * this.displayScaleX,
                        h = (bottomRight.Y - topLeft.Y) * this.displayScaleY,
                    }
                };

                SDL_UpdateWindowSurfaceRects(this.windowPtr, rects, rects.Length);
            }
            else
            {
                const int Delay    = 50;
                byte[][]  fadeBits = new byte[][]
                {
                    new byte[] { 0, 11, 7, 15 },
                    new byte[] { 8, 4, 1, 12 },
                    new byte[] { 14, 2, 9, 5 },
                    new byte[] { 10, 6, 13, 3 },
                };

                for (int fadeCount = 0; fadeCount < 16; fadeCount++)
                {
                    for (int j = topLeft.Y; j < bottomRight.Y; j++)
                    {
                        int positionY = (offsetYRenderPoints + j) * this.displayScaleY;

                        for (int i = topLeft.X; i < bottomRight.X; i++)
                        {
                            if (fadeBits[i % 4][j % 4] == fadeCount)
                            {
                                byte pixel = bytes[i, j];

                                int positionX = i * this.displayScaleX;

                                for (int deltaY = 0; deltaY < this.displayScaleY; deltaY++)
                                {
                                    for (int deltaX = 0; deltaX < this.displayScaleX; deltaX++)
                                    {
                                        Marshal.WriteByte(new IntPtr(surface.pixels.ToInt32() + ((positionY + deltaY) * surface.pitch) + (positionX + deltaX)), pixel);
                                    }
                                }
                            }
                        }
                    }

                    var rects = new SDL_Rect[]
                    {
                        new SDL_Rect()
                        {
                            x = topLeft.X * this.displayScaleX,
                            y = (topLeft.Y + offsetYRenderPoints) * this.displayScaleY,
                            w = (bottomRight.X - topLeft.X) * this.displayScaleX,
                            h = (bottomRight.Y - topLeft.Y) * this.displayScaleY,
                        }
                    };

                    SDL_UpdateWindowSurfaceRects(this.windowPtr, rects, rects.Length);

                    SDL_Delay(Delay);
                }
            }

            var src = new SDL_Rect()
            {
                x = topLeft.X * this.displayScaleX,
                y = (topLeft.Y + offsetYRenderPoints) * this.displayScaleY,
                w = (bottomRight.X - topLeft.X) * this.displayScaleX,
                h = (bottomRight.Y - topLeft.Y) * this.displayScaleY,
            };

            SDL_RenderCopy(this.rendererPtr, this.texturePtr, ref src, ref src);
            SDL_RenderPresent(this.rendererPtr);
        }
예제 #16
0
 public void draw(SDL_Surface Surface)
 {
     // Code for Draw
     m_surface = Surface;     // maybe, need to check datatype.
 }
예제 #17
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_GetColorKey(
			ref SDL_Surface surface,
			ref uint key
		);
예제 #18
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_GetSurfaceColorMod(
			ref SDL_Surface surface,
			ref byte r,
			ref byte g,
			ref byte b
		);
예제 #19
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern void SDL_FreeSurface(ref SDL_Surface surface);
예제 #20
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern void SDL_GetClipRect(
			ref SDL_Surface surface,
			ref SDL_Rect rect
		);
예제 #21
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_FillRects(
			ref SDL_Surface dst,
			SDL_Rect[] rects,
			int count,
			uint color
		);
예제 #22
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_FillRect(
			ref SDL_Surface dst,
			ref SDL_Rect rect,
			uint color
		);
예제 #23
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static SDL_Surface SDL_ConvertSurfaceFormat(
			ref SDL_Surface src,
			uint pixel_format,
			uint flags
		) {
			SDL_Surface result;
			IntPtr result_ptr = INTERNAL_SDL_ConvertSurfaceFormat(
				ref src,
				pixel_format,
				flags
			);
			result = (SDL_Surface) Marshal.PtrToStructure(
				result_ptr,
				result.GetType()
			);
			return result;
		}
예제 #24
0
 public static void SDL_FreeSurface(SDL_Surface Sdl2Surface) => FreeSurfaceImpl(Sdl2Surface);
예제 #25
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_LockSurface(ref SDL_Surface surface);
예제 #26
0
        /// <summary>
        /// Identifies the positions of the glyphs on the specified surface.
        /// </summary>
        /// <param name="surface">The surface on which to identify glyphs.</param>
        /// <param name="source">The region on the surface in which to look for glyphs, or null to examine the entire surface.</param>
        /// <returns>A collection of rectangles describing the positions of the glyphs on the specified surface.</returns>
        public static IEnumerable <Rectangle> IdentifyGlyphs(SDL_Surface surface, Rectangle?source = null)
        {
            if (source.HasValue && (source.Value.Width > surface.Width | source.Value.Height > surface.Height))
            {
                throw new ArgumentOutOfRangeException("source");
            }

            var regionValue = source ?? new Rectangle(0, 0, surface.Width, surface.Height);
            var data        = new Color[regionValue.Width * regionValue.Height];

            surface.GetData(data, regionValue);

            // Find the glyphs on the texture.
            var positions = new List <Rectangle>();
            var nextLine  = 0;
            var nextGlyph = 0;

            for (int y = 0; y < regionValue.Height; y = nextLine)
            {
                nextLine = y + 1;
                for (int x = 0; x < regionValue.Width; x = nextGlyph)
                {
                    nextGlyph = x + 1;

                    // Skip buffer pixels.
                    var pixel = data[y * regionValue.Width + x];
                    if (pixel.Equals(Color.Magenta))
                    {
                        continue;
                    }

                    // Find the width of the glyph.
                    var x2 = x + 1;
                    while (x2 < regionValue.Width)
                    {
                        if (data[y * regionValue.Width + x2++].Equals(Color.Magenta))
                        {
                            break;
                        }
                    }
                    var glyphWidth = (x2 - x) - 1;

                    // Find the height of the glyph.
                    var y2 = y + 1;
                    while (y2 < regionValue.Height)
                    {
                        if (data[y2++ *regionValue.Width + x].Equals(Color.Magenta))
                        {
                            break;
                        }
                    }
                    var glyphHeight = (y2 - y) - 1;

                    // Calculate the position of the next glyph and the next line of glyphs.
                    nextGlyph = x + glyphWidth + 1;
                    if (y + glyphHeight > nextLine)
                    {
                        nextLine = y + glyphHeight + 1;
                    }

                    // Store the glyph's position.
                    positions.Add(new Rectangle(regionValue.X + x, regionValue.Y + y, glyphWidth, glyphHeight));
                }
            }
            return(positions);
        }
예제 #27
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_LowerBlit(
			ref SDL_Surface src,
			ref SDL_Rect srcrect,
			ref SDL_Surface dst,
			ref SDL_Rect dstrect
		);
예제 #28
0
        public FC_Font(IntPtr ttf, IntPtr gRenderer, SDL_Color color)
        {
            height        = TTF_FontHeight(ttf);
            heightPadd    = height + 1;
            ascent        = TTF_FontAscent(ttf);
            descent       = -TTF_FontDescent(ttf);
            baseline      = height - descent;
            default_color = color;

            int w = heightPadd * 12;
            int h = heightPadd * 12;
            // FontTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA8888, (int)SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, w * 16, h * 16);
            // SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING

            IntPtr   fontSurface = SDL_CreateRGBSurface(0, h, w, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
            SDL_Rect cursorRect  = new SDL_Rect();

            for (int i = 0; i < 144; i++)
            {
                byte[] charByte = new byte[1] {
                    (byte)(i + 33)
                };
                char   letter       = Encoding.ASCII.GetString(charByte, 0, 1)[0];
                IntPtr glyphSurface = TTF_RenderUTF8_Blended(ttf, letter.ToString(), color);
                if (glyphSurface != IntPtr.Zero)
                {
                    SDL_Surface glyphSurfaceT = Marshal.PtrToStructure <SDL_Surface>(glyphSurface);

                    // IntPtr glyphTexture = SDL_CreateTextureFromSurface(gRenderer, glyphSurface);
                    // SDL_Rect destRect = new SDL_Rect() { x = (i % 12) * height, y = (i / 12) * height, h = height, w = height };

                    SDL_Rect srcRect = new SDL_Rect {
                        x = 0, y = 0, w = glyphSurfaceT.w, h = glyphSurfaceT.h
                    };
                    cursorRect.w = srcRect.w;
                    cursorRect.h = srcRect.h;

                    //drop to next line
                    if (cursorRect.x + cursorRect.w > w)
                    {
                        cursorRect.x  = 0;
                        cursorRect.y += heightPadd;
                    }


                    // SDL_Rect destRect = new SDL_Rect() { x = (i % 12) * height, y = (i / 12) * height, h = height, w = height };

                    // SDL_SetTextureBlendMode(glyphTexture, SDL_BlendMode.SDL_BLENDMODE_BLEND);

                    //Render Glyph
                    SDL_SetSurfaceBlendMode(glyphSurface, SDL_BlendMode.SDL_BLENDMODE_NONE);
                    // SDL_BlitSurface(glyphSurface, ref srcRect, fontSurface, ref destRect);
                    SDL_BlitSurface(glyphSurface, ref srcRect, fontSurface, ref cursorRect);

                    if (cursorRect.w % 2 != 0)
                    {
                        cursorRect.w++;
                    }
                    if (cursorRect.h % 2 != 0)
                    {
                        cursorRect.h++;
                    }

                    if (!Glyphs.ContainsKey(letter))
                    {
                        Glyphs.Add(letter, new Glyph()
                        {
                            code     = (ushort)(i + 33),
                            width    = (byte)cursorRect.w,
                            height   = (byte)cursorRect.h,
                            textureX = cursorRect.x,
                            textureY = cursorRect.y,
                        });
                    }

                    cursorRect.x += cursorRect.w;
                    // SDL_SetTextureBlendMode(glyphTexture, SDL_BlendMode.SDL_BLENDMODE_BLEND);
                    // SDL_RenderCopy(gRenderer, glyphTexture, IntPtr.Zero, ref destRect);

                    // SDL_DestroyTexture(glyphTexture);
                    SDL_FreeSurface(glyphSurface);
                }
            }

            FontTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA8888, (int)SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, w, h);
            SDL_SetTextureBlendMode(FontTexture, SDL_BlendMode.SDL_BLENDMODE_BLEND);
            SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");

            SDL_SetRenderTarget(gRenderer, FontTexture);
            SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
            SDL_RenderClear(gRenderer);

            IntPtr glyphTexture = SDL_CreateTextureFromSurface(gRenderer, fontSurface);

            SDL_RenderCopy(gRenderer, glyphTexture, IntPtr.Zero, IntPtr.Zero);

            SDL_DestroyTexture(glyphTexture);
            SDL_FreeSurface(fontSurface);

            SDL_SetRenderTarget(gRenderer, IntPtr.Zero);
        }
예제 #29
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern SDL_bool SDL_MUSTLOCK(ref SDL_Surface surface);
예제 #30
0
 public static void SDL_BlitScaled(SDL_Surface src, SDL_Rect srcRect, SDL_Surface dst, SDL_Rect dstRect) => BlitScaledImpl(src, srcRect, dst, dstRect);
예제 #31
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SaveBMP(
			ref SDL_Surface surface,
			[InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)]
				string file
		);
예제 #32
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern IntPtr SDL_CreateColorCursor(
			ref SDL_Surface surface,
			int hot_x,
			int hot_y
		);
예제 #33
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern SDL_bool SDL_SetClipRect(
			ref SDL_Surface surface,
			ref SDL_Rect rect
		);
예제 #34
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern IntPtr SDL_CreateRenderer(
			ref SDL_Surface surface
		);
 static extern int SDL_SaveBMP_RW(SDL_Surface* surface, IntPtr dst, int freedst);
 static extern int SDL_UnlockSurface(SDL_Surface* surface);
예제 #37
0
 public static IntPtr SDL_CreateColorCursor(ref SDL_Surface surface, int hot_x, int hot_y) => s_SDL_CreateColorCursor_SDL_Surface_int_int_t(ref surface, hot_x, hot_y);
예제 #38
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SetColorKey(
			ref SDL_Surface surface,
			int flag,
			uint key
		);
예제 #39
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		private static extern IntPtr INTERNAL_SDL_ConvertSurface(
			ref SDL_Surface src,
			IntPtr fmt,
			uint flags
		);
예제 #40
0
 public static void SDL_SetWindowIcon(IntPtr window, ref SDL_Surface icon) => s_SDL_SetWindowIcon_IntPtr_SDL_Surface_t(window, ref icon);
예제 #41
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SetSurfaceAlphaMod(
			ref SDL_Surface surface,
			byte alpha
		);
예제 #42
0
 public static SDL_Cursor SDL_CreateColorCursor(SDL_Surface Sdl2Surface, int hotX, int hotY) => CreateColorCursorImpl(Sdl2Surface, hotX, hotY);
예제 #43
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SetSurfaceBlendMode(
			ref SDL_Surface surface,
			SDL_BlendMode blendMode
		);
예제 #44
0
 public static IntPtr SDL_CreateSoftwareRenderer(ref SDL_Surface surface) => s_SDL_CreateSoftwareRenderer_SDL_Surface_t(ref surface);
예제 #45
0
        unsafe public void LoadAsTexture(string fileLocation, string resourceName)
        {
            while (!EngineInit)
            {
                SDL_Delay(100);
            }
            if (_SDL_Renderer == IntPtr.Zero)
            {
                Debug.Log("ResourceManager.LoadAsTexture()", "SDL Renderer not yet initialized, waiting for init.");
                Debug.Log("ResourceManager.LoadAsTexture()", "Warning! Call 'GameEngine.Start()' first before loading game resources.");
                Debug.Log("ResourceManager.LoadAsTexture()", "Otherwise, this will be an endless loop.");
                while (_SDL_Renderer == IntPtr.Zero)
                {
                    SDL_Delay(100);
                }
                Debug.Log("ResourceManager.LoadAsTexture()", "SDL Renderer initialized.");
                //throw new ResourceException($"SDL Renderer not yet initialized, try calling GameEngine.InitGraphics() first", fileLocation);
            }
            if (_Textures.Contains(resourceName))
            {
                throw new ResourceException($"A resource with the same name '{resourceName}' already exists.", fileLocation);
            }
            if (!File.Exists(fileLocation))
            {
                throw new ResourceException($"Error loading resource '{resourceName}'. File not found.", fileLocation);
            }
            ZipArchive archive;

            try
            {
                archive = ZipFile.OpenRead(fileLocation);
            }
            catch
            {
                throw new ResourceException($"Error loading resource '{resourceName}'.", fileLocation);
            }
            // sort by name
            var           entries = archive.Entries.OrderBy(zip => zip.Name);
            bool          loadedMetadata = false;
            List <string> files = new List <string>();
            Size          spriteSize = new Size(), sheetSize = new Size();
            bool          isSheet = false;

            foreach (ZipArchiveEntry entry in entries)
            {
                if (entry.Name == "metadata")
                {
                    loadedMetadata = true;
                    using (Stream ms = entry.Open())
                    {
                        try
                        {
                            StreamReader reader = new StreamReader(ms);
                            string       json   = reader.ReadToEnd();
                            reader.Close();
                            JsonDocument doc  = JsonDocument.Parse(json);
                            var          meta = doc.RootElement;
                            isSheet      = meta.GetProperty("IsSheet").GetBoolean();
                            spriteSize.W = meta.GetProperty("SpriteSize").GetProperty("Width").GetInt32();
                            spriteSize.H = meta.GetProperty("SpriteSize").GetProperty("Height").GetInt32();
                            sheetSize.W  = meta.GetProperty("SheetSize").GetProperty("Width").GetInt32();
                            sheetSize.H  = meta.GetProperty("SheetSize").GetProperty("Height").GetInt32();
                            doc.Dispose();
                        } catch
                        {
                            throw new ResourceException($"Error parsing metadata for '{resourceName}'.", fileLocation);
                        }
                    }
                }
                else
                {
                    files.Add(entry.Name);
                }
            }
            if (!loadedMetadata && !FLAG_ALLOW_MISSING_METADATA)
            {
                archive.Dispose();
                throw new ResourceException($"Error loading resource '{resourceName}'. Metadata not found.", fileLocation);
            }
            List <IntPtr> surfaces = new List <IntPtr>();
            List <IntPtr> textures = new List <IntPtr>();

            /* Load resource here */
            SDL_GetError();
            foreach (string file in files)
            {
                try
                {
                    ZipArchiveEntry data   = archive.GetEntry(file);
                    Stream          s      = data.Open();
                    byte[]          buffer = new byte[data.Length];
                    s.Read(buffer, 0, buffer.Length);
                    string fn = "temp" + data.Name;
                    File.WriteAllBytes(fn, buffer);
                    //Marshal.Copy(buffer, 0, ptrArray, buffer.Length);
                    //GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    //IntPtr ptrArray = handle.AddrOfPinnedObject();
                    //IntPtr ptrArray = Marshal.AllocHGlobal(buffer.Length);
                    //s.Read(buffer, 0, buffer.Length);
                    //Marshal.Copy(buffer, 0, ptrArray, buffer.Length);
                    Debug.Log("ResourceManager.LoadAsTexture()", $"Read texture data from {file}#{resourceName} @ {buffer.Length} byte(s).");
                    //IntPtr rwops = SDL_RWFromMem(ptrArray, buffer.Length);
                    IntPtr surface = IMG_Load(fn);
                    //IntPtr surface = IMG_Load_RW(rwops, 0);
                    SDL_Surface sd = *(SDL_Surface *)surface;
                    File.Delete(fn);
                    string sE1 = SDL_GetError();
                    if (surface == IntPtr.Zero)// || rwops == IntPtr.Zero)
                    {
                        Debug.Log("ResourceManager.LoadAsTexture()", $"Error reading texture data {file}#{resourceName}. {sE1}");
                        continue;
                    }
                    Debug.Log("ResourceManager.LoadAsTexture()", $"Loaded texture data as surface from {file}#{resourceName}.");
                    IntPtr texture;
                    while (_SDL_Renderer == IntPtr.Zero)
                    {
                        SDL_Delay(100);
                    }
                    try
                    {
                        texture = SDL_CreateTextureFromSurface(_SDL_Renderer, surface);
                    } catch (Exception e)
                    {
                        Debug.Log("ResourceManager.LoadAsTexture()", $"Error creating texture data {file}#{resourceName}. {e.Message}");
                        continue;
                    }
                    string sE2 = SDL_GetError();
                    if (texture == IntPtr.Zero)
                    {
                        Debug.Log("ResourceManager.LoadAsTexture()", $"Error creating texture data {file}#{resourceName}. {sE2}");
                        continue;
                    }
                    surfaces.Add(surface);
                    textures.Add(texture);
                    Debug.Log("ResourceManager.LoadAsTexture()", $"Created texture from surface {file}#{resourceName}.");
                    //SDL_FreeSurface(surface);
                    //Marshal.FreeHGlobal(ptrArray);
                    //handle.Free();
                    //SDL_RWclose(rwops);
                } catch
                {
                    Debug.Log("ResourceManager.LoadAsTexture()", $"Error loading texture {file}#{resourceName}. Skipped file.");
                }
            }
            archive.Dispose();
            TextureResource res = new TextureResource()
            {
                IsSpriteSheet = isSheet,
                SheetSize     = sheetSize,
                SpriteSize    = spriteSize,
                DataPtr       = surfaces.ToArray(),
                Textures      = textures.ToArray(),
                ResourceName  = resourceName
            };

            _Textures.Add(res);
            Debug.Log("ResourceManager.LoadAsTexture()", $"Successfully added texture {resourceName} to resources.");
        }
예제 #46
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SetSurfacePalette(
			ref SDL_Surface surface,
			IntPtr palette
		);
예제 #47
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SetSurfaceRLE(
			ref SDL_Surface surface,
			int flag
		);
예제 #48
0
 public static bool SDL_MUSTLOCK(SDL_Surface S) =>
 ((S.flags & SDL_RLEACCEL) != 0);
예제 #49
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SoftStretch(
			ref SDL_Surface src,
			ref SDL_Rect srcrect,
			ref SDL_Surface dst,
			ref SDL_Rect dstrect
		);
예제 #50
0
 internal Surface(IntPtr surfacePointer)
 {
     _surfacePointer = surfacePointer;
     _surface        = Marshal.PtrToStructure <SDL_Surface>(_surfacePointer);
 }
예제 #51
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern void SDL_UnlockSurface(ref SDL_Surface surface);
예제 #52
0
파일: SDL2.cs 프로젝트: pakoito/SDL2-CS
		public static extern int SDL_SetSurfaceColorMod(
			ref SDL_Surface surface,
			byte r,
			byte g,
			byte b
		);
 static extern void SDL_UpdateRect(SDL_Surface* surface, int x, int y, int width, int height);