-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|677|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Misc


 
Phoenix
Created : 01 May 2008
 

Find powers of two



Took me quite a while to figure out how to do find out if a number is a power of two without having lots of bells and whistles. Not sure if it's the fastest way, but it sure is small.



If anyone's interested in why it works I'll happily explain. But right now, I'm tired and need to sleep.

 

Comments


Friday, 02 May 2008, 02:07
Phoenix
OpenGL hates non-power of two textures, so I use it to check if the texture sizes are correct.
Friday, 02 May 2008, 02:59
JL235
There are also ways of using non power of two textures with OpenGL. You could try invesigating those methods if this is something you want.
Sunday, 04 May 2008, 09:21
Phoenix
I've already investigated those methods, and I've found that not all cards support those extensions. Including mine.

(Yes, I'm still on this laptop with awful specs).
Sunday, 04 May 2008, 09:26
HoboBen
Sometimes engines cheat and if you give it a 513 by 513 texture, it'll draw it on a 1024 by 1024 square instead.

It's a bit of a nasty solution, but if you're using a 2D-in-3D technique, it can be handy not to have to worry about perfectly 2^n textures for everything.