OpenGL, how to load non power of two dimension bitmap?

All your problems with Audio, Video and Images.

OpenGL, how to load non power of two dimension bitmap?

Postby guian » Thu Dec 04, 2008 5:51 pm

in the OpenGL android API
(android.opengl.GLUtils.texImage2D() )
( http://code.google.com/android/referenc ... Utils.html )

we can read=>
"Whether or not bitmap can have non power of two dimensions depends
on the current OpenGL context."

I load my OpenGL context using :
mEglContext = mEgl.eglCreateContext(mEglDisplay,
mEglConfig,EGL10.EGL_NO_CONTEXT, null);
do you know what do I have to do in order to load non power of two
dimensions bitmap?
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Top

Postby guian » Fri Dec 05, 2008 12:01 pm

the answer :

its NOT possible to load non power of two size bitmap as texture

but it's very easy to resize our bitmap ;)

=>



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.         //correct the bitmap if its not a power of two width
  5.  
  6.         if(((Math.log((double)bitmap.getWidth())/Math.log(2.0))
  7.  
  8.                         - Math.floor((Math.log((double)bitmap.getWidth())/Math.log(2.0)))) != 0){
  9.  
  10.                 //the bitmap width isn't a power of two.
  11.  
  12.                
  13.  
  14.                 int aimWidth = (int) Math.pow(2,Math.ceil(Math.log((double)bitmap.getWidth())/Math.log(2.0)));
  15.  
  16.                
  17.  
  18.                 bitmap = Bitmap.createScaledBitmap(bitmap, aimWidth, bitmap.getHeight(), false);
  19.  
  20.                //you can adapt the height in the same way if needed.
  21.  
  22.         }
  23.  
  24.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


;)
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Postby MrSnowflake » Fri Dec 05, 2008 12:45 pm

guian wrote:but it's very easy to resize our bitmap ;)
Simple yes (if you have the code, as we do now), but very expensive! (I suppose) The Log will probably use a lot of cycles, so make sure, you resize your bitmaps in advance!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Emmanuel7 » Fri Dec 12, 2008 2:34 am

Note :
A much more lighter way to know whether a number is a power of 2 is to test for :
x & ( x-1 ) == 0
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 23 guests