Before updating to Windows 10 you may need to return your Pro license. More information here

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.


more ▼

asked Nov 17, 2010 at 02:07 AM

avatar image

13 9 6 16

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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.

more ▼

answered Nov 17, 2010 at 08:31 AM

avatar image

787 10 8 28

@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

Dec 07, 2010 at 07:38 AM IronMike
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 22, 2012 at 10:00 PM

avatar image

179 1 1 6

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 27, 2011 at 05:07 PM

avatar image

670 27 24 36

GUI.DrawTextureWithTexCoords does.

Feb 06 at 06:00 PM BilboX
(comments are locked)
10|3000 characters needed characters left

GUI.DrawTexture is significantly faster, tested on a single texture drawn 1920 times, it performed 50% better.

more ▼

answered Jul 25 at 01:46 AM

avatar image


(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Nov 17, 2010 at 02:07 AM

Seen: 6824 times

Last Updated: Jul 25 at 01:46 AM