Sign in to follow this  
PnP Bios

Non power of 2 texture woes...

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
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:

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
Or :)


// Check for some extensions.
Extensions = strdup((char*)glGetString(GL_EXTENSIONS));

if (strstr("GL_ARB_texture_rectangle", Extensions) == 0)
{
TextureType = GL_TEXTURE_RECTANGLE_ARB;
}
else
{
TextureType = GL_TEXTURE_2D;
DoYourPowerOf2FunctionThingHere();
}



Should do it I guess :P ( Works fine for me )

Share this post


Link to post
Share on other sites
Thanks everybody for the feedback. Like I have said, and what is fairly obvious from my post, I am realy kinda new to OpenGL. I have played with it in the past, but I never even got as far as lighting. I did some texture stuff, but that was about it for 3d. I will look into loading and checking for the extension.

Again, thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by PinguinDude
Or :)

*** Source Snippet Removed ***

Should do it I guess :P ( Works fine for me )

So, PenguinDude, I have to do that for everywhere that needs GL_TEXTURE_2D, or just bind?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this