Non power of 2 texture woes...

Started by
13 comments, last by PnP Bios 19 years, 4 months ago
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.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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) :)
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 :)
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
Yes, I know I could just make the images larger... But I would rather take advantage of hardware where i can.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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.
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.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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...
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Wait, yes it does...
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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*

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;}

This topic is closed to new replies.

Advertisement