Search Unity

Question How to do GUI.DrawTextureWithTexCoords() but with Graphics instead of GUI.

Discussion in 'General Graphics' started by PowerJake, May 4, 2023.

  1. PowerJake

    PowerJake

    Joined:
    Nov 15, 2019
    Posts:
    64
    [Unity 2021.3.19f1 | URP]

    EDIT: I reread the docs for Graphics.DrawTexture and there is an parameter for the texture coordinates so the problem is solved and I wish I could delete this post.


    Hey, I have a function that renders a 9-sliced texture using GUI.DrawTextureWithTexCoords, but I need to be able to render this onto a RenderTexture. It doesn't look like IMGUI supports drawing to a RenderTexture, so I need to use the Graphics class to draw it. Graphics only has Graphics.DrawTexture(), so it is unclear how or if I can do what I am going for.

    How can I use the Graphics class API to recreate GUI.DrawTextureWithTexCoords?

    I'm aware that Graphics.DrawTexture() has 9-slicing built in, but it stretches the texture. My function tiles the slices. The tex coords are necessary to chop up partial tiles.
     
    Last edited: May 4, 2023