Sign in to follow this  
cskelton

non-square image loading in OpenGL

Recommended Posts

Does anyone know any way to load images that aren't sized to a power of two in OpenGL? I need to load a photo(4x6 or 3x5) for use as a texture.

Share this post


Link to post
Share on other sites
You've got a few options: pad the image to a POT size and then use texture co-ordinates to chop out the bit that you want, use the gluBuild2DMipmaps function which will take a non-POT texture or you could use the non_power_of_two extension.

I've not used the extension route myself and so I can't speak for how well it's supported but either of the two first options are fine. Probably using gluBuild2DMipmaps would be the easiest way.

Hope that helps!

Share this post


Link to post
Share on other sites
The non_power_of_two extension works well for GF6x00+ cards and probobly for ATI X800+ cards, just make shure you have the latest drivers.
I don't know about other cards though.

Share this post


Link to post
Share on other sites
Thanks guys. I think DevIL is going to do the trick, if I can figure out how to get it to work with Visual Studio .NET. If anyone knows how, I'd appreciate the help.

Share this post


Link to post
Share on other sites
Hi,

i assume that you are already able to load and use textures in opengl?

If you do, it's really easy to use non power of two textures:

1. check for the GL_ARB_texture_non_power_of_two extension.

2. if its supported, load textures as normal (glTexImage2D) - no code has to change, you dont have to add anything. Just set a non power of 2 width and height in glTexImage2D and use the texture as normal. This is the easiest extension ever!

If the extension is not supported, then you can either pad the image to the larger size, or use the NV_tex_rectangle extension - which is pretty well supported.


Share this post


Link to post
Share on other sites
Well, NV_tex_rect (and EXT_tex_rect for the same issue) are very widely supported but they're quite cumbersome to use unless you're writing a very small application.
In case this is your issue, you'll be very happy with them. I believe it's supported by everything after NV1x but I'm not sure. It is supported by sure means by NV2x and later.

Don't even think however using texture_rect for more advanced issues. The lack of wrapping modes, the different texture target and texture coordinate scheme will make you scream. Well, this actually won't happen until you start building up something complicated.
If you do, you'll find that for example, you need to retassellate geometry to accomodate simil-wrap modes, you'll have to have rect and POTD shaders and the machinery involved will rapidly pile up.
For more advanced applications, ARB_npotd (or GL2 for that matter) is a must.

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