View Full Version : How you do that ? ( Sub imagens at exture )

DelNeto

09-16-2002, 04:48 PM

Hi,

I'v got a texture with a lot of sub-imagens that i use on my program.

My problem is how do i do to get the texture coordenates for each sub-image. The sub-imagens are not the same size.

How do you do that ?

Thanks, and sorry about my english.

DelNeto

newCoordTop = 1/TextureHeight*TopPixel

newCoordleft = 1/TextureWidth*LeftPixel

newCoordBottom = 1/TextureHeight*BottomPixel

newCoordRight = 1/TextureWidth*RightPixel

tinak

09-17-2002, 01:43 AM

I've tried this out before and the way you do it is something as follows:

The whole texture is like an opengl 2D screen with 0,0 being the bottom left point and 1,1 being the top right point..

So to get the corner points you would use

bottom left = x=0.00,y=0.00

bottom right = x=1.00,y=0.00

top left = x=0.00,y=1.00

top right = x=1.00,y=1.00

and you would effectively use the whole texture...

If it say had 4 textures of equal size then you would use points as following to access the bottom left texture..

bottom left = x=0.00,y=0.00

bottom right = x=0.25,y=0.00

top left = x=0.00,y=0.25

top right = x=0.25,y=0.25

and so on because 4 equal textures are a quarter the width and height...

Now for something a bit more fancy like unequal textures you would need to know what percentage of the full textures width and height each sub texture took up and where started from.. Your good old paint program will help you figure that out by showing you the actual pixel points for each corner of the sub textures so a bit of maths will help the rest..

Say, we had a texture on the bottom that took up the whole width but was only a 5th of the height then that would be accessed with something as follows: (off the top of my head so you may need to rework these a bit):

bottom left x=0.00,y=0.00

botttom right x=1.00,y=0.00

top left x=0.00,y=0.20

top right x=1.00,y=0.20

hopefully I didn't forget something else I might have done to get it to work.

Tina

[This message has been edited by tinak (edited 09-17-2002).]

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.