PDA

View Full Version : manage your texture better!



jdz_simon
02-18-2004, 08:58 AM
I have studied your OpenGL tutorials for a long time.I am very interested in the texture mapping.Now,I have a question solve in time,however,I have no good idea for it after thinking again and again.My question as follows :
Can I map two or more two textures on one face of an object and keep those textures aligning according to some kinds of rules,rather than blending or replacing each other?for example ,the right top of the face is mapped by texture0,the left bottom of it is mapped by texture1.
Looking forward to reply!
Thank you in advance.

simon

Relic
02-18-2004, 11:03 PM
Yes, you can place a texture on a part of an object with this small trick:
Set the outmost texels to be transparent (alpha == 0). Use GL_CLAMP_TO_EDGE to not fall off the teximage during sampling.
Specify texture coordinates at the vertices to place the texture.
Rough example:
If you draw a quad and want the image to lie in the bottom left quarter the upper and right vertices need texture coordinates around 2.0, the lower left is at 0.0.
These is not exact, you need to adjust the texture coordinates very carefully to start on the opaque texels depending on where you want the texture edge!
For multiple texture you need to use multitexturing and do the same for each texture unit.

zeckensack
02-19-2004, 12:39 AM
Why all the effort? Do that as a "preprocessing" step.

Two obvious solutions:
a)merge the two textures into a single bigger texture and map it onto the surface in one piece
b)split the surface into multiple pieces

a) will perform best, at the expense of some "wasted" memory.
b) will not perform bad but you'll have to switch textures. Duh.

Both approaches avoid the nasty texcoord/mipmap filter/texture repeat problems that might occur otherwise.

Relic
02-19-2004, 03:48 AM
>>Why all the effort?<<
Because it's possible?! http://www.opengl.org/discussion_boards/ubb/biggrin.gif
No, seriously I wouldn't really do it either.

jdz_simon
02-19-2004, 04:50 PM
Originally posted by zeckensack:
Why all the effort? Do that as a "preprocessing" step.

Two obvious solutions:
a)merge the two textures into a single bigger texture and map it onto the surface in one piece
b)split the surface into multiple pieces

a) will perform best, at the expense of some "wasted" memory.
b) will not perform bad but you'll have to switch textures. Duh.

Both approaches avoid the nasty texcoord/mipmap filter/texture repeat problems that might occur otherwise.

I have ever thought about your solution,but I hold it is so difficult to realize.Now that I am a greenhand for OpenGL,I can't understand how to split the surface(such as floor) into multiple pieces.Can you help me ?

zeckensack
02-19-2004, 08:56 PM
Originally posted by jdz_simon:
I have ever thought about your solution,but I hold it is so difficult to realize.Now that I am a greenhand for OpenGL,I can't understand how to split the surface(such as floor) into multiple pieces.Can you help me ?Well well, this is hard to answer with full generality. There are certainly dozens of books that cover the topic. It's reasonably simple for quads, so I'll try that as an example.

You can split a quad into two quads by inserting an extra vertex at two opposite edges. Use linear interpolation for the vertex attributes.
Ie if an edge is 5 units long and you want a new vertex 3 units away from the "first" vertex (you'll simply have to choose one) ...

AB would be the vector describing the original edge ( =B-A )
Then the new vertex A' would be at A+(3*AB/5).
Do this for all attributes, ie if the color of the first vertex is cA and the color of the second vertex is cB, the color at the new vertex would be cA+(3*(cB-cA)/5). Normals are more complicated, as linear interpolation isn't sufficent for normals.

Then do it for the opposite edge.

Okay, we now have six vertices forming two quads instead of four vertices forming one quad. We can now split in the other direction. There are three edges (the two original edges and the new edge between our two new vertices). Each one would be split exactly as above, so we end up with nine vertices forming four quads.

Now you can map the textures to the split quads individually.