Non-Power of 2 Texture

Started by
12 comments, last by silvermace 18 years, 10 months ago
I'm in the process of creating a little app that mates USGS DEM (digital elevation) data to an image (a registered map of some kind). The DEM data gets turned into a mesh, the image is the texture for said mesh. The problem here is that the image is rarely going to be in power of two dimensions, and I can't resize it (via stretching or shrinking) as it will distort the image too much. The obvious, though to me somewhat inellegant way around this, is to add padding around the image to get it up to a power of 2. Anybody have a better way to do this?
Advertisement
Use this extension GL_ARB_texture_non_power_of_two .
bye
Quote:Original post by ff8
Use this extension GL_ARB_texture_non_power_of_two .
bye


Ah... forgot to mention. This has to be able to run on an old machine... or rather, old video card. I'm not counting on anything greater than OpenGL 1.2 functionality, so swanky extension won't do. Thanks, though.
Quote:Original post by glGuy3f
The obvious, though to me somewhat inellegant way around this, is to add padding around the image to get it up to a power of 2.
While it sounds inellegant, I believe that it is the standard method, since the non-power-of-2 stuff is hardware dependent, and even now I think the majority of cards on the market don't support it. (I don't know how exactly this works with OGL, but that's how it is with D3D, so I suppose since it's a hardware limitation, it's the same on both.) I know that I use this method all the time, as it has been in all the sample code that I've looked at whenever it was needed.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
hey,

Rounding up to the next power of 2 is what I would consider the 'standard' way of doing things. If you're concerned about memory wastage [on cards where it's available] you may want to look into putting in an alternate path for non power of 2 textures.

An alternative [with the next power of 2] is clipping the textures so that you don't get so much wastage... IE, bad diagram:

Texture [300x70]:
||||||

Gets turned into texture [256x128]:
|||
=

or some other such equivelent system. Of course, this really isn't so great if you're not sure of the dimensions before hand. In that case, I'd probably try to put two or more textures into the 'spare' space remaining on the texture.

CJM
another solution is to change your texture coordinates from UV to texel positions and use GL_ARB_texture_rectangle (GL_EXT_texture_rectangle on older cards, same Enum's though)

compatability is great on NVIDIA (GeForce2+) and looks great on ATI (Radeon 7000+) but ATI's implmentation of the EXT version was pretty dodge AFAIK, though that has definatly changed in the ARB version (im using it just fine on my R9500 Pro)

compatability list for EXT_texture_rectangle
compatability list for ARB_texture_rectangle

OpenGL registry specs for ARB_texture_rectangle (which should be identical to the EXT version save the prefixes.)

Cheers
-Danu
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
I'll look into those extensions, I might be able to use TEXTURE_RECTANGLE one, but we're talking about an old Matrox (G200, if I recall) card here. The initial texture is large, anyway: 5000x3000 give or take, so I'll have to be breaking it into tiles (256x256, most likely). Some of the tiles will still have to be padded though or, if it works, created via that extension.

Thanks for the help, much appreciated.
Eh, you know, on my geforce6600 my max texture size is 4096x4096 you better be breaking it up :-p

cheers
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
IIRC you can use non power of 2 textures if you are using mipmaps, I think I read that in a nehe tutorial somewhere. Anyways hope that helps.
My Current Project Angels 22 (4E5)
Quote:Original post by Ademan555
Eh, you know, on my geforce6600 my max texture size is 4096x4096 you better be breaking it up :-p

cheers
-Dan


Heh, no doubt. I remember, not so fondly, of the day when the good ol' Voodoo3 could handle 256x256, max. Sadly, I'm revisiting those days...

This topic is closed to new replies.

Advertisement