#### Archived

This topic is now archived and is closed to further replies.

# texturing polygon

This topic is 5977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am a opengl beginner and I am reading throught the tutorial on this site. I got up to texture, and I want to try something on my own. Here''s the question: we all know that bitmap much be rectangular, how do I texture a polygon that''s not rectangular (or just not square), be it triangular, or even more vertices. Here''s another, why does the image has to be 256x256 (power of 2). The tutorial just say IT HAS TO. Is there a reason? Is there a work around?

##### Share on other sites
You can kind think of the texture as picture layed over your polygon(s), and whereever the vertices touch the picture is the offest of that point on the texture. For example:

If you texture a square like this with one texture:

0---------1
|---------|
|---------|
|---------|
|---------|
3---------2

the offsets would be:

0(u,v) = (0.0f, 0.0f)
1(u,v) = (1.0f, 0.0f)
2(u,v) = (1.0f, 1.0f)
3(u,v) = (0.0f, 1.0f).

So, if you want to texture the following shape with one texture:

0-
|----
|-------
|---------1
|---------|
3---------2

the texture offsets would be something like:

0(u,v) = (0.0f, 0.0f)
1(u,v) = (1.0f, 0.8f)
2(u,v) = (1.0f, 1.0f)
3(u,v) = (0.0f, 1.0f).

Now, if you wanted to put one texture over four connected quads:

a0-------a1,b0--------b1
|----------|----------|
|----------|----------|
|----------|----------|
|----------|----------|
a3-------a2,b3--------b2
c0-------c1,d0--------d1
|----------|----------|
|----------|----------|
|----------|----------|
|----------|----------|
c3-------c2d3--------d2

the texture offsets would be:

a0(u,v) = (0.0f, 0.0f) b0(u,v) = (0.5f, 0.0f)
a1(u,v) = (0.5f, 0.0f) b1(u,v) = (1.0f, 0.0f)
a2(u,v) = (0.5f, 0.5f) b2(u,v) = (1.0f, 0.5f)
a3(u,v) = (0.0f, 0.5f) b3(u,v) = (0.5f, 0.5f)

c0(u,v) = (0.0f, 0.5f) d0(u,v) = (0.5f, 0.5f)
c1(u,v) = (0.5f, 0.5f) d1(u,v) = (1.0f, 0.5f)
c2(u,v) = (1.0f, 1.0f) d2(u,v) = (1.0f, 1.0f)
c3(u,v) = (0.0f, 1.0f) d3(u,v) = (0.5f, 1.0f).

As far as texture sizes go, OpenGL puts a power of 2 limitation on textures, but if I'm not mistaken, gluBuild2DMipmaps(...) will generate textures from an image inwhich the dimensions aren't a power of 2.

I Hope that helps and doesn't confuse you any more.

Take Care,
Nyko

Edited by - Nyko on January 13, 2002 6:30:24 PM

Edited by - Nyko on January 13, 2002 6:35:22 PM

##### Share on other sites
THank you, that was very good explaination on Texture Coord...
I can see that say you want a shape of:
-
---
-----
------
------
------
------
the you just "map" points on the texture to the polygon:
say I have a square bitmap of tiles...I can just kinda draw up the polygone inscribed by square and see the coords. the vertexes lies...that''s cool..

but what if say I have a wierd shaded 4-side polygone, like the one above...but I have a square bitmap of the woodenboard...like the one in tutorial 7...so it''s a sqare board, with sides...is it possible to aligned the four sides (the darker color wood) along a non-rectangular polygone like the one above????
------------------
| |
| | no-rectangular four-sided | | ====?====> polygone, with the four sides
| | match???
| |
| |
------------------

if that''s not possible, the I think we HAVE to draw another bitmap with the polygon shaped side board on it, right??

• 10
• 16
• 9
• 13
• 41