PDA

View Full Version : Texturing Question/Problem GL_CLAMP GL_CLAMP_TO_EDGE



James A.
04-05-2006, 11:50 PM
Hello,

I did a search on this and found some similar problems but none that matched exactly to mine, so i hope you don't mind me asking.

I have one texture with dimensions 256 by 256, it contains regular tiled images (every 16 by 16 pixels) within it that i want to apply individually to quads in my 3D scene. However due to the bilinear(?) sampling i am getting unwanted influence from the neighbouring tiles on the edges of my quads.

For example using the second tile into the bitmap i have texture coordinates from (0.0625,0.0) to (0.125,0.625) and some of the colour from the neighbouring first, third and seventeenth tiles are showing though.

Using GL_LINEAR is not really an option as it looks quite out of place with the rest of the scene.

does GL_CLAMP_TO_EDGE fix this problem? are their any solutions aside from adjusting my texture coordinates to compensate?

zed
04-06-2006, 03:07 AM
quote]Using GL_LINEAR is not really an option as it looks quite out of place with the rest of the scene.[/QUOTE]
i assume u mean GL_NEAREST


does GL_CLAMP_TO_EDGE fix this problem? are their any solutions aside from adjusting my texture coordinates to compensate?GL_CLAMP_TO_EDGE wont help, the only options are NEAREST or witheach tile within the larger image create a border around the edge eg use the inside 14x14 pixels as standard (u will need to adjust the texture coordinates) and use the outside 1 pixel width as a border. this invloves quite a bit of wortk (i know from experience, its not fun) and also will not work 100% if u use mipmapping (though its better than nothing)
another option is to increase the image from say 256x256->2048x2048 ie 16x16->128x128 this will make the errors less noticable.

James A.
04-06-2006, 03:40 AM
Yeah, sorry I did mean GL_NEAREST.

Thanks for your help, I did have a feeling that it wouldn't work but i wasn't sure.

OK i have another question: If on loading my bitmap, before telling openGL about it, I go through the individual texels and split it up into blocks of 16 by 16 registering all of them individually, and making sure i have the clamping around the edges selected correctly it should get rid of the effects right? But it is alright performance wise to register lost of small textures?

Zulfiqar Malik
04-06-2006, 04:47 AM
Originally posted by James A.

OK i have another question: If on loading my bitmap, before telling openGL about it, I go through the individual texels and split it up into blocks of 16 by 16 registering all of them individually, and making sure i have the clamping around the edges selected correctly it should get rid of the effects right? But it is alright performance wise to register lost of small textures?

That will give you the behavior, as you desire. However, this will involve lots of texture changes which is a batch killer. Its not a problem for such a small application such as yours, but lots of texture changes are in general not recommended.

James A.
04-06-2006, 06:56 PM
Thank you very much for your help. I think, as i was expecting to use more than just one 256 by 256 bitmap I shall have to try Zed's method of placing a border around the edge and see how that works out.

Thanks again,

James A.
04-06-2006, 08:41 PM
Would it work if I loaded by big textures in as normal as whenever i needed to put on of the squares inside those bitmaps into the scene I copied the section i wanted to a separate registered bitmap of the right size using glTexSubImage2d?

In this case i wouldn't be swapping all the time, only when a differing section was called, and i wouldn't have to split up all the textures. in the worste case i would be using glTexSubImage for eacy tile on screen and not each one in memory.

There is no way of copying data from one part of the video memory to another is there?

edit: sorry my first post didn't make much sense.

arekkusu
04-07-2006, 02:14 AM
It seems like the crop rectangle feature of the OES_draw_texture extension would do exactly what you want. But this is an OpenGL ES 1.1 extension, desktop GL doesn't support this functionality.

James A.
04-07-2006, 02:52 AM
oh well, maybe it will be added in in the future :)