Sign in to follow this  
Juksosah

Mapping an image on a quad

Recommended Posts

Hi again, Here's something I still don't understand : In my 3D game I have a billboarded quad with an image (150 X 450 pixels) with some text in it Now how will I be able to map this image in the quad without it being stretched (because text will no more be readable). What will be the height and width of the quad containing this pic? What will be the tex. coords ? How would you do it guys ? thanks

Share this post


Link to post
Share on other sites
Hello.
Theoreticaly, you just have to make sure the quad has the same aspect ratio as the thing that you put on it in order for nothing to get streched, squashed. For you, the aspect ratio is 150/450 = 0.3

However, the image of size 150x450 is not a valide texture size. Textures can be only square and multiple of 2, aka 16x16, 32x32, 64x64, 128x128, 256x256, 512x512 etc etc.

You have two options:
1. Put your image into a editing software and resize it to 256x256 so it is streched and square. The quad, make it of such size that it has an aspect ratio of 0.3 so when you put the texture on, it will get unsquished and unstreched. Visual quality of the texture might decrease after all this process. Having bigger textures (512x512) helps with this. In this case the texture coordinates would be 0,0 - 1,0 - 0,1 - 1,1. This means that you put the whole texture on the quad.

2. Option number two is two make a new image of size 512x512, and copy paste your billboard sign on the left top corner. This will occupie only 150x450 of the texture and you can fill the rest with black. The quad you make it of aspect ratio 0.3 and when you put the texture on it, you put only the part which has useful information, aka not all of it, just the first 150x450. You do this by editing the texture coordinates. For example to put only the first 150 pixels of the whole 512 pixels widht , the texture coordinate would be 150/512 = 0.29

Texture coordinates are between 0 and 1.

Hope this helps

Share this post


Link to post
Share on other sites
Quote:
Original post by EthanStorm
However, the image of size 150x450 is not a valide texture size. Textures can be only square and multiple of 2, aka 16x16, 32x32, 64x64, 128x128, 256x256, 512x512 etc etc.

Textures do not have to be square.

Share this post


Link to post
Share on other sites
In a normal 3D application I would go for option number 1 so there is no wasted texture space. Texture space is valuable and even if nowdays graphics card have alot of memory, that's no reason to waste it. In option 2 the black part is just wasted space while in option 1, even if there is some streching going on it will look better when you aproach the billboard or view it at angles and such because there is more texture information.

If I'm doing a 2D application, or just drawing the menus on the screen for my game, menus which are always in one place on the screen and flat, i would go for option 2 to avoid streching the texture.

Try both techniques and see which one you like best.

Share this post


Link to post
Share on other sites
oh ya. my bad. they don't have to be square. i only used square ones and got used to it.

but they have to be multiple of 2, aka those magic numbers (32, 64, 128 etc etc)

Share this post


Link to post
Share on other sites
Textures do not need to be square and they do not need to be power of 2 unless your video card lacks support.

Keeping an aspect ratio does not prevent resizing, but just keeps images from getting long or fat. If you want to prevent stretching/scaling you can check into setting the magnification and minification filters, or you can just calculate the polygon coordinates.

Notes:

Checking support for features is essential. Please look at D3DCAPS to learn what video cards can choose to support. D3DCAPS::TextureCaps has a D3DPTEXTURECAPS_SQUAREONLY and D3DPTEXTURECAPS_POW2 flag which relate to this specific topic.

Setting min/mag filters (D3DSAMP_MINFILTER/D3DSAMP_MAGFILTER set to D3DTEXF_NONE) will apply to everything, and frequent switching may be expensive.

Calculating polygon coordinates to exact pixels is complicated if you are in a window, as you need to subtract the border from your calculations (a 640x480 windowed D3D app does not have a 640x480 D3D surface).


Good luck.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this