Advertisement

texture coords problem

Started by January 13, 2003 06:45 AM
0 comments, last by werdy666 22 years, 1 month ago
this is probably simple, but could someone help me with the right formula to get a quad to animate a texture? I have a 64x256 image loaded as a texture, and i have 4 images that animate the quad. what i can''t work out is how to set my texcoords to make it display the correct part of the image depending on what animation frame it is on. this is my code so far..... it displays all the 4 images together instead of just one at a time....

				glTexCoord2f(0.0 ,1-(1/anim)); glVertex2d(-15.0,-15.0);
				glTexCoord2f(1.0 ,1-(1/anim)); glVertex2d(15.0,-15.0);
				glTexCoord2f(1.0 ,1/anim ); glVertex2d(15.0,15.0);
				glTexCoord2f(0.0 ,1/anim ); glVertex2d(-15.0,15.0);
 
where anim changes from 1 - 4. Any help you can give would be appreciated. Thanks Werdy666
good to see your doing things the really fast way :-)

ok,

your right with the x texture coords, being 0 and 1,
as for the y, this may help,

think of the texture in terms of a grid, half way down is 0.5.. a quater way down is 0.25.. 3/4 is 0.75.. etc.


so, you want to show the first quater, then second, etc...

so, you have to show the range, from 0 to 0.25, then 0.25 to 0.5, then 0.5 to 0.75, then finally 0.75 to 1...

the equation for this is pretty simple, really,

start:
0.25*(anim-1)

end:
0.25*anim

tada :-)




| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

This topic is closed to new replies.

Advertisement