UnityEngine.Graphics.DrawTexture(UnityEngine.Rect, UnityEngine.Texture, UnityEngine.Rect, int, int, int, int, UnityEngine.Color, UnityEngine.Material)

Here are the examples of the csharp api UnityEngine.Graphics.DrawTexture(UnityEngine.Rect, UnityEngine.Texture, UnityEngine.Rect, int, int, int, int, UnityEngine.Color, UnityEngine.Material) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 View Source File : StereoRenderEffect.cs
License : MIT License
Project Creator : harshitjuneja

void OnRenderImage(RenderTexture source, RenderTexture dest) {
    GL.PushMatrix();
    int width = dest ? dest.width : Screen.width;
    int height = dest ? dest.height : Screen.height;
    GL.LoadPixelMatrix(0, width, height, 0);
    // Camera rects are in screen coordinates (bottom left is origin), but DrawTexture takes a
    // rect in GUI coordinates (top left is origin).
    Rect blitRect = cam.pixelRect;
    blitRect.y = height - blitRect.height - blitRect.y;
    RenderTexture oldActive = RenderTexture.active;
    RenderTexture.active = dest;
    Graphics.DrawTexture(blitRect, source, fullRect, 0, 0, 0, 0, Color.white, material);
    RenderTexture.active = oldActive;
    GL.PopMatrix();
  }

19 View Source File : TextureExtensions.cs
License : MIT License
Project Creator : peteschmitz

static void _gpu_scale(Texture2D src, Rect? srcRect, int width, int height, FilterMode fmode)
    {
        //We need the source texture in VRAM because we render with it
        src.filterMode = fmode;
        src.Apply(true);

        //Using RTT for best quality and performance. Thanks, Unity 5
        RenderTexture rtt = new RenderTexture(width, height, 32);

        //Set the RTT in order to render to it
        Graphics.SetRenderTarget(rtt);

        //Setup 2D matrix in range 0..1, so nobody needs to care about sized
        GL.LoadPixelMatrix(0, 1, 1, 0);

        //Then clear & draw the texture to fill the entire RTT.
        GL.Clear(true, true, new Color(0, 0, 0, 0));
        if (srcRect.HasValue)
        {
            //srcRect.Value.AsNormalizedUv(src.width, src.height)
            Graphics.DrawTexture(new Rect(0, 0, 1, 1), src, srcRect.Value.AsNormalizedUv(src.width, src.height), 0, 0, 0, 0);
        }
        else
        {
            Graphics.DrawTexture(new Rect(0, 0, 1, 1), src);
        }
    }

19 View Source File : Interfaces.cs
License : MIT License
Project Creator : XINCGer

public static void DrawTexture(Rect screenRect, Texture texture, ScaleMode scaleMode, AlphaPacking alphaPacking, Material material)
		{
			if (Event.current.type == EventType.Repaint)
			{
				float textureWidth = texture.width;
				float textureHeight = texture.height;
				switch (alphaPacking)
				{
					case AlphaPacking.LeftRight:
						textureWidth *= 0.5f;
						break;
					case AlphaPacking.TopBottom:
						textureHeight *= 0.5f;
						break;
				}

				float aspectRatio = (float)textureWidth / (float)textureHeight;
				Rect sourceRect = new Rect(0f, 0f, 1f, 1f);
				switch (scaleMode)
				{
					case ScaleMode.ScaleAndCrop:
						{
							float screenRatio = screenRect.width / screenRect.height;
							if (screenRatio > aspectRatio)
							{
								float adjust = aspectRatio / screenRatio;
								sourceRect = new Rect(0f, (1f - adjust) * 0.5f, 1f, adjust);
							}
							else
							{
								float adjust = screenRatio / aspectRatio;
								sourceRect = new Rect(0.5f - adjust * 0.5f, 0f, adjust, 1f);
							}
						}
						break;
					case ScaleMode.ScaleToFit:
						{
							float screenRatio = screenRect.width / screenRect.height;
							if (screenRatio > aspectRatio)
							{
								float adjust = aspectRatio / screenRatio;
								screenRect = new Rect(screenRect.xMin + screenRect.width * (1f - adjust) * 0.5f, screenRect.yMin, adjust * screenRect.width, screenRect.height);
							}
							else
							{
								float adjust = screenRatio / aspectRatio;
								screenRect = new Rect(screenRect.xMin, screenRect.yMin + screenRect.height * (1f - adjust) * 0.5f, screenRect.width, adjust * screenRect.height);
							}
						}
						break;
					case ScaleMode.StretchToFill:
						break;
				}

				Graphics.DrawTexture(screenRect, texture, sourceRect, 0, 0, 0, 0, GUI.color, material);
			}
		}