Code archives/Graphics/DX UV wrap
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Will wrap a texture depending on the UV settings rather than clamp it to the surface size. | |||||
Strict Graphics 800,600 Cls Function tg_setuv(image:TImage,u0#,v0#,u1#,v1#,frame:Int=0) TD3D7ImageFrame(image.frame(frame)).SetUV(u0#,v0#,u1#,v1#) End Function Function tg_resetuv(image:TImage,frame:Int=0) TD3D7ImageFrame(image.frame(frame)).SetUV(0.0,0.0,1.0,1.0) End Function Local base:Timage = LoadImage("max.png") Local u0# = 0 Local v0# = 0 Local u1# = 0.5 Local v1# = 1 Local frame:Byte = 0 Local wrap_u0# = 0.0 Local wrap_v0# = 0.0 Local wrap_u1# = 2.0 Local wrap_v1# = 2.0 While Not KeyHit(KEY_ESCAPE) Cls tg_SetUV(base,u0#,v0#,u1#,v1#) DrawImage(base,0,0) setwrap() tg_SETUV(base,wrap_u0#,wrap_v0#,wrap_u1#,wrap_v1#) DrawImage base , 400 , 0 tg_resetuv(base) setnowrap() DrawImage base , 0 , 200 Flip Wend Function setwrap() PrimaryDevice.device.SetTextureStageState( 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP); End Function Function setnowrap() PrimaryDevice.device.SetTextureStageState( 0 , D3DTSS_ADDRESS , D3DTADDRESS_CLAMP) ; End Function |
Comments
| ||
Seems to work OK but there was no feedback from the person who asked for it so I can only assume it worked. |
| ||
Oh, that's me ;) Sorry, tonyg, I thought my answer counts as "works great". So: it works like a charm and you really helped me with this! Big Thanx! |
| ||
No problem Jake. I just worry that me running it a few times and somebody using it for real are two different things. |
| ||
It's probably worth mentioning that this'll only work with pow2 images. [edit] As most people would probably expect it to, at least. [/edit] |
| ||
lol, Yea Tony, were's your code to make sure its a Pow 2 image. Slacker ;) |
| ||
Is there a problem with a non-pow2 texture? Does Bmax handle that on load as I don't get a problem with a non-pow2 image? |
| ||
When BMax loads an image it scales the texture up to the nearest power of two and blits the pixmap into the top left corner. This means that the bottom right of the image isn't necessarily at UV coords 1,1 and the texture, when wrapped, will show the 'empty' part of the texture. I don't know OGL or DX well enough to know whether it's possible to set a 'window' on the texture for wrapping. You could just make a new DrawWrappedImage command that scrolled the verts and UVs of a 2x2 quad around, I suppose. I didn't bother as the pow2 limitation was fine for my purposes. I thought I'd just mention this as people may be expecting the wrap to occur at the image boundary rather than the texture boundary. |
| ||
Sorry, I understand what everybody's getting out now. Yep, there'll be spaces between the 'wraps' if it's not pow2. For some reason I thought people were saying it was not working for non-pow2. I suppose I could rescale to nearest pow2 but it could have horrible results. Anyway, people can mess about as theyt see fit. |
| ||
Yeah, sorry about that, my first post wasn't at all clear, even with the edit. :o/ It's a gift... ;o) |
Code Archives Forum