# DrawTexture

> Draw a texture in screen coordinates.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## DrawTexture(Rect, Texture, Rect, int, int, int, int, Color, Material, int)

Draw a texture in screen coordinates.

```csharp
public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Color color, Material mat, int pass)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the texture. In pixel coordinates with (0,0) in the upper-left corner.**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to draw.**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Region of the texture to use. In normalized coordinates with (0,0) in the bottom-left corner.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the left that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the right that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the top that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the bottom that are not affected by scale.**** (\[Color]\(/engine/6000.7/script-reference/unityengine/color)): [Color](/engine/6000.7/script-reference/unityengine/color.md) that modulates the output. The neutral value is (0.5, 0.5, 0.5, 0.5). Set as vertex color for the shader.**** (\[Material]\(/engine/6000.7/script-reference/unityengine/material)): Custom [Material](/engine/6000.7/script-reference/unityengine/material.md) that can be used to draw the texture. Unity passes the texture into the shader as `_MainTex`. If null is passed, a default material with the Internal-GUITexture.shader is used.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): If -1 (default), draws all passes in the material. Otherwise, draws given pass only.

### Remarks

If you want to draw a texture from inside of OnGUI code, you should only do that from [EventType.Repaint](/engine/6000.7/script-reference/unityengine/eventtype/repaint.md) events. It's probably better to use [GUI.DrawTexture](/engine/6000.7/script-reference/unityengine/gui/drawtexture.md) for GUI code.

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    // Draws a texture on the screen at 10, 10 with 100 width, 100 height.

    Texture aTexture;

    void OnGUI()
    {
        if (Event.current.type.Equals(EventType.Repaint))
        {
            Graphics.DrawTexture(new Rect(10, 10, 100, 100), aTexture);
        }
    }
}
```

## DrawTexture(Rect, Texture, Rect, int, int, int, int, Material, int)

Draw a texture in screen coordinates.

```csharp
public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Material mat, int pass)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the texture. In pixel coordinates with (0,0) in the upper-left corner.**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to draw.**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Region of the texture to use. In normalized coordinates with (0,0) in the bottom-left corner.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the left that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the right that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the top that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the bottom that are not affected by scale.**** (\[Material]\(/engine/6000.7/script-reference/unityengine/material)): Custom [Material](/engine/6000.7/script-reference/unityengine/material.md) that can be used to draw the texture. Unity passes the texture into the shader as `_MainTex`. If null is passed, a default material with the Internal-GUITexture.shader is used.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): If -1 (default), draws all passes in the material. Otherwise, draws given pass only.

### Remarks

If you want to draw a texture from inside of OnGUI code, you should only do that from [EventType.Repaint](/engine/6000.7/script-reference/unityengine/eventtype/repaint.md) events. It's probably better to use [GUI.DrawTexture](/engine/6000.7/script-reference/unityengine/gui/drawtexture.md) for GUI code.

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    // Draws a texture on the screen at 10, 10 with 100 width, 100 height.

    Texture aTexture;

    void OnGUI()
    {
        if (Event.current.type.Equals(EventType.Repaint))
        {
            Graphics.DrawTexture(new Rect(10, 10, 100, 100), aTexture);
        }
    }
}
```

## DrawTexture(Rect, Texture, int, int, int, int, Material, int)

Draw a texture in screen coordinates.

```csharp
public static void DrawTexture(Rect screenRect, Texture texture, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Material mat, int pass)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the texture. In pixel coordinates with (0,0) in the upper-left corner.**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to draw.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the left that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the right that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the top that are not affected by scale.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of pixels from the bottom that are not affected by scale.**** (\[Material]\(/engine/6000.7/script-reference/unityengine/material)): Custom [Material](/engine/6000.7/script-reference/unityengine/material.md) that can be used to draw the texture. Unity passes the texture into the shader as `_MainTex`. If null is passed, a default material with the Internal-GUITexture.shader is used.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): If -1 (default), draws all passes in the material. Otherwise, draws given pass only.

### Remarks

If you want to draw a texture from inside of OnGUI code, you should only do that from [EventType.Repaint](/engine/6000.7/script-reference/unityengine/eventtype/repaint.md) events. It's probably better to use [GUI.DrawTexture](/engine/6000.7/script-reference/unityengine/gui/drawtexture.md) for GUI code.

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    // Draws a texture on the screen at 10, 10 with 100 width, 100 height.

    Texture aTexture;

    void OnGUI()
    {
        if (Event.current.type.Equals(EventType.Repaint))
        {
            Graphics.DrawTexture(new Rect(10, 10, 100, 100), aTexture);
        }
    }
}
```

## DrawTexture(Rect, Texture, Material, int)

Draw a texture in screen coordinates.

```csharp
public static void DrawTexture(Rect screenRect, Texture texture, Material mat, int pass)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the texture. In pixel coordinates with (0,0) in the upper-left corner.**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to draw.**** (\[Material]\(/engine/6000.7/script-reference/unityengine/material)): Custom [Material](/engine/6000.7/script-reference/unityengine/material.md) that can be used to draw the texture. Unity passes the texture into the shader as `_MainTex`. If null is passed, a default material with the Internal-GUITexture.shader is used.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): If -1 (default), draws all passes in the material. Otherwise, draws given pass only.

### Remarks

If you want to draw a texture from inside of OnGUI code, you should only do that from [EventType.Repaint](/engine/6000.7/script-reference/unityengine/eventtype/repaint.md) events. It's probably better to use [GUI.DrawTexture](/engine/6000.7/script-reference/unityengine/gui/drawtexture.md) for GUI code.

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    // Draws a texture on the screen at 10, 10 with 100 width, 100 height.

    Texture aTexture;

    void OnGUI()
    {
        if (Event.current.type.Equals(EventType.Repaint))
        {
            Graphics.DrawTexture(new Rect(10, 10, 100, 100), aTexture);
        }
    }
}
```
