Sign in to follow this  
OpenGL_Guru

non-power of 2 textures -- what are my options??

Recommended Posts

I need to change my texturing technique on a surface from a 1D to a 2D texture. i wont go into why i need it, just trust that i need it for various reasons. there is one problem.. the surface is not a power of 2. i am working with a NV FX 5700.. ive checked the extensions and GL_ARB_texture_non_power_of_2 extension is not listed. was there or is there a non-power of 2 texture for this card thats not an extension? i mean something added on before the ARB extension? I am assuming that this card doesnt have this capability so i am wondering what my options are. if my surface lets say is 1300x500 i could always take a ratio but i would rather not. i have heard of the NV_RECTANGLE extension but dont know if this is what i want. any thoughts? appreciate the help...

Share this post


Link to post
Share on other sites
For the latest geforce cards there is also GL_ARB_texture_non_power_of_two ...but as you can see below it isn't supported on anything less than GeForce 6 series cards [headshake]

Free Image Hosting at www.ImageShack.us

Share this post


Link to post
Share on other sites
You have GL_NV_texture_rectangle and GL_ARB_texture_rectangle which are of course there--but there are a number of caveats for use, such as non normalized texture coordinates, different texture targets, inability to use mipmap filtering: everything should be there in the registry.

If you want to use GLU there is a function gluScaleImage which can scale the image to a power of two--you could try that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Metorical
Can you not just use the next power of 2 up?

e.g. if it's 48 then use 64?


He can indeed fit this smaller image into a larger POT image, but it's a messy solution at best. It involves a lot of readjustment of texture coordinates and may introduce some filtering artifacts on the edges of the image. A much simpler solution is to simply scale the images in an image editing suite to the appropriate dimensions. Don't use the automatic power of two scaling in the GLU library, cause quite frankly it's horrible...

Share this post


Link to post
Share on other sites
so let me see if i have this right.. or if you think this would be a good idea..

btw here is the gluScaleImage link courtesy of msdn.

what my code does or is supposed to do is create an image first. the image will be a bitmap so i will be working with bytes. so in my class i declare:

unsigned byte src_image = new unsigned byte[500*1300*4];
unsigned byte dest_image = new unsigned byte[1024*1300*4];

i will color the image or assign the indices of the images based on the common (value/(max-min) /2) formula.

Now as far as i understand only the w or the h has to be a power of 2 right? you dont have to have both. So i could in theory have a 1024x1300 and be just fine. is this correct?

this is the call i should make.. i think:

gluScaleImage(GL_COLOR_INDEX, 500, 1300, GL_UNSIGNED_BYTE, src_image, 1024, 1300, GL_UNSIGNED_BYTE, dest_image);

so your thoughts? on the right track or any other suggestions? thanks for all your help..

oh yeah i looked up the GL_ARB_texture_rectangle in the SGI registry and for this project i dont need mipmapping or GL_REPEAT.. but my formula for assigning the colors to the texture give me a result from 0..1... so i think this is a problem? i dunno if that is true 100%.

Share this post


Link to post
Share on other sites
Quote:
Original post by Darragh
Quote:
Original post by Metorical
Can you not just use the next power of 2 up?

e.g. if it's 48 then use 64?


He can indeed fit this smaller image into a larger POT image, but it's a messy solution at best. It involves a lot of readjustment of texture coordinates and may introduce some filtering artifacts on the edges of the image. A much simpler solution is to simply scale the images in an image editing suite to the appropriate dimensions. Don't use the automatic power of two scaling in the GLU library, cause quite frankly it's horrible...


Darragh,
the idea i have is to create a 2D texture and assign the colors of the texture before applying the texture to the surface. This will save me loads of texture calls, especially when i am assigned a texture coordinate for every vertex of my surface..which is what i am doing now. this slows down my FPS horribly. if i could assign the texture colors ahead of time i can just paste the 2D texture on my surface my assigning them via just 4 TexCoord2D() calls instead of 500*1300 like i am now with a 1D texture.

Share this post


Link to post
Share on other sites
do not use gluScaleImage(..) its most likely not what u want
with nv3x GL_ARB_texture_non_power_of_2 runs in software
theres no problems with ARB_texture_rectangle though with nv3x if its suitable use it

Share this post


Link to post
Share on other sites
Quote:
Original post by OpenGL_Guru
gluScaleImage(GL_COLOR_INDEX, 500, 1300, GL_UNSIGNED_BYTE, src_image, 1024, 1300, GL_UNSIGNED_BYTE, dest_image);

I am not saying that it is a good idea to use this, but still, FYI, the first parameter would be GL_RGB or GL_BGR dpending on whether you flip the color channels of the bitmap images while loading. Also, the *datain is a pointer to the loaded pixel data, you wouldn't need a new unsigned byte[...] for that.

Quote:
oh yeah i looked up the GL_ARB_texture_rectangle in the SGI registry and for this project i dont need mipmapping or GL_REPEAT.. but my formula for assigning the colors to the texture give me a result from 0..1... so i think this is a problem? i dunno if that is true 100%.

It should be pretty easy to modify the texture coordinates: just multiply the x-coordinate by the image width, y-coordinate by height when calling glTexCoord. Of course you need to keep track of the image width and height, but that shouldn't be very difficult. [smile]

/edit: Regarding your other question, both image width and height must be power of two (excluding border)

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