Advertisement

TexCoords(TRIANGLE?

Started by August 17, 2000 07:04 PM
9 comments, last by Cel 24 years, 3 months ago
Hey, I have a potentially dumb question: All these tutes I have found show how to assign texture co ordinates to GL_QUADS. This is fine because 4 vertices and 4 texture co ordinates (one for each texture corner). HOWEVER, I am currently slightly baffled at how to apply tex co ords to a triangle correctly! TRIANGLE = 3 vertices, 2d texture = 4 co ords....?? Please someone shed some light on applying textures to triangles as opposed to quads or have I just missed something really obvious?? Thnx heaps, Cel
Cel aka Razehttp://chopper2k.qgl.org
depends on how you want the image to look like. the 4 texture coords represent the four corners of the 2d image. suppose you want to pinch the upper right corner with the lower right corner, so that the image seems to taper to a point towards the right. then on a triangle, you would do something like

glvertex1
gltexcoord1
glvertex2
gltexcoord2
gltexcoord3
glvertex3
gltexcoord4

or something like that. if you map 2 tex coords to one vertex, that part of the image will be "pinched."

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Advertisement
how many bloody aussies post on this forum

very simple mate just use the same coords as u would for a quad
glvertex1
gltexcoordbottomleft 1 (0,0)
glvertex2
gltexcoordtopleft 2 (0,1)
glvertex3
gltexcoordtopright 3 (1,1)

2____3
|.../
|../
|./
|/
1

hi... these guys are right...
remember that top-left corner of the texture is 0,0
top-right is (1,0), bottom-left (0,1) and bottom-right (1,1)

if you aply texture by glTexCoord2f() or similar you can assign texture to each vertex but corners dont have to match... you can strech or shrink it ...
glvertex;
gltexcoord2f(0,0);
glvertex;
gltexcoord2f(0,0.5f); // streched
glvertex;
gltexcoord2f(0.5f,0.5f);

replace 0.5f with sth larger than 1 to shrink texture
example (0.5,0.5) is a middle point of texture ... (0.33f,0.33f)
is a point in 1/3 of lenght and height. ( excuse my english )
By giving other values than 0 or 1 ( glTexCoor2f ) you can have your texture ''rotated'' or ''moved''
Pet
oh yea ... I forgot... maybe that''ll help:
imagine that you put your points in 3d space by glVertex3f
and imagine tht by glTexCoord2f you place your triangle in a ''2d texture-space''

you probably knew that and taking p|ss out of my reply

anyway ... I read lots of posts before I compiled my own prog from scratch...

Pet
Pet
bottom left is 0,0 not top left
at least in opengl and maths i might add,
on a personal note (OT) this is a major pisser for me i spent 3 hours today working out me normals and i still havent got it 100% sussed cause in the confusion of sometimes counting z as up or z as down. eg 3dmax defines space in z==up + y into the screen , but i do the opposite ,easy problem u might think which for one case it is but layered cases ie sometimes up sometimes down blah blah all hell breaks loose hours down the tube etc
(hope u can understand that)
my advice pick one coornation system and stick to it religiously so if y is up always let y be up DONT make exceptions

Edited by - zedzeek on August 18, 2000 8:42:24 AM
Advertisement
ok,ok... maybe 0,0 if bottom left ... doesn''t really matter , right ?
Pet
Pet
ok,ok... maybe 0,0 if bottom left ... doesn''t really matter , right ?
Pet
I''m going to pretend I didn''t see a2k try to call glTexCoord 4 times with only 3 calls to glVertex.
you HAVE to call it 4 times because there are 4 SIDES to every bitmap. Hey, you guys using 3DS MAX. You're using the modifier UNWRAP UVW, right? well, that pretty much works the same was as the glTexCoord, except you manipulate the face vertices to match the bitmap, instead of the bitmap coords to the faces. Maybe i'm just talking shit, but if it WORKS FOR ME, I don't really care, right?

a2k

btw, regarding the coordinate system, i usually rotate the whole thing in max by 90 degrees before sending to my conversion utility. it DOES suck that the axes are flipped, but hell, 3DS MAX is just a way cool program.

Edited by - a2k on August 18, 2000 11:31:24 AM
------------------General Equation, this is Private Function reporting for duty, sir!a2k

This topic is closed to new replies.

Advertisement