Texture edge artifact workaround question

The project I’m working on calls for many small textures (anywhere from 2px to 8px square), which must maintain their original detail (I’m basically making a mosaic out of a larger image). With the current ofTexture workaround, these small textures lose detail because they get scaled up. I noticed some comments in the code about padding the image with a 2px border and then recomputing the tex_t coords.

How can I carry out this solution? When you say a 2px border, do you mean an extension/duplication of the original edge pixels, as if the edge pixels have been clamped? And how should I recompute the tex_t and tex_u coords? Thanks for any help!

I’ve also written an extension of ofTexture with a method called drawQuad, which takes four points as arguments and maps the texture to them. This allows the user to map a tex to any shape of quad. It’s pretty sweet and almost done; I’ll post the source once it’s ready!

hi christian

two notes - the very soon to be released new version features two features in the code that you might enjoy:

a) it uses protected instead of private everywhere, so your inherited classes will be able to modify “private” variables

b) it includes opengl extension code for non-power of two textures.

you can find this code on the svn. we are pretty sick of saying “it’s coming” but we promise you it is - there are some very nice new things on the way…

if you are using power of two textures you can adjust these lines of code:

GLfloat offsetw = 1.0f/(tex_w);
GLfloat offseth = 1.0f/(tex_h);

so that the offset is 0.

this scaling hack is to fix an essential problem with opengl that has to do with non-power of two textures (essnetially uploading a subimage vis glTexSubImage2d) and the edges that are caused by cubic interpolation along the non-border edges of that texture. whew…

basically, if you have a texture that is 100 by 80, it gets uploaded into into a 128x128 texture, there are some edges:

xxxxxxx00
xxxxxxx00
xxxxxxx00
000000000

like the x/0 edges, where opengl will mess them up a bit. typical artifacts include white borders, black borders, etc.

secondly, you may want to alter this:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

to be GL_NEAREST which will do nearest neighbor interpolation for pixels, which will keep very small “pixely” like textures looking pixely when they are blown up.

some info:
http://www.khronos.org/opengles/documen-…-meter.html

that seems like a good thing to add to the texture class – picking smooth or not smooth. we will look into adding an option (like type has…)

hope that helps !!
zach

Ah, great, thanks Zach! That was a great explanation and clears up a lot for me. FYI, the project I’m working on involves animating Van Gogh’s “Starry Night” painting for a commercial… if all goes well, and if my boss gives the go ahead, I’ll post a mov in a couple weeks!