Jump to content
  • Advertisement
Sign in to follow this  
Decrius

OpenGL Repeating padded textures?

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

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Hmm stretching...how? Using an FBO, where you render to the FBO the stretched texture, and read it back as a new texture?

Share this post


Link to post
Share on other sites
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 :).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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...?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!