- Home /
GUI.DrawTexture versus Graphics.DrawTexture
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.
THanks.
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, 2015 at 01:46 AM
GUI.DrawTexture is significantly faster, tested on a single texture drawn 1920 times, it performed 50% better.
Your answer
Follow this Question
Related Questions
Graphics.DrawTexture drawing in both 2d and 3d?!? 2 Answers
Unity3D texture2d error help 0 Answers
Material is blending with background problem 0 Answers
GUI Rotation and Depth problem 1 Answer
How to cut image horizontally using DrawTextureWithTexCoords? 0 Answers