Sign in to follow this  

Texture Non Power of 2 size ?

This topic is 4775 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

Hello. I know it is possible to make textures load without them having a size like 2x2 4x4 8x8 16x16 etc. But I would like to know how to for example load a 342x859 texture. :) If anyone can give me some code or post a link to a tutorial or... I would be very happy :) And I will be so nice to rate the guy that gave me the most useful tutorial or code or tip :)

Share this post


Link to post
Share on other sites
If you want to really be able to load a non-power-of-two textures into your video memory, you'll have to use the TEXTURE_RECTANGLE extension or something similar. Check the SGI extension registry . I think though that this extension don't support some filter formats(mipmapping mostly).

If you just want to be able to load image files with non-power of 2 dimensions, there is an easiest way. You can load them using gluBuild2DMipmaps(). You don't have to do anything else yourself,it will automatically scale the image to a power of 2, and then load it. The texture that will be stored in VRAM will be power of 2, but the image file from where you load it don't need to.

Just make sure you set glPixelStoref(GL_UNPACK_ALIGNMENT,1), because it's 4 by default and you'll get memory errors if the alignment of the image don't match.

Share this post


Link to post
Share on other sites
Hrm, im actually glad you brought this up, because the openGL 2.0 specification states that non-power of 2 textures was brought to core... but i dont know if that means we still need to extend to use it... any clarifications here?

thanks
-Dan

Share this post


Link to post
Share on other sites
It's basically another texture target, like GL_TEXTURE_2D so you can do with it whatever you do with GL_TEXTURE_2D. Read the spec of the extension if you want to learn more.

Quote:

Hrm, im actually glad you brought this up, because the openGL 2.0 specification states that non-power of 2 textures was brought to core... but i dont know if that means we still need to extend to use it... any clarifications here?


2.0 promotes many things to the core, but Microsoft will not update the libs beyond 1.2(I think), so we will still have to access them through the extension mechanism. Anyway, this particular extension don't require to load new functions, only some constants defined in the header file.

Share this post


Link to post
Share on other sites
only some constants defined in the header file.???

what will those be?

I ve include glprocs.c and glprocs.h to my project visual studio... with the following headers:


#include <gl.h>
#include <glext.h>
#include <wglext.h>
#include <glprocs.h>

so far, I didnt have to load the extensions one by one like you guys probably do... and it works no problems... but for some reasons when I test to get either...

GL_EXT_texture_rectangle and/or
GL_ARB_texture_non_power_of_two


the extension are not found but the programs compiles without any errors or crashes... having:

glEnable(GL_TEXTURE_RECTANGLE_ARB);
glEnable(GL_ARB_texture_non_power_of_two);

plus... a texture 178 x 385... just doesnt show up...

what am i missing here... any ideas?

THX

Share this post


Link to post
Share on other sites
You need to replace everything that you normally would do GL_TEXTURE_2D with the extension define. I still haven't tested it but that seems what has to be done to get it working :) I dont see why most games dont use this since it seems to have been an extension since OPenGL 1.1 :o !?

Share this post


Link to post
Share on other sites

One option that hasn't been addressed and is very simple is just using the next power of two up in size from your non-power-of-two size, and not scaling but just making sure that your texture coords. match up with the smaller image in the texture.

This is often a good approach, especially with smaller textures (the amount of waste is not as great). But certainly it is wasteful, although one often seems to find that when non-power-of-two textures are given to drivers that they simply do this anyway.

~SPH

Share this post


Link to post
Share on other sites

This topic is 4775 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.

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