🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Texture wrapping on objects ??

Started by
3 comments, last by NinjaCross 24 years ago
Hi guys !! I have a question... How can I tile a single texture on the poligons of a mesh, model, objetc... ??? I explain. The texture is really bigger than the poligons of the mesh (or others objects), and so i want that the poligons are tiled and wrapped correctly on the surfaces of the object. How can i do it ?? I know what I should do if i want to tile textures in a single poligon, but i don''t know what i should do if i want that the textures are applied to more poligons !! Please, help meee !!! //------------- Making Funny Fake Codes //-------------
//-------------A straight line may be the shortest distance between two points, but it is by no means the most interesting.http://members.xoom.it/NinjaCross
Advertisement
As a simple example take a look at the flag effect tutorial, it applies the texture to a mesh of polygons. If you try to wrap it around really complex object such as a humanoid model you will run into lots of problems figuring it out, but that lesson is a good place start.

Morgan
thanks Morgan, i''ll check it ASAP !

//-------------
Making Funny Fake Codes
//-------------
//-------------A straight line may be the shortest distance between two points, but it is by no means the most interesting.http://members.xoom.it/NinjaCross
Hi NinjaCross,

The way to go about wrapping a texture around a complex model (such as a humanoid) is just a matter of figuring out what texture coordinates to assign to each vertex.

I believe this is how the "skins" in the Quake series works (ie, one big rectangular image that has texture info for every face of the model).


I'm finding it a bit hard to explain without a good visual aid... but here goes. I'll use a really lame cube as an example.

NOTE: in my "diagrams" , wherever there is a /, it should be a vertical bar, but the messageboard doesn't allow them.

1. Take your model and "break" it so that it can lay flat (this is just conceptual, don't alter the x,y,z values of the vertices)

    ----    /  /------------/   /  /   /------------    /  /    ----    /  /    ---- 


2. Now, looking at the layout of the model on this 2D plane, we can draw a lovely picture on each side of the cube and store it in a bitmap (or whatever) that only just encloses the polys).

------------/   / @/   /------------/ + / #/ * /------------/   / %/   //   ----   //   / $/   /------------ 


... there, isn't that beautiful


3. Next, we make this bitmap into a single texture (load it up etc as usual). The tricky bit is figuring out what the texture coordinates are for each vertex of the cube. For convenience sake, we'll ignore the fact that some vid cards don't like textures that aren't square, and we'll assume the texture is the dimensions shown (height:width = 4:3).

This means that the texture coords you would specify for the face you want to display the $ picture on would be like this:

    glBegin(GL_QUADS);       ...       ...              glTexCoord2f(0.33, 0.0);       glVertex3f(0.0, 0.0, 0.0);       glTexCoord2f(0.66, 0.0);       glVertex3f(0.1, 0.0, 0.0);       glTexCoord2f(0.66, 0.25);       glVertex3f(0.1, 0.1, 0.0);       glTexCoord2f(0.33, 0.25);       glVertex3f(0.0, 0.1, 0.0);       ...       ...    glEnd();  


...Now I'll explain why I chose those texture coords.

Now, we'll work under the assumption that the bottom-left corner of the texture image has tex coords (0,0) and the top-right has coords (1,1).
Because we want to specify only a small region of the whole texture for the face, the "bottom-left" of the face gets the tex coords (0.33, 0.0), and the "top-right" gets the coords (0.66, 0.25). This is because the region we want starts one third of the distance across the image (at the bottom), and finishes two thirds of the way across the image (at one quarter of the way up the image).

By repeating this process for the other faces of our lame cube, we can map different parts of our large texture onto each face.


Damn, that was a really long post. Well, I hope I didn't confuse the hell out of you... at least I know what I mean

-------------
squirrels are a remarkable source of protein...

Edited by - Bad Monkey on June 8, 2000 11:14:07 PM
Thankyou BadMonkey !!
Don''t worry you have been very clear, and you helped me very much !!
Thankyou again, and bye bye !

//-------------
Making Funny Fake Codes
//-------------
//-------------A straight line may be the shortest distance between two points, but it is by no means the most interesting.http://members.xoom.it/NinjaCross

This topic is closed to new replies.

Advertisement