BBstyle DrawImageRect

BlitzMax Forums/BlitzMax Programming/BBstyle DrawImageRect

tonyg(Posted 2007) [#1]
There are a few methods to do this but the set viewport method appears to cause problems. If there any advantages doing it another way (or problems with this
way) then please post.
This method has cropped up in a few posts so thanks to those who raised it.

P.S. This post is in relation to :
BlitzMaxier 2D? thread


Grey Alien(Posted 2007) [#2]
I'm using this which looks very similar. I don't use viewports as yes, they don't work on all cards. For me this used to be heresay until I saw it with my own eyes.

' -----------------------------------------------------------------------------
' ccDrawImageArea: Draws part of an image. (faster?)
' (by Ian Duff)
' -----------------------------------------------------------------------------
Function ccDrawImageArea(image:TImage, x#, y#, rx#, ry#, rw#, rh#, theframe=0)
 'Note that this code works fine in DirectX or OpenGL on PCs - it autodetects (Grey Alien).
 'Warning: make sure that none of your images have pixels right on the edge otherwise
 'when drawing clipped, they may leave smear in the clipped area!
  Local origin_x#, origin_y# ; GetOrigin (origin_x, origin_y)
  Local tw = ccDrawImageAreaPow2Size(image.width)
  Local th = ccDrawImageAreaPow2Size(image.height)
  Local rw1#  = rx + rw
  Local rh1#  = ry + rh
  Local x0# = -image.handle_x, x1# = x0 + rw
  Local y0# = -image.handle_y, y1# = y0 + rh
  
  If rw1 > image.width
    x1 = x0 + rw + image.width - rw1
    rw1 = image.width
  EndIf
   
  If rh1 > image.height
    y1 = y0 + rh + image.height - rh1
    rh1 = image.height
  EndIf
?Win32
  If TD3D7ImageFrame(image.frame(theframe))
    Local frame:TD3D7ImageFrame = TD3D7ImageFrame(image.frame(theframe))
    
    frame.setUV(rx / tw, ry / th, rw1 / tw, rh1 / th)
	frame.Draw x0, y0, x1, y1, x + origin_x, y + origin_y
    frame.setUV(0, 0, image.width / Float(tw), image.height / Float(th))
  Else
?
    Local frameA:TGLImageFrame = TGLImageFrame (image.frame(theframe))
                
    frameA.u0 = rx / tw
    frameA.v0 = ry / th
    frameA.u1 = rw1 / tw
    frameA.v1 = rh1 / th
    
    frameA.Draw x0, y0, x1, y1, x + origin_x, y + origin_y
    
    frameA.u0 = 0
    frameA.v0 = 0
    frameA.u1 = image.width / Float(tw)
    frameA.v1 = image.height / Float(th)
?Win32
  EndIf
?
  
  Function ccDrawImageAreaPow2Size%(n)
    Local ry = 1
    
    While ry < n
      ry :* 2
    Wend
    
    Return ry
  End Function
End Function



TartanTangerine (was Indiepath)(Posted 2007) [#3]
Grey, a drawimage rect function is already included in your framework - just look at my Bitmap font code :) Why re-invent the wheel.


tonyg(Posted 2007) [#4]
Off-topic, Tim did you get my email re:RTT?
I have posted on your forums, used PM, used Contact from indiepath.com and responded to the contact form email I received from that.


Grey Alien(Posted 2007) [#5]
Tim. ccDrawImageArea was in my framework before your bitmap font code, but now I have both. I've improved that bitmap font code in a number of cool ways (and fixed some bugs ;-)) You'll get it with the next update ... sooon...