x


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.

more ▼

asked Nov 17 '10 at 02:07 AM

Auzette gravatar image

Auzette
13 3 3 8

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

3 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 '10 at 08:31 AM

denewbie gravatar image

denewbie
757 3 3 18

@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 '10 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 '12 at 10:00 PM

spolglase gravatar image

spolglase
114 1

(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 '11 at 05:07 PM

JoeStrout gravatar image

JoeStrout
237 8 9 18

(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

By RSS:

Answers

Answers and Comments

Topics:

x5105
x712
x88

asked: Nov 17 '10 at 02:07 AM

Seen: 5260 times

Last Updated: Feb 22 '12 at 10:00 PM