Jump to content
  • Advertisement
Sign in to follow this  
PnP Bios

Non power of 2 texture woes...

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Because of the 2D libray I am writing is well... 2D, I need to handle non-power of 2 textures in a reasonable manner. Neither of the cards I have worked on were able to handle a 640 by 480 texture. So I did some digging. It turns out that there is an ARB extension for this, and that is about as far as I got. So, now I have 2 questions: 1) How do I use the non-power of 2 ARB extension? 2) What should I do for poor people like me who's video cards don't support it? One thought I had was that I simply rebuild the surface to the next nearest power of two, but I have also heard that you can use mip-mapping. From what I understand, mipmapping is only good for level of detail when sorting Z.

Share this post


Link to post
Share on other sites
Advertisement
I have tried non-power-of-2 textures in my game, and they work just fine. Same goes with textures over 512x512. I dunno why, but it is working (no extensions, nothing out of the ordinary OpenGL) :)

Share this post


Link to post
Share on other sites
If your video card doesn't support power non power of 2 textures make every image on a 256x256 or 512x512 image and use alpha channels to only show for example the 39x737 part :)

Share this post


Link to post
Share on other sites
Simplest (??) way would be to have pointer to function (ie. sth like bool (*funcPtr) (Usint32 width, Usint32 height, andOthers...)) which would be filled during library initialization if such GL extensions are available with pointer to function which would use that extension, if no, then you probably to pass function that would expand texture to power of 2, and use only that part of normal, not expanded size through texture coordinates. Then in texture loading code you check if sizes are of power 2, and if not, just call funcPtr().

If it sounds unclear (my english sucks :P) I can try to precise things up.

Share this post


Link to post
Share on other sites
Quote:
Original post by Koshmaar
Simplest (??) way would be to have pointer to function (ie. sth like bool (*funcPtr) (Usint32 width, Usint32 height, andOthers...)) which would be filled during library initialization if such GL extensions are available with pointer to function which would use that extension, if no, then you probably to pass function that would expand texture to power of 2, and use only that part of normal, not expanded size through texture coordinates. Then in texture loading code you check if sizes are of power 2, and if not, just call funcPtr().

If it sounds unclear (my english sucks :P) I can try to precise things up.


That is a wonderfull idea, and one I would probably do, if I could figure out how to test weither or not the extension is available.

Share this post


Link to post
Share on other sites
Ok, sticking with the lowtech method for now. I need to know how to find the next power of two.

int hxiNextPowerOfTwo(int val)
{
int rv = 0;
for(int i = 0; i < 32; i += 1)
{
if(pow(2,i) >= val)
return pow(2,i);
}

return rv;
}

This doesn't seem to want to work though...

Share this post


Link to post
Share on other sites
Quote:
Original post by PnP Bios
That is a wonderfull idea, and one I would probably do, if I could figure out how to test weither or not the extension is available.


*points at GLee in the forum FAQ*

Share this post


Link to post
Share on other sites

Quote:

That is a wonderfull idea, and one I would probably do, if I could figure out how to test weither or not the extension is available.


Of course that by checking available OGL extensions! :-] it's explained in Red Book and dozens of other OGL tutorials.

-----

Now I also think that you could also somehow check if users card is cappable of supporting non power of 2 textures and if so, then ignore other functions and just create surface, let the card handle the rest of nitty gritty details.

Quote:

Ok, sticking with the lowtech method for now. I need to know how to find the next power of two.


This version may be slightly faster:



typedef unsigned short int usint;

usint PowerOfTwo(usint _input)
{
usint value = 2; // better 1, though in 99,99% you won't be creating such tiny textures in normal SDL games

while ( value < _input )
{
value <<= 1;
}
return value;
}



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!