Compare 4 type of TextureOptions

  ... tutorials on how to use AndEngine.

Compare 4 type of TextureOptions

Postby rubycell » Sun Oct 17, 2010 5:36 am

Hi there,
In AndEngine, we can use 4 default Texture option that's defined in TextureOptions class.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class TextureOptions {
  2.         // ===========================================================
  3.         // Constants
  4.         // ===========================================================
  5.  
  6.         public static final TextureOptions DEFAULT = new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_MODULATE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE);
  7.         public static final TextureOptions BILINEAR = new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_MODULATE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE);
  8.         public static final TextureOptions REPEATING = new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_MODULATE, GL10.GL_REPEAT, GL10.GL_REPEAT);
  9.         public static final TextureOptions REPEATING_BILINEAR = new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_MODULATE, GL10.GL_REPEAT, GL10.GL_REPEAT);
  10.  
  11.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Could any one please tell me what is the difference between 4 options above.
My opinion:
- DEFAULT, fast but do not smooth in case of scaling (for example, scale 800x480 texture to display in a 480x320 screen)
- BILINEAR, better but slower
rubycell
 
Posts: 30
Joined: Wed Jul 21, 2010 4:44 am
Location: Hanoi, Vietnam

Re: Compare 4 type of TextureOptions

Postby Nicolas Gramlich » Mon Oct 18, 2010 1:33 pm

Hi,

http://code.google.com/p/andengine/sour ... tions.java

Recently I added even more :P
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. NEAREST = new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_MODULATE, false);
  2. BILINEAR = new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_MODULATE, false);
  3. REPEATING = new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_REPEAT, GL10.GL_REPEAT, GL10.GL_MODULATE, false);
  4. REPEATING_BILINEAR = new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_REPEAT, GL10.GL_REPEAT, GL10.GL_MODULATE, false);
  5.  
  6. NEAREST_PREMULTIPLYALPHA = new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_MODULATE, true);
  7. BILINEAR_PREMULTIPLYALPHA = new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_CLAMP_TO_EDGE, GL10.GL_CLAMP_TO_EDGE, GL10.GL_MODULATE, true);
  8. REPEATING_PREMULTIPLYALPHA = new TextureOptions(GL10.GL_NEAREST, GL10.GL_NEAREST, GL10.GL_REPEAT, GL10.GL_REPEAT, GL10.GL_MODULATE, true);
  9. REPEATING_BILINEAR_PREMULTIPLYALPHA = new TextureOptions(GL10.GL_LINEAR, GL10.GL_LINEAR, GL10.GL_REPEAT, GL10.GL_REPEAT, GL10.GL_MODULATE, true);
  10.  
  11. DEFAULT = NEAREST_PREMULTIPLYALPHA;
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Your assumptions were correct :)
- NEAREST: Faster then BILINEAR as only the nearest pixel on the Texture is used (Sprites tend to look pixelated when, physical resolution is higher or lower than texture resolution. Up/Down-scaling)
- BILINEAR: Slower than NEAREST, but looks better, as not only one pixel from the texture is fetched but the 4 nearest.

The difference between those and the REPEATING TextureOptions is the way OpenGL treats TextureCoordinates that are out of the physical bounds of the Texture (usually ranging from 0.0 to 1.0).
Where REPEATING paints the Texture twice when the coordinates go from 0.0 to 2.0, NON-REPEATING will stretch the outermost pixel of the Texture what looks pretty ugly.

So the REPEATING TextureOptions are used only in very special cases.

For a description what the PREMULTIPLYALPHA-thing is, have a look here: tutorials/on-textureoptions-premulitplyalpha-blendfunctions-alpha-t786.html

Hope this helped :)

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: Yahoo [Bot] and 16 guests