Determine the necessary size for a Texture

  ... tutorials on how to use AndEngine.

Determine the necessary size for a Texture

Postby darklord » Thu Aug 12, 2010 2:55 pm

Hi!

First of all, awesome job on the AndEngine! I've been lurking here for a while and making some prototypes. I've decided to stick with AndEngine! Perhaps I might one day be proficient enough to return something to the community.

I have a question about the term "Texture" and its use. I've searched the boards and notices that the parameters given when instancing a Texture class is used to register the width and height on the graphics chip. This must always be in ^2.

My question is, which size do I have to use when instancing a texture object? Do I have to look at the image I want to use and base it on those dimensions?

For example:
I have an image of 32x48, then I should instance a Texture with 32x64?
Background with 800 x 600 would then be 1024x1024?

Thanks! ;)
darklord
 
Posts: 121
Joined: Thu Aug 12, 2010 2:48 pm

Re: Texture

Postby Nicolas Gramlich » Thu Aug 12, 2010 3:31 pm

Hi,

thanks :)

Exactly. There is a method in the TextureFactory class:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public static Texture createForTextureSourceSize(final ITextureSource pTextureSource, final TextureOptions pTextureOptions) {
  2.         final int loadingScreenWidth = pTextureSource.getWidth();
  3.         final int loadingScreenHeight = pTextureSource.getHeight();
  4.         return new Texture(MathUtils.nextPowerOfTwo(loadingScreenWidth), MathUtils.nextPowerOfTwo(loadingScreenHeight), pTextureOptions);
  5. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

MathUtils.nextPowerOfTwo is the interestign part here.

Hope this helped :)

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: Determine the necessary size for a Texture

Postby darklord » Thu Aug 12, 2010 3:54 pm

Thanks for the super quick reply! :)

I've added a small snippet from SpriteExample.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         public void onLoadResources() {
  3.                 this.mTexture = new Texture(64, 32, TextureOptions.BILINEAR);
  4.                 this.mFaceTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/face_box.png", 0, 0);
  5.  
  6.                 this.mEngine.getTextureManager().loadTexture(this.mTexture);
  7.         }
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Why do you use 64,32 and not 32, 32? I am asking because the face_box.png is 32x32.

Also, is the BILINEAR TextureOption load-intensive for mobile devices? I'm inclined to always use TextureOption.BILINEAR because of all the different screen resolutions.

Thanks alot! 8-)
darklord
 
Posts: 121
Joined: Thu Aug 12, 2010 2:48 pm

Re: Determine the necessary size for a Texture

Postby Nicolas Gramlich » Fri Aug 13, 2010 1:36 pm

Hi,

thanks, those Textures were bigger than necessary :)
Changeset: http://code.google.com/p/andengineexamp ... bd828e0f3c

Bilinear doesn't introduce more load, but takes longer to draw. The performance impact depends from device to device. Due to the very different screen resolutions and the possibility to use zooming, using Bilinear very often improves visual quality.

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: Determine the necessary size for a Texture

Postby darklord » Fri Aug 13, 2010 7:43 pm

Nicolas Gramlich wrote:Hi,

thanks, those Textures were bigger than necessary :)
Changeset: http://code.google.com/p/andengineexamp ... bd828e0f3c

Bilinear doesn't introduce more load, but takes longer to draw. The performance impact depends from device to device. Due to the very different screen resolutions and the possibility to use zooming, using Bilinear very often improves visual quality.

Best Regards,
Nicolas


Hi!
Mentioning my name is way to much credit, but thanks!

Isn't a "Longer drawing time" equal to "more load"?

Anyways.. I saw you also updated your benchmark tests.. but won't this mess up your already collected results?
darklord
 
Posts: 121
Joined: Thu Aug 12, 2010 2:48 pm

Re: Determine the necessary size for a Texture

Postby Nicolas Gramlich » Sat Aug 14, 2010 10:03 am

Oops... shouldn't have changed the Benchmarks. But as the Texture never in those benchmarks just gets loaded once is the only Texture loaded and never changes it most likely has no effect.

Oh I thought with "load-intensive" you mean it would take longer when initially loaded. So yes, it just takes longer to draw.

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: Determine the necessary size for a Texture

Postby darklord » Sat Aug 14, 2010 1:36 pm

Got it! Thanks for the help!
darklord
 
Posts: 121
Joined: Thu Aug 12, 2010 2:48 pm

Re: Determine the necessary size for a Texture

Postby isaiah » Thu Aug 19, 2010 7:32 am

So if using the createForTextureSourceSize function in TextureFactory class how do we specify the ITextureSource variable that is supposed to pull the info from the texture? There doesnt seem a way to actually instantiate a ITextureSource variable.
isaiah
 
Posts: 5
Joined: Tue Aug 17, 2010 6:58 pm

Re: Determine the necessary size for a Texture

Postby Nicolas Gramlich » Fri Aug 20, 2010 10:06 pm

Hi isaiah,

isaiah wrote:So if using the createForTextureSourceSize function in TextureFactory class how do we specify the ITextureSource variable that is supposed to pull the info from the texture? There doesnt seem a way to actually instantiate a ITextureSource variable.


ITextureSource is an interface that has a couple of implementation, like i.e. AssetTextureSource

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany


Return to Tutorials

Who is online

Users browsing this forum: Alexa [Bot], dichhv, Google Feedfetcher and 15 guests