Repeating padded textures?

Started by
8 comments, last by Decrius 15 years, 2 months ago
Supposedly I'd have a 400x400 texture, which is put in a 512x512 OpenGL texture. Now I want to repeat the texture and fill the whole screen (tiling). However, we have a gap of 112 pixels on the right and the bottom of the texture that shouldn't be drawn. I've been writing software support for this problem, but it's SLOW. Mainly due to recalculating texture offsets whenever the texture doesn't fully fits the area (no more). Do we have native support or extensions that support this? Or has anyone got an optimized way of doing this? Thanks!
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Advertisement
No, there are no extensions for that type of repeating.

options are:
1. Make a 400x400 texture. The GPU will support it if you have GL 2.0
http://www.opengl.org/wiki/NPOT_Textures
2. stretch the texture to 512x512
3. If we are talking about rendering tiles, make lots of small quads and render the texture you already have on each quad, with texcoords 0.0 to 400/512 - 0.375/512
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
V-man covered all your options.

Why would you not just stretch it to 512. Your not losing any quality unless you strech an image smaller. Non-power of 2 textures, even if supported are apparently still slower.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Hmm stretching...how? Using an FBO, where you render to the FBO the stretched texture, and read it back as a new texture?
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
I'd just use mspaint. Or Photoshop. Or whatever you used to make the texture in the first place, completely removed from the rendering process :).
Another option might be shaders, i.e. calculate the texture coordinates in the vertex/pixel shader (e.g. map your coordinates from [0,1] to [0,400/512]). I do this when texturing terrain using tiles from a texture atlas.

You should take care of mip mapping problems though (mostly color bleeding), i.e. either disable mipmapping, provide your own mipmaps or create a colored border at the right and bottom edges.

If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Yes, Lord Evil, that's another thing: textures could be in a texture atlas, so I guess the only way is to support texture repeat software wise or writing a shader? (I'm rather unknown with shaders so far).

Textures won't have mipmapping, it's a GUI project :-)
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
If the textures could also be in an atlas and still should be tileable you'll need to use shaders.

It's not so tough, have a look into GLSL/CG. The hardest part is getting a shader to execute, which normally involves 4 steps: loading, compiling, binding, setting parameters. Most of those steps are done via a small set of functions (my basic code for handling cg shaders is about 20 lines).

Writing the shader is rather easy, with the hardest part calculating your texture coordinates. When you have those it's just reading the texture at those coordinates and returning the color (maybe multiplied with the geometry color or otherwise modified).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Awesome, thanks! I will try this out! ;)
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
How would using GL_TEXTURE_RECTANGLE_NV solve this problem? What is the chance it's not supported? Would I need to write a lot of code to make it also work for people who don't have the extension available? Or can I default to something else that uses unnormalised coordinates...?
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora

This topic is closed to new replies.

Advertisement