Ooops
March 01, 2021, 10:07:14 PM

Author Topic: [bmx] DX UV wrap by tonyg [ 1+ years ago ]  (Read 420 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] DX UV wrap by tonyg [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : DX UV wrap
Author : tonyg
Posted : 1+ years ago

Description : Will wrap a texture depending on the UV settings rather than clamp it to the surface size.

Code :
Code: BlitzMax
  1. Strict
  2. Graphics 800,600
  3. Cls
  4. Function tg_setuv(image:TImage,u0#,v0#,u1#,v1#,frame:Int=0)
  5.   TD3D7ImageFrame(image.frame(frame)).SetUV(u0#,v0#,u1#,v1#)
  6. End Function
  7. Function tg_resetuv(image:TImage,frame:Int=0)
  8.     TD3D7ImageFrame(image.frame(frame)).SetUV(0.0,0.0,1.0,1.0)
  9. End Function
  10. Local base:Timage = LoadImage("max.png")
  11. Local u0#                       = 0
  12. Local v0#                       = 0
  13. Local u1#                       = 0.5
  14. Local v1#                       = 1
  15. Local frame:Byte         = 0
  16. Local wrap_u0# = 0.0
  17. Local wrap_v0#                  = 0.0
  18. Local wrap_u1#                  = 2.0
  19. Local wrap_v1#                  = 2.0
  20. While Not KeyHit(KEY_ESCAPE)
  21.         Cls
  22.         tg_SetUV(base,u0#,v0#,u1#,v1#)
  23.         DrawImage(base,0,0)
  24.         setwrap()
  25.         tg_SETUV(base,wrap_u0#,wrap_v0#,wrap_u1#,wrap_v1#)
  26.         DrawImage base , 400 , 0
  27.         tg_resetuv(base)
  28.         setnowrap()
  29.         DrawImage base , 0 , 200
  30.         Flip
  31. Wend
  32. Function setwrap()
  33.         PrimaryDevice.device.SetTextureStageState( 0, D3DTSS_ADDRESS,   D3DTADDRESS_WRAP);
  34. End Function
  35. Function setnowrap()
  36.         PrimaryDevice.device.SetTextureStageState( 0 , D3DTSS_ADDRESS ,         D3DTADDRESS_CLAMP) ;
  37. End Function


Comments :


tonyg(Posted 1+ years ago)

 Seems to work OK but there was no feedback from the person who asked for it so I can only assume it worked.


Jake L.(Posted 1+ years ago)

 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!


tonyg(Posted 1+ years ago)

 No problem Jake. I just worry that me running it a few times and somebody using it for real are two different things.


Yan(Posted 1+ years ago)

 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]


H&K(Posted 1+ years ago)

 lol,Yea Tony, were's your code to make sure its a Pow 2 image. Slacker ;)


tonyg(Posted 1+ years ago)

 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?


Yan(Posted 1+ years ago)

 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.


tonyg(Posted 1+ years ago)

 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.


Yan(Posted 1+ years ago)

 Yeah, sorry about that, my first post wasn't at all clear, even with the edit. :o/It's a gift... ;o)


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal