/// <summary> /// Copies a portion of the texture to the current rendering target. /// </summary> /// <param name="texture">Texture to copy</param> /// <param name="srcRect">Source rectangle (null for copying whole texture)</param> /// <param name="dstRect">Destination rectangle (null to fill the entire render target)</param> /// <param name="angle"> /// Angle in degrees that indicates the rotation that will be applied /// to dstRect, rotating it in a clockwise direction /// </param> /// <param name="center"> /// Point around which dstRect will be rotated (if null, rotation will be /// done around dstRect's center) /// </param> /// <param name="flip"> /// Flipping actions that should be performed on the texture /// </param> public void Draw(Texture texture, Rectangle?srcRect, Rectangle?dstRect, double angle = 0.0, Point?center = null, TextureFlip flip = TextureFlip.None) { var srcR = Pin(srcRect?.ToSDL()); var dstR = Pin(dstRect?.ToSDL()); var cntr = Pin(center?.ToSDL()); try { unsafe { Try(() => SDL_RenderCopyEx(Handle, texture.Handle, (SDL_Rect *)srcR.AddrOfPinnedObject(), (SDL_Rect *)dstR.AddrOfPinnedObject(), angle, (SDL_Point *)cntr.AddrOfPinnedObject(), (SDL_RendererFlip)flip), "SDL_RenderCopyEx"); } } finally { srcR.Free(); dstR.Free(); cntr.Free(); } }
/// <summary> /// Copies a portion of the texture to the current rendering target. /// </summary> /// <param name="texture">Texture to copy</param> /// <param name="srcRect">Source rectangle (null for copying whole texture)</param> /// <param name="dstRect">Destination rectangle (null to fill the entire render target)</param> /// <param name="angle"> /// Angle in degrees that indicates the rotation that will be applied /// to dstRect, rotating it in a clockwise direction /// </param> /// <param name="center"> /// Point around which dstRect will be rotated (if null, rotation will be /// done around dstRect's center) /// </param> /// <param name="flip"> /// Flipping actions that should be performed on the texture /// </param> /// <param name="tint">Tint color to be applied on the texture</param> public void Draw(Texture texture, Rectangle?srcRect, Rectangle?dstRect, Color tint, double angle = 0.0, Point?center = null, TextureFlip flip = TextureFlip.None) { var oldTint = texture.Tint; texture.Tint = tint; Draw(texture, srcRect, dstRect, angle, center, flip); texture.Tint = oldTint; }
public void Render(int x, int y, Vector2 position = default(Vector2), Vector2 origin = default(Vector2), float angle = default(float), Color? color = null, TextureFlip textureFlip = default(TextureFlip), RectangleF subRegion = default(RectangleF), float scale = 1, float zIndex = 0) { RectangleF newSubRegion = new RectangleF(x * Size.X, y * Size.Y, Size.X, Size.Y); if (!subRegion.IsEmpty) { newSubRegion.X += subRegion.X; newSubRegion.Y += subRegion.Y; newSubRegion.Width = Math.Min(subRegion.Width, Size.X); newSubRegion.Height = Math.Min(subRegion.Height, Size.Y); } Texture.Render(position, origin, angle, color, textureFlip, newSubRegion, scale, zIndex); }
public static Texture FromFile(string FileName, TextureRotation rotation, TextureFlip flip) { if (texturesByFileName.ContainsKey(FileName)) { Texture tex = texturesByFileName[FileName]; tex.Rotation = rotation; tex.Flip = flip; return(tex); } uint[] textureIDs = new uint[1]; Internal.OpenGL.Methods.glGenTextures(1, textureIDs); uint textureID = textureIDs[0]; Texture texture = new Texture(textureID); texture.Target = TextureTarget.Texture2D; texture.FileName = FileName; texture.MinFilter = TextureFilter.Linear; texture.MagFilter = TextureFilter.Linear; // texture.TextureWrapR = TextureWrap.Repeat; texture.TextureWrapS = TextureWrap.Repeat; texture.TextureWrapT = TextureWrap.Repeat; texture.Rotation = rotation; texture.Flip = flip; if (!texturesByID.ContainsKey(textureID)) { texturesByID.Add(textureID, texture); } if (!texturesByFileName.ContainsKey(FileName)) { texturesByFileName.Add(FileName, texture); } return(texture); }
private void UpdateTexture(ref Rect textureRect, ref Vector2 textureSize, TextureFlip flip) { var lt = new Vector2(textureRect.x / textureSize.x, textureRect.y / textureSize.y); var rb = new Vector2(textureRect.xMax / textureSize.x, textureRect.yMax / textureSize.y); if ((flip & TextureFlip.HORIZONTAL) != 0) { var temp = rb.x; rb.x = lt.x; lt.x = temp; } if ((flip & TextureFlip.VERTICAL) != 0) { var temp = rb.y; rb.y = lt.y; lt.y = temp; } leftTop.texCoord = new Vector2(lt.x, 1 - lt.y); rightBottom.texCoord = new Vector2(rb.x, 1 - rb.y); leftBottom.texCoord = new Vector2(lt.x, 1 - rb.y); rightTop.texCoord = new Vector2(rb.x, 1 - lt.y); }
public void UpdateTransform(ref Matrix4x4 matrix, ref Rect textureRect, ref Vector2 textureSize, ref Vector2 anchor, TextureFlip flip = TextureFlip.NONE) { UpdateVertices(ref matrix, ref textureRect, ref anchor); UpdateTexture(ref textureRect, ref textureSize, flip); }
public void Render(Vector2 position = default(Vector2), Vector2 origin = default(Vector2), float angle = default(float), Color?color = null, TextureFlip textureFlip = default(TextureFlip), RectangleF subRegion = default(RectangleF), float scale = 1, float zIndex = 0) { RectangleF newSubRegion = SubRegion; if (!subRegion.IsEmpty) { newSubRegion.X += subRegion.X; newSubRegion.Y += subRegion.Y; newSubRegion.Width = Math.Min(subRegion.Width, SubRegion.Width); newSubRegion.Height = Math.Min(subRegion.Height, SubRegion.Height); } Texture.Render(position, origin, angle, color, textureFlip, newSubRegion, scale); }
public virtual void Render(Vector2 position = default(Vector2), Vector2 origin = default(Vector2), float angle = default(float), Color? color = null, TextureFlip textureFlip = default(TextureFlip), RectangleF subRegion = default(RectangleF), float scale = 1, float zIndex = 0) { GL.PushMatrix(); { GL.BindTexture(TextureTarget.Texture2D, textureID); Vector2 renderSize = subRegion.IsEmpty ? Size : new Vector2(subRegion.Width, subRegion.Height); GL.Scale(scale, scale, 1); GL.Translate(position.X, position.Y, zIndex); GL.Rotate(angle, 0, 0, 1); float[] texture_points = BASE_COORDS; switch (textureFlip) { case TextureFlip.Vertical: GL.Translate(0, renderSize.Y / 2, 0); GL.Rotate(180, 1, 0, 0); GL.Translate(0, -renderSize.Y / 2, 0); break; case TextureFlip.Horizontal: GL.Translate(renderSize.X / 2, 0, 0); GL.Rotate(180, 0, 1, 0); GL.Translate(-renderSize.X / 2, 0, 0); break; case TextureFlip.Both: GL.Translate(renderSize.X / 2, renderSize.Y / 2, 0); GL.Rotate(180, 1, 0, 0); GL.Rotate(180, 0, 1, 0); GL.Translate(-renderSize.X / 2, -renderSize.Y / 2, 0); break; } GL.Translate(new Vector3(-origin)); GL.Color4(color ?? Color.White); GL.Enable(EnableCap.Texture2D); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); { float[] textureCoords = BASE_COORDS; if (!subRegion.IsEmpty) { float x1 = subRegion.Left / Width; float x2 = subRegion.Right / Width; float y1 = subRegion.Top / Height; float y2 = subRegion.Bottom / Height; textureCoords = new float[] { x1, y1, x2, y1, x2, y2, x1, y2 }; } GL.VertexPointer(2, VertexPointerType.Float, 0, BASE_COORDS); GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, textureCoords); GL.Scale(new Vector3(renderSize)); GL.DrawArrays(PrimitiveType.Quads, 0, 4); } GL.DisableClientState(ArrayCap.TextureCoordArray); GL.Disable(EnableCap.Texture2D); } GL.PopMatrix(); GL.BindTexture(TextureTarget.Texture2D, 0); }
public static Texture FromPicture(PictureObjectModel pic, TextureRotation rotation, TextureFlip flip) { if (texturesByPicture.ContainsKey(pic)) { Texture tex = texturesByPicture[pic]; tex.Rotation = rotation; tex.Flip = flip; return(tex); } uint[] textureIDs = Engine.GetDefault().GenerateTextureIDs(1); uint textureID = textureIDs[0]; Texture texture = new Texture(textureID); texture.Target = TextureTarget.Texture2D; texture.TextureImage = pic; texture.MinFilter = TextureFilter.Linear; texture.MagFilter = TextureFilter.Linear; texture.TextureWrapR = TextureWrap.Repeat; texture.TextureWrapS = TextureWrap.Repeat; texture.TextureWrapT = TextureWrap.Repeat; texture.Rotation = rotation; texture.Flip = flip; if (!texturesByID.ContainsKey(textureID)) { texturesByID.Add(textureID, texture); } if (!texturesByPicture.ContainsKey(pic)) { texturesByPicture.Add(pic, texture); } return(texture); }
/// <summary> /// Updates matrix for each quad. /// </summary> public void UpdateTransform(int quadIndex, ref Matrix4x4 matrix, ref Rect textureRect, ref Vector2 textureSize, ref Vector2 anchor, TextureFlip flip) { EnsureSize(quadIndex + 1); quads[quadIndex].UpdateTransform(ref matrix, ref textureRect, ref textureSize, ref anchor, flip); }
public virtual void Render(Vector2 position = default(Vector2), Vector2 origin = default(Vector2), float angle = default(float), Color?color = null, TextureFlip textureFlip = default(TextureFlip), RectangleF subRegion = default(RectangleF), float scale = 1, float zIndex = 0) { GL.PushMatrix(); { GL.BindTexture(TextureTarget.Texture2D, textureID); Vector2 renderSize = subRegion.IsEmpty ? Size : new Vector2(subRegion.Width, subRegion.Height); GL.Scale(scale, scale, 1); GL.Translate(position.X, position.Y, zIndex); GL.Rotate(angle, 0, 0, 1); float[] texture_points = BASE_COORDS; switch (textureFlip) { case TextureFlip.Vertical: GL.Translate(0, renderSize.Y / 2, 0); GL.Rotate(180, 1, 0, 0); GL.Translate(0, -renderSize.Y / 2, 0); break; case TextureFlip.Horizontal: GL.Translate(renderSize.X / 2, 0, 0); GL.Rotate(180, 0, 1, 0); GL.Translate(-renderSize.X / 2, 0, 0); break; case TextureFlip.Both: GL.Translate(renderSize.X / 2, renderSize.Y / 2, 0); GL.Rotate(180, 1, 0, 0); GL.Rotate(180, 0, 1, 0); GL.Translate(-renderSize.X / 2, -renderSize.Y / 2, 0); break; } GL.Translate(new Vector3(-origin)); GL.Color4(color ?? Color.White); GL.Enable(EnableCap.Texture2D); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); { float[] textureCoords = BASE_COORDS; if (!subRegion.IsEmpty) { float x1 = subRegion.Left / Width; float x2 = subRegion.Right / Width; float y1 = subRegion.Top / Height; float y2 = subRegion.Bottom / Height; textureCoords = new float[] { x1, y1, x2, y1, x2, y2, x1, y2 }; } GL.VertexPointer(2, VertexPointerType.Float, 0, BASE_COORDS); GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, textureCoords); GL.Scale(new Vector3(renderSize)); GL.DrawArrays(PrimitiveType.Quads, 0, 4); } GL.DisableClientState(ArrayCap.TextureCoordArray); GL.Disable(EnableCap.Texture2D); } GL.PopMatrix(); GL.BindTexture(TextureTarget.Texture2D, 0); }
public void Render(Vector2 position = default(Vector2), Vector2 origin = default(Vector2), float angle = default(float), Color?color = null, TextureFlip textureFlip = default(TextureFlip), RectangleF subRegion = default(RectangleF), float scale = 1, float zIndex = 0) { int tileY = frames[currentFrame] / spriteSheet.TilesX; int tileX = frames[currentFrame] - tileY * spriteSheet.TilesX; spriteSheet.Render(tileX, tileY, position, origin, angle, color ?? Color.White, textureFlip, subRegion, scale, zIndex); }
public Texture CreateTextureFromFile(string FileName, TextureRotation rotation, TextureFlip flip) { if (_texturesByFileName.ContainsKey(FileName)) { Texture tex = _texturesByFileName[FileName]; tex.Rotation = rotation; tex.Flip = flip; return(tex); } uint[] textureIDs = Engine.GenerateTextureIDs(1); uint textureID = textureIDs[0]; Texture texture = new Texture(textureID); texture.Target = TextureTarget.Texture2D; texture.FileName = FileName; texture.MinFilter = TextureFilter.Linear; texture.MagFilter = TextureFilter.Linear; // texture.TextureWrapR = TextureWrap.Repeat; texture.TextureWrapS = TextureWrap.Repeat; texture.TextureWrapT = TextureWrap.Repeat; texture.Rotation = rotation; texture.Flip = flip; if (!_texturesByID.ContainsKey(textureID)) { _texturesByID.Add(textureID, texture); } if (!_texturesByFileName.ContainsKey(FileName)) { _texturesByFileName.Add(FileName, texture); } return(texture); }
public static Texture FromPicture(PictureObjectModel pic, TextureRotation rotation, TextureFlip flip) { if (texturesByPicture.ContainsKey(pic)) { Texture tex = texturesByPicture[pic]; tex.Rotation = rotation; tex.Flip = flip; return tex; } uint[] textureIDs = new uint[1]; Internal.OpenGL.Methods.glGenTextures(1, textureIDs); Internal.OpenGL.Methods.glErrorToException(); uint textureID = textureIDs[0]; Texture texture = new Texture(textureID); texture.Target = TextureTarget.Texture2D; texture.TextureImage = pic; texture.MinFilter = TextureFilter.Linear; texture.MagFilter = TextureFilter.Linear; texture.TextureWrapR = TextureWrap.Repeat; texture.TextureWrapS = TextureWrap.Repeat; texture.TextureWrapT = TextureWrap.Repeat; texture.Rotation = rotation; texture.Flip = flip; if (!texturesByID.ContainsKey(textureID)) { texturesByID.Add(textureID, texture); } if (!texturesByPicture.ContainsKey(pic)) { texturesByPicture.Add(pic, texture); } return texture; }
public static Texture FromFile(string FileName, TextureRotation rotation, TextureFlip flip) { if (texturesByFileName.ContainsKey(FileName)) { Texture tex = texturesByFileName[FileName]; tex.Rotation = rotation; tex.Flip = flip; return tex; } uint[] textureIDs = new uint[1]; Internal.OpenGL.Methods.glGenTextures(1, textureIDs); uint textureID = textureIDs[0]; Texture texture = new Texture(textureID); texture.Target = TextureTarget.Texture2D; texture.FileName = FileName; texture.MinFilter = TextureFilter.Linear; texture.MagFilter = TextureFilter.Linear; // texture.TextureWrapR = TextureWrap.Repeat; texture.TextureWrapS = TextureWrap.Repeat; texture.TextureWrapT = TextureWrap.Repeat; texture.Rotation = rotation; texture.Flip = flip; if (!texturesByID.ContainsKey(textureID)) { texturesByID.Add(textureID, texture); } if (!texturesByFileName.ContainsKey(FileName)) { texturesByFileName.Add(FileName, texture); } return texture; }
public static Texture FromPicture(PictureObjectModel pic, TextureRotation rotation, TextureFlip flip) { if (texturesByPicture.ContainsKey(pic)) { Texture tex = texturesByPicture[pic]; tex.Rotation = rotation; tex.Flip = flip; return(tex); } uint[] textureIDs = new uint[1]; Internal.OpenGL.Methods.glGenTextures(1, textureIDs); Internal.OpenGL.Methods.glErrorToException(); uint textureID = textureIDs[0]; Texture texture = new Texture(textureID); texture.Target = TextureTarget.Texture2D; texture.TextureImage = pic; texture.MinFilter = TextureFilter.Linear; texture.MagFilter = TextureFilter.Linear; texture.TextureWrapR = TextureWrap.Repeat; texture.TextureWrapS = TextureWrap.Repeat; texture.TextureWrapT = TextureWrap.Repeat; texture.Rotation = rotation; texture.Flip = flip; if (!texturesByID.ContainsKey(textureID)) { texturesByID.Add(textureID, texture); } if (!texturesByPicture.ContainsKey(pic)) { texturesByPicture.Add(pic, texture); } return(texture); }
public Texture2D RenderPreview(float HeightOffset = 0, int Width = 256, int Height = 256, bool Flip = true, bool RenderEverything = false) { RenderingPreview = true; //Sbool Slope = ScmapEditor.Current.Slope; //bool Grid = ScmapEditor.Current.Grid; //if (Slope) //ScmapEditor.Current.ToogleSlope(false); //if(Grid) //ScmapEditor.Current.ToogleGrid(false); if (RenderEverything) { Cam.cullingMask = FullLayers; } else { Cam.cullingMask = Layers; } ScmapEditor.Current.TerrainMaterial.EnableKeyword("PREVIEW_ON"); Vector3 CamPos = MapLuaParser.Current.MapCenterPoint; float Size = Mathf.Max(ScmapEditor.Current.map.Width, ScmapEditor.Current.map.Height) * 0.1f; float distance = Size * (2.0f * Mathf.Tan(0.5f * Cam.fieldOfView * Mathf.Deg2Rad)); distance = (Size) * 0.5f / Mathf.Tan(Cam.fieldOfView * 0.5f * Mathf.Deg2Rad); CamPos.y = distance + HeightOffset; transform.position = CamPos; //Cam.targetTexture.width = Width; //Cam.targetTexture.height = Height; if (DefaultRenderTex.width != Width || DefaultRenderTex.height != Height) { Cam.targetTexture = new RenderTexture(Width, Height, DefaultRenderTex.depth, DefaultRenderTex.format); } RenderTexture currentActiveRT = RenderTexture.active; RenderTexture.active = Cam.targetTexture; float LastLodBias = QualitySettings.lodBias; QualitySettings.lodBias = 100000; // --> Cam.Render(); // <-- QualitySettings.lodBias = LastLodBias; // Texture Texture2D PreviewRender = new Texture2D(Width, Height, TextureFormat.RGBA32, false); Color[] Colors = new Color[Width * Height]; for (int i = 0; i < Colors.Length; i++) { Colors[i] = Empty; } PreviewRender.SetPixels(Colors); PreviewRender.Apply(false); PreviewRender.ReadPixels(new Rect(0, 0, PreviewRender.width, PreviewRender.height), 0, 0, false); PreviewRender.Apply(false); RenderTexture.active = currentActiveRT; if (Cam.targetTexture != DefaultRenderTex) { Destroy(Cam.targetTexture); Cam.targetTexture = DefaultRenderTex; } //if(Slope) //ScmapEditor.Current.ToogleSlope(Slope); //if(Grid) //ScmapEditor.Current.ToogleGrid(Grid); ScmapEditor.Current.TerrainMaterial.DisableKeyword("PREVIEW_ON"); RenderingPreview = false; if (Flip) { return(TextureFlip.FlipTextureVertical(PreviewRender, false)); } else { return(PreviewRender); } }