PDA

View Full Version : Two Questions About Textures



cpsmusic
01-16-2006, 08:06 AM
Hi,

I've currently put together a simple multitexture program. I have two questions that I hope someone on this list can help me with.

1. Is is possible to place a texture in the centre of a polygon? For example, if I have a 5 x 5 square polygon, can I draw a texture in a 1 x 1 square in the centre of the poly but not draw it anywhere else?

2. I've managed to get a simple lightmap working however when I move around the scene it flickers a lot (sometimes it disappears completely!). Why is this happening and is there a way to fix it?

Cheers,

Chris

cpsmusic
01-16-2006, 08:22 AM
Dont't worry about the second question as I've sorted that out.

I'm still not sure about the first one though.

Cheers,

Chris

Obli
01-16-2006, 09:05 AM
Originally posted by cpsmusic:

1. Is is possible to place a texture in the centre of a polygon? For example, if I have a 5 x 5 square polygon, can I draw a texture in a 1 x 1 square in the centre of the poly but not draw it anywhere else?Yes, but you'll have to set up the texcoords accordingly and provide a correct wrap mode.
I'll be more specific: you need something like CLAMP (or variants) and a border color which 'clips' the texture. Another option is to avoid all texture contributions when out of unwrapped texture space thuru a fragment shader.
A similar result could be accomplished thuru multitexturing.

The approaches I suggested you all require the texture to have correct borders - you know how CLAMP works.

dorbie
01-16-2006, 09:32 AM
YOu can use borders as suggested or you can simply make sure the border of your texture has alpha = 0 and be more broadly and more efficiently supported. Using an alpha test will even kill the fragments.

The flickering is probably caused by zfighting. Make sure you use glPolygonOffset to avoid zfighting, but if both passes are textured I'd have expected fill invariance to work. Oh well, all sorts of state can mess with this on older cards. You could try to use multitexture instead of multipass for your lighting to avoid the flickering.

cpsmusic
01-16-2006, 01:53 PM
Hi,

I'm not sure what you mean by


you need something like CLAMP (or variants) and a border color which 'clips' the texture. Another option is to avoid all texture contributions when out of unwrapped texture space thuru a fragment shader.
A similar result could be accomplished thuru multitexturing. Would it be possible for you to explain this further.

Cheers,

Chris

dorbie
01-16-2006, 02:03 PM
Look at the documentation for glTexParameterf, specifically for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T.

Also look at texture borders (not that I recommend using them).