- Home /
What are the differences between GUI.Label(Used to draw a texture) and GUI.DrawTexture?
Are there any differences between GUI.DrawTexture and GUI.Label, when used to draw a texture, other than the former offering more specialized options for drawing textures and the latter being stylable by default?
In a situation where either would work, which would be a more efficient?
To my irritation, I discovered that drawing Images using GUI.Label and setting the rectangle dimensions to those of the image caused it to draw slightly improperly(filtering what made active, meaning that it wasn't at an ideal resolution). Setting the size of the rectangle higher solved the problem but I don't see why I should have to do this. GUI.DrawTexture doesn't seem to have this problem.
I'm taking a guess here: I think that's because the label gets rendered with a GUIStyle that has a padding, i.e. some default space between its edges and the start of its contents. Take a look at http://unity3d.com/support/documentation/ScriptReference/GUIStyle-padding.html
So if the padding is non-zero, it's going to try to offset the texture you provide for it. Could that be what you're seeing?
Yes, the problem was caused by padding values of 3 for both top and bottom. Since I'm using the label element for other things, it makes sense for me to keep the padding values as they are and keep using GUI.DrawTexture for my textures.
Thank you, this partially answers my question, as the usefulness of having at least two ways of drawing a texture has been demonstrated.
I would like to know the same, is one of them better for showing gui images? Is there perhaps a performance difference?
It's possible there's some overhead associated with a Label vs just drawing the texture since the Label is a styled GUI component, and to get the same behavior as GUI.DrawTexture, you need to define a separate style with no padding for it. It also seems GUI.DrawTexture makes it pretty easy to use alpha blending with the background, I'm not sure how well GUI.Label would accomplish that, if at all.
For most intents and purposes I'd say they are interchangable, but without wanting to be definitive, GUI.DrawTexture feels a little more lightweight and lowlevel than the Label.
Your answer
Follow this Question
Related Questions
IsPlaying vs isplaying 1 Answer
GUI.DrawTexture Error: BCE0023 0 Answers
GUILabel Text Overlapping After Updating 0 Answers
A'm I setting Up My GUI style Right? 1 Answer