Aligning a texture on a polygon... help
I've gone over several texturing examples, but they all seem to only deal with cubes. What if I have a face that's more than 4 vertices? Say I have a face like this:
V1 {0.0, 0.0, 1.0} ------------- /\.
V2 {1.0, 0.0, 1.0} ------------ /--\.
V3 {1.0, 1.0, 1.0} ----------- |----|.
V4 {0.5, 1.5, 1.0} ----------- |----|.
V5 {0.0, 1.0, 1.0} ----------- |----|. Polygon like this.
how can I map a texture to this face so it doesn't warp?
(Using a simple checker board pattern for example, and without disecting the face into simpler polygons).
And references or articles would be appreciated.
[edited by - Xorcist on March 29, 2004 8:15:37 PM]
I assume what you meant by "not warping" is that the image just gets cut off where the polygon narrows instead of being scrunched to fit into the polygon. In this case... you need to detect the width & height of your polygon & then any point that you specify with glvertex3f() (or whatever, I forget the actual name) you also have to specify texture coordinates, but not just any texture coordinates, scaled coordinates. & by the way... after looking at your diagram... you don''t even have your vertices correct... or at least not understandable. So here is a better one:
so first find the max bounds of the shape & compute the width & height:
width = height = 2.0 //in this case
For the effect you want, the point of every vertice in this shape should be scaled down to the max dimensions of a texture, which are:
width = height = 1.0 //standard for texture coords
So for each point in the shape, divide the X value by the width & divide each Y-value by the height & you will find your texture coordinates. So the gltextcoord() that you specify for these vertices are:
t1 = { 0.5 , 1.0 }
t2 = { 0.0 , 0.5 }
t3 = { 1.0 , 0.5 }
t4 = { 0.0 , 0.0 }
t5 = { 1.0 , 0.0 }
notice they are similar to the actual vertice coordinates except scaled down by the width & height. FYI - this scaling assumes that the reference point of the polygon has the minimum X & Y coordinates of any point in the polygon. So in real time... find the minimum x & y values for each poly, find their width & height, & then find your texture coordinates based on the scaled vertice coordinates relative to the min X & Y. This scaling doesn''t have to be scaling down either, it also works for scaling up. Does any of this make sense to anybody?
1 /\ 2 / \ 3 | | | | 4 5v1 = {1,2,1}v2 = {0,1,1}v3 = {2,1,1}v4 = {0,0,1}v5 = {2,0,1}
so first find the max bounds of the shape & compute the width & height:
width = height = 2.0 //in this case
For the effect you want, the point of every vertice in this shape should be scaled down to the max dimensions of a texture, which are:
width = height = 1.0 //standard for texture coords
So for each point in the shape, divide the X value by the width & divide each Y-value by the height & you will find your texture coordinates. So the gltextcoord() that you specify for these vertices are:
t1 = { 0.5 , 1.0 }
t2 = { 0.0 , 0.5 }
t3 = { 1.0 , 0.5 }
t4 = { 0.0 , 0.0 }
t5 = { 1.0 , 0.0 }
notice they are similar to the actual vertice coordinates except scaled down by the width & height. FYI - this scaling assumes that the reference point of the polygon has the minimum X & Y coordinates of any point in the polygon. So in real time... find the minimum x & y values for each poly, find their width & height, & then find your texture coordinates based on the scaled vertice coordinates relative to the min X & Y. This scaling doesn''t have to be scaling down either, it also works for scaling up. Does any of this make sense to anybody?
Whatsoever you do, do it heartily as to the Lord, and not unto men.
4 /\ 5 / \ 3 | | | | 1 ---- 2V1 {0.0, 0.0, 1.0}V2 {1.0, 0.0, 1.0}V3 {1.0, 1.0, 1.0}V4 {0.5, 1.5, 1.0}V5 {0.0, 1.0, 1.0}usingT1 {0.0, 0.0}T2 {1.0, 0.0}T3 {1.0, 1.0}T4 {0.5, 1.5}T5 {0.0, 1.0}
Actually I meant to set it up like this (didn''t know you could use "code" to preserve spacing). What ends up happening, using a checkerboard texture, is that between 1,2,3 the texture maps fine, but between the rest of the points the texture skews such that the checkerboard is not straight up and down. I assume this is since I didn''t do the proper division you spoke of. I''ll try it out tonight and let you know how it goes.
March 31, 2004 02:02 AM
I don''t think you want to use a texture coordinate of 1.5, then you get into a whole other problem. Try sticking to numbers between 0.0 - 1.0, otherwise you will effectively "roll" the texture. Since the height of THAT polygon is 1.5, just divide the Y value''s of all the vertices by 1.5, so your real texture coords are:
T1 {0.0, 0.0}
T2 {1.0, 0.0}
T3 {1.0, 0.667}
T4 {0.5, 1.0}
T5 {0.0, 0.667}
notice they are scaled down for the Y-axis. try that.
T1 {0.0, 0.0}
T2 {1.0, 0.0}
T3 {1.0, 0.667}
T4 {0.5, 1.0}
T5 {0.0, 0.667}
notice they are scaled down for the Y-axis. try that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement