Author Topic: UITexture and UISprite differences in displaying. Android.  (Read 11403 times)

fork8

  • Guest
UITexture and UISprite differences in displaying. Android.
« on: September 26, 2012, 08:03:22 AM »
Hi there!
I need to change texture by mask(another texture) and output(draw) result to UITexture(for example it is tracery or images on cars).
It works, but when I put two widgets on screen - UISprite(with texture from atlas) and UITexture(with texture loaded through WWW and LoadImageIntoTexture),  texture on UISprite looks good, but texture on UITexture looks blurred. Why blurred? Maybe it has something to do with the checkbox "automatic" at UIRoot?

Also, please answer - how to properly manage resolutions for android - is it needed different-sizes textures for different resolutions? What about checkbox "Automatic" for Android?
Where can I read about developing for android using NGUI and Unity3D?

Thank you!

PhilipC

  • Guest
Re: UITexture and UISprite differences in displaying. Android.
« Reply #1 on: September 26, 2012, 08:43:35 AM »
It sounds like to me the sprite you are using for the second UITexture is not the same size as the texture being download. After assigning the texture to the UITexture do a MakePixelPerfect it should get rid of any blurryness.

The second question has been covered multiple times

http://www.tasharen.com/forum/index.php?topic=1714.msg8656#msg8656
http://www.tasharen.com/forum/index.php?topic=1321.msg6733#msg6733

and others just search the forums.

fork8

  • Guest
Re: UITexture and UISprite differences in displaying. Android.
« Reply #2 on: September 26, 2012, 09:20:23 AM »
MakePixelPerfect() calling had no effect on the blurring of UITexture  :-\     Textures of UISprite and UITexture  are the same and have the same resolution.

Thank you for links!

UPD:  Here is how I load texture to UITexture object:
  1.         Texture2D texCar = null;
  2.         WWW loadCar = null;
  3.                 string targetFileCar = "file://" + Application.dataPath + "/Textures/scar9_c_l.png";
  4.         loadCar = new WWW(targetFileCar);
  5.                 texCar = new Texture2D(720, 720); // Real resolution of PNG file
  6.                 loadCar.LoadImageIntoTexture(texCar);
  7.                 if(texCar == null){
  8.                         Debug.LogError("Can't find texCar");
  9.                         return;
  10.                 }
  11.                 texCar.Apply();
  12.                
  13.                 dest.mainTexture = texCar;
  14.                 dest.MakePixelPerfect();
  15.  

Is that correct for correct texture resolution?
« Last Edit: September 26, 2012, 10:08:16 AM by fork8 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture and UISprite differences in displaying. Android.
« Reply #3 on: September 26, 2012, 10:22:34 AM »
What's your target platform? Some can only do power-of-two textures, and 720x720 isn't. Also make sure that the transforms leading up to your texture are using whole numbers, and that UIAnchor has "half-pixel offset" checked.

fork8

  • Guest
Re: UITexture and UISprite differences in displaying. Android.
« Reply #4 on: September 26, 2012, 05:05:50 PM »
Thank you i shall check it
« Last Edit: September 26, 2012, 05:07:28 PM by fork8 »

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: UITexture and UISprite differences in displaying. Android.
« Reply #5 on: November 28, 2012, 08:47:52 AM »
Hey dude, I got trap as well.
Here's a way out:

Texture2D _t2d=new Texture2D(100,100,TextureFormat.BGRA32,false);

Note that specify TextureFormat may solve your problem.

filo

  • Guest
Re: UITexture and UISprite differences in displaying. Android.
« Reply #6 on: February 18, 2013, 02:01:06 PM »
Hi,

I am looking for the answer to this same problem. I tried everything in this thread but had no luck in making it work.
Did anyone find a working solution?

Here's my code:
  1.                 // create texture
  2.                 UITexture buttonTexture = NGUITools.AddWidget<UITexture>(buttonAnchor.gameObject);
  3.                 buttonTexture.pivot = UIWidget.Pivot.BottomRight;
  4.                
  5.                 // create path and load texture2d
  6.                 string docPath = Application.dataPath;
  7.                 docPath += "/Resources/listIcon.bytes";
  8.                 Texture2D imgTexture=new Texture2D(190,190,TextureFormat.BGRA32,false);
  9.                 imgTexture.LoadImage(System.IO.File.ReadAllBytes(docPath));
  10.                
  11.                 // assign texture2d to ngui texture
  12.                 buttonTexture.material = new Material (Shader.Find ("Unlit/Transparent Colored"));
  13.         buttonTexture.material.mainTexture = imgTexture;
  14.                 buttonTexture.transform.localPosition = new Vector3(Screen.width, - Screen.height);
  15.                 buttonTexture.MakePixelPerfect();

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture and UISprite differences in displaying. Android.
« Reply #7 on: February 18, 2013, 05:09:54 PM »
Never change UIWidget's material's texture (buttonTexture.material.mainTexture). Set UIWidget.mainTexture instead.

filo

  • Guest
Re: UITexture and UISprite differences in displaying. Android.
« Reply #8 on: February 19, 2013, 05:18:03 AM »
Than you for replying so fast.
This is the first way I tried to do it but I had the same result. The texture is blurry and MakePixelPerfect does not fix it.
Some more info: I am developing for iOS, Unity 4, NGUI 2.2.7.c. The problem appears both on device and in the unity editor.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture and UISprite differences in displaying. Android.
« Reply #9 on: February 19, 2013, 09:18:59 AM »
Blurry texture can be caused by a variety of issues. Do a search on the forum for "blurry" and you will find quite a few posts, including one in the FAQ sticky.