We've been using GUI.DrawTexture for our UI system, but a question was brought up as to why we don't simply use Graphics.DrawTexture instead.
Is there any drawback to always using Graphics.DrawTexture instead of GUI.DrawTexture? It seems that the former provides everything the latter does, but with the added bonus of being able to utilize materials.
Answer by denewbie
Nov 17, 2010 at 08:31 AM
I've never really compared them side by side before but based on how I've used them I cant tell much of a difference at run time. And I m talking about calling the textures about more than 50 times withing each OnGUI segment because I've to dynamically generate 2D UI data. I've come to like drawTexture a little better because I've been using "GUI." stuff so if make my code and thought process more consistance looking but I don't really see why the other should be deemed as inferior.
@denewbie Can you help me on this thread? I want to use DrawTexture and can't get it to work: http://answers.unity3d.com/questions/30582/gui-drawtexture-not-working
Answer by spolglase
Feb 22, 2012 at 10:00 PM
One thing I will say about Graphics.DrawTexture() is that it allows you to write your own shaders for your 2D elements. The way to do this is to pass in a material to you Graphics.DrawTexture() call that has an attached custom shader. This can be handy in any number of ways if you want to use shaders in the 2D world.
Answer by JoeStrout
Feb 27, 2011 at 05:07 PM
The main difference I've found is that Graphics.DrawTexture allows you to specify a source rect (in texture coordinates, 0-1 in each axis), whereas GUI.DrawTexture can only draw the entire texture map. That makes the latter less useful for constructing any nontrivial GUI.
The other difference, I think, is that GUI.DrawTexture is smart about not drawing for event types other than EventType.Repaint, and Graphics.DrawTexture is not. See this thread for more details on this gotcha.
Answer by VoidX_HUN
Jul 25 at 01:46 AM
GUI.DrawTexture is significantly faster, tested on a single texture drawn 1920 times, it performed 50% better.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
2 People are following this question.
Graphics.DrawTexture drawing in both 2d and 3d?!?
DrawTexture without stretching it
Scrollview is positioning things incorrectly
DrawTexture and Resources.Load()
How to cut image horizontally using DrawTextureWithTexCoords?