Tiling part of texture?

Started by
4 comments, last by Taharez 22 years, 3 months ago
Hi guys. I'm currently working on a GUI for use with DirectX apps, but I'm sort of stuck when it comes to tiling textures on polygons. I use a square bitmap with different parts of the GUI mapped out on it, like a GUI component skin, but the only examples I've seen that utilize tiling uses the entire texture and then sets texture coordinates above 1.0 to set repeat frequency. This is of course not possible when I just use part of the texture. I would be grateful for any assistance provided, I usually don't ask questions here, as it has most likely been answered already, but I've yet to find the answer to this one. /edit/ UPDATE: Ok, I dropped an e-mail to Robert Dunlop over at The X-Zone, and according to his reply, it's impossible to tile part of a texture, so it's either dividing the bitmap into several textures, or dividing the primitive into more triangles. Just thought I'd update this in case someone searches for this topic in the fututre. /edit/ Edited by - Taharez on December 30, 2001 8:21:33 AM
Advertisement
  ImageRect.left   = 64-ScreenOffX;ImageRect.top    = 64-ScreenOffY;ImageRect.right  = ImageRect.left + 640;ImageRect.bottom = ImageRect.top  + 480;lpDevice3->SetTexture( 0, lpGround );tiles[0] = D3DTLVERTEX(D3DVECTOR( (float)0, (float)480.0,		1), 0.5f, 0xffffffff, 0, ImageRect.left*0.35/128.0, ImageRect.bottom*0.42/128.0);tiles[1] = D3DTLVERTEX(D3DVECTOR( (float)0, (float)0,			1), 0.5f, 0xffffffff, 0, ImageRect.left*0.35/128.0, ImageRect.top*0.42/128.0);tiles[2] = D3DTLVERTEX(D3DVECTOR( (float)640.0, (float)480.0,	1), 0.5f, 0xffffffff, 0, ImageRect.right*0.35/128.0, ImageRect.bottom*0.42/128.0);tiles[3] = D3DTLVERTEX(D3DVECTOR( (float)640.0, (float)0,		1), 0.5f, 0xffffffff, 0, ImageRect.right*0.35/128.0, ImageRect.top*0.42/128.0);lpDevice3->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX,tiles, 4, 0);  


That grabs a portion of the texture (ImageRect) and tiles it because the ImageRect*scale can be greater than 128 making the final value > 1.

Ben

I just love the response time in this place, and to think, it's Christmas Day..
Many thanks, Ben, I'll try it now.

/edit/

Ok, I don't quite follow you, I'm afraid.
I would be glad for some further explanation of the variables and values you use in the code:
-imageRect: this was supposed to represent a piece of the texture, right?
-"imageRect.left = 64-ScreenOfX;" what is the '64' here? the texture width?, and what is ScreenOfX?
-"imageRect.right = imageRect.left + 640;" what is 640 here?
-What are the modifiers 0.35 for width, and 0.42 for height?, how do you calculate them?
-Finally, how is the divisor ( 128.0 in your example ) calculated?

Sorry for all the questions, but I really like understanding what it is I'm doing, so that I feel I've learned something too.

Merry X-Xmas

/edit/

Edited by - Taharez on December 25, 2001 4:52:19 PM
ImageRect is the section you want of the texture. Ignore the values I have it set to as they''ll all fubar which is how I figured out this stuff in the first place. I didn''t want it to tile.

The divisor is the actual size of the texture.

(length of the texture) / (length of the primitive) is what you multiply the rect.left and right by.


(height of texture) / (height of primitive) is what you multiply the rect.top and bottom by

It''s proportions. If you set the mutilplier primitive values less than the actual dimensions of the primitive it should tile.

Ben

Thanks again, I must admit I was a little confused with the imageRect initialization =)

Happy New Year!
I'm sad to say I can't get this to work, as soon as I set u,v coords > 1.0, the entire texture is tiled, just with a displacement. I've spent a day looking through MSDN, but it's hopeless..
Please, if some has gotten this to work I'd really appreciate a message from you.

Ben, have you tested the code you put up? 'Cause if you have I'm just to damn stupid to get how it's supposed to work =( Thanks for your help, tho.

/edit/

An image says more than a thousand words..


/edit

Edited by - Taharez on December 26, 2001 2:16:47 PM

This topic is closed to new replies.

Advertisement