November 25, 2020, 05:08:56 AM

Author Topic: [bb] 2d alpha rotation and scaling realtime for b3d only sry blitz+ :( by Nate the Great [ 1+ years ago ]  (Read 616 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : 2d alpha rotation and scaling realtime for b3d only sry blitz+ :(
Author : Nate the Great
Posted : 1+ years ago

Description : This is a free 2d alpha engine only in 3d mode.  It uses multi layered rendering and 3d rectangles (not blitz sprites) I am working on incorperating textures in at the moment. Here is a list of the functions. (NTG stands for Nate the Great) :)

DrawNTG
UpdateNTG
NTGsetblend
NTGsetrotation
NTGsetscale
NTGsetalpha
NTGCreateRect
NTGinit2dAlpha


Code :
Code: BlitzBasic
  1. Graphics3D 640,480,0,2
  2.  
  3. lit = CreateLight(2)
  4.  
  5. MoveEntity lit,0,-101,0
  6.  
  7. SetBuffer BackBuffer()
  8.  
  9. Global NTGox#
  10. Global NTGoz#
  11. Global NTGpixelwidth#
  12. Global NTGpixelheight#
  13. Global NTGinit = False
  14. Global NTGplane
  15. Global NTGcam
  16. Global NTGheight#
  17. Global NTGrotation#
  18. Global NTGscalex# = 1
  19. Global NTGscaley# = 1
  20. Global NTGalpha# = 1
  21. Global NTGblend = 3
  22.  
  23. Type NTGsprite
  24.         Field entity,active
  25. End Type
  26.  
  27.  
  28. NTGinit2dAlpha()
  29. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  30. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  31. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  32. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  33.  
  34.  
  35.  
  36.  
  37.  
  38. Type rects
  39.         Field x#,y#,rot#,rotspeed#,vx#,vy#,lif,ent.NTGsprite
  40. End Type
  41.  
  42.  
  43.  
  44. rect1.NTGsprite = NTGcreateRect.NTGsprite(40,40)
  45.  
  46. cnt# = 1
  47.  
  48. timer = MilliSecs()
  49. While Not KeyDown(1)
  50. Cls
  51.  
  52. NTGsetrotation cnt#
  53. NTGsetscale Sin(cnt#),Sin(cnt#)
  54. NTGsetalpha Sin(cnt#/2)/2 + .5
  55. DrawNTG rect1.NTGsprite,MouseX(),MouseY()
  56.  
  57. NTGsetscale 1,1
  58.  
  59.         For r.rects = Each rects
  60.                 NTGsetrotation r
  61. ot#
  62.                 NTGsetalpha rlif/255.0
  63.                 DrawNTG rent.NTGsprite,rx#,ry#
  64.                 rlif = rlif - 1
  65.                 r
  66. ot# = r
  67. ot# + r
  68. otspeed#
  69.                 rx# = rx# + rvx#
  70.                 ry# = ry# + rvy#
  71.                 rvy# = rvy# + .07
  72.                 If ry# > 480 Then
  73.                         rvy# = - rvy#*Rnd#(.5,.9)
  74.                         ry# = 480
  75.                 EndIf
  76.                
  77.                 If rlif = 0 Then
  78.                         FreeEntity rententity
  79.                         Delete rent.NTGsprite
  80.                         Delete r.rects
  81.                 EndIf
  82.         Next
  83.  
  84. If MouseDown(1) Then
  85.         r.rects = New rects
  86.         rx# = MouseX()
  87.         ry# = MouseY()
  88.         r
  89. ot# = Rnd(360)
  90.         r
  91. otspeed# = Rnd#(-10,10)
  92.         rvx# = Rnd#(-3,3)
  93.         rvy# = Rnd#(-3,4)
  94.         rlif = 255
  95.         rent.NTGsprite = NTGCreateRect.NTGsprite(40,40,255,0,255)
  96. EndIf
  97.  
  98. cnt = cnt + 1
  99. If cnt = 720 Then cnt = 0
  100.  
  101. UpdateWorld()
  102. RenderWorld()
  103. UpdateNTG()
  104.  
  105. .stt1
  106. If MilliSecs()-timer > 0 Then
  107. .stt   
  108.         x = 1000/(MilliSecs()-timer)
  109.         If x > 58 Then Goto stt
  110.         Text 1,1,x
  111. Else
  112.         Goto stt1
  113. EndIf
  114. timer = MilliSecs()
  115.  
  116. Flip
  117. Wend
  118.  
  119.  
  120. Flip
  121. WaitKey()
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  132. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  133. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  134. ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. Function DrawNTG(hand.NTGsprite,x#,y#)
  146.  
  147. ShowEntity handentity
  148. handactive = True
  149. PositionEntity handentity,NTGox# + x#*NTGpixelwidth#,0,NTGoz# + y#*NTGpixelheight
  150. RotateEntity handentity,0,NTGrotation#,0
  151. ScaleEntity handentity, NTGscalex#,1,NTGscaley#
  152. EntityAlpha handentity, NTGalpha#
  153. EntityBlend handentity, NTGblend
  154.  
  155. End Function
  156.  
  157.  
  158. Function UpdateNTG()
  159.  
  160. For s.NTGsprite = Each NTGsprite
  161.         sactive = False
  162.         HideEntity sentity
  163. Next
  164.  
  165. End Function
  166.  
  167. Function NTGSetBlend(bld)
  168.         NTGblend = bld
  169. End Function
  170.  
  171. Function NTGSetRotation(Rot# = 0)
  172.         NTGrotation = rot#
  173. End Function
  174.  
  175. Function NTGsetscale(sclx# = 1,scly# = 1)
  176.         NTGscalex# = sclx#
  177.         NTGscaley# = scly#
  178. End Function
  179.  
  180. Function NTGsetalpha(alph# = 1)
  181.         NTGalpha# = alph#
  182. End Function
  183.  
  184.  
  185. Function NTGCreateRect.NTGsprite(width#,height#,r = 255,g = 255,b = 255)
  186.  
  187. tmp.NTGsprite = New NTGsprite
  188. tmpentity = CreateMesh()
  189. tmpsurf = CreateSurface(tmpentity)
  190. width# = width# / 2
  191. height# = height# / 2
  192. v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#))
  193. v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#))
  194. v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#))
  195. v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#))
  196.  
  197.  
  198. AddTriangle(tmpsurf,v3,v4,v2)
  199. AddTriangle(tmpsurf,v2,v4,v1)
  200.  
  201. EntityColor tmpentity,r,g,b
  202.  
  203. UpdateNormals tmpentity
  204.  
  205. HideEntity tmpentity
  206.  
  207. Return tmp.NTGsprite
  208.  
  209. End Function
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219. Function NTGinit2dAlpha(maxrng# = 1000)
  220.  
  221. NTGcam = CreateCamera()
  222. NTGinit = True
  223.  
  224. If NTGcam = 0 Then RuntimeError("Camera does not exist.")
  225.  
  226. NTGplane = CreatePlane()
  227.  
  228. TurnEntity NTGplane,-90,0,0
  229. MoveEntity NTGplane,0,-2,0
  230. EntityParent NTGplane,NTGcam
  231. EntityAlpha NTGplane,0
  232. EntityPickMode NTGplane,2
  233.  
  234. CameraRange NTGcam,.01,maxrng#
  235. TurnEntity NTGcam,90,0,0
  236. MoveEntity NTGcam,0,0,100
  237. CameraZoom NTGcam,3
  238. CameraClsMode NTGcam,0,1
  239.  
  240. CameraPick NTGcam,1,1
  241.  
  242. x1# = PickedX()
  243. z1# = PickedZ()
  244. NTGheight# = PickedY()
  245.  
  246. CameraPick NTGcam,GraphicsWidth(),GraphicsHeight()
  247.  
  248. x2# = PickedX()
  249. z2# = PickedZ()
  250.  
  251.  
  252. NTGox# = x1#
  253. NTGoz# = z1#
  254.  
  255. NTGpixelwidth# = (x2#-x1#)/GraphicsWidth()
  256. NTGpixelheight# = (z2#-z1#)/GraphicsHeight()
  257.  
  258. End Function


Comments :


Nate the Great(Posted 1+ years ago)

 I guess what I am trying to do here is write something that makes blitz 3d more like blitz max.  One thing I didn't mention before is that you can just make a normal camera before you call the init function and it will act like normal on your game. and I think it eliminates the alpha problem between the camera for the 2d fx and the normal camera so your sprites will never look like they are behind the water wich they are obviously not behind.  I also have locked it at 58 fps because it keeps it from leaping between 58 and 1000 fps on my machine... it is very unstable.


MikhailV(Posted 1+ years ago)

 Like FastImage and SpriteCandy :)You anew invent bicycle...


Nate the Great(Posted 1+ years ago)

 yeah... it was just for the learning experience. I got the idea from fastimage because I like to know how every part of my game works... I even made a small 3d engine for blitzbasic when it first came out. I wish I had known about this blog earlier :)P.S. I know it isn't as fast as fastimage but it can handle 200 sprites easily which serves my purpose especially since I have added a load2dsprite function for images.


Nate the Great(Posted 1+ years ago)

 ok I added NTGloadimage now this will be more useful... here is the code.P.S. you have to replace the name of my image with the name of your own image for this to work.after you move the mouse around a little hold the space bar down and move the mouse around some more.
Code: [Select]



Graphics3D 640,480,0,2

lit = CreateLight(2)

MoveEntity lit,0,-101,0

SetBuffer BackBuffer()

Global NTGox#
Global NTGoz#
Global NTGpixelwidth#
Global NTGpixelheight#
Global NTGinit = False
Global NTGplane
Global NTGcam
Global NTGheight#
Global NTGrotation#
Global NTGscalex# = 1
Global NTGscaley# = 1
Global NTGalpha# = 1
Global NTGblend = 3

Type NTGsprite
Field entity,active
End Type


NTGinit2dAlpha()
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||


img1.NTGsprite = NTGLoadImage.NTGsprite("img1.jpg",256) ;PUT YOUR PICTURE HERE :) HOLD DOWN THE SPACE BAR AFTER YOU RUN THIS ONE

While Not KeyDown(1)
Cls

DrawNTG img1.NTGsprite,MouseX(),MouseY()

If KeyDown(57) Then
NTGSetRotation MouseX()
NTGsetalpha MouseY()/480.0
EndIf

UpdateWorld()
RenderWorld()
UpdateNTG()

.stt1
If MilliSecs()-timer > 0 Then
.stt
x = 1000/(MilliSecs()-timer)
If x > 58 Then Goto stt
Text 1,1,x
Else
Goto stt1
EndIf
timer = MilliSecs()

Flip
Wend


Flip
WaitKey()









;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||










Function DrawNTG(hand.NTGsprite,x#,y#)

ShowEntity handentity
handactive = True
PositionEntity handentity,NTGox# + x#*NTGpixelwidth#,0,NTGoz# + y#*NTGpixelheight
RotateEntity handentity,0,NTGrotation#,0
ScaleEntity handentity, NTGscalex#,1,NTGscaley#
EntityAlpha handentity, NTGalpha#
EntityBlend handentity, NTGblend

End Function


Function UpdateNTG()

For s.NTGsprite = Each NTGsprite
sactive = False
HideEntity sentity
Next

End Function

Function NTGSetBlend(bld)
NTGblend = bld
End Function

Function NTGSetRotation(Rot# = 0)
NTGrotation = rot#
End Function

Function NTGsetscale(sclx# = 1,scly# = 1)
NTGscalex# = sclx#
NTGscaley# = scly#
End Function

Function NTGsetalpha(alph# = 1)
NTGalpha# = alph#
End Function


Function NTGCreateRect.NTGsprite(width#,height#,r = 255,g = 255,b = 255)

tmptex = CreateTexture(64,64)
SetBuffer TextureBuffer(tmptex)

Color r,g,b
Rect 0,0,65,65,1

SetBuffer BackBuffer()

tmp.NTGsprite = New NTGsprite
tmpentity = CreateMesh()

tmpsurf = CreateSurface(tmpentity)
width# = width# / 2
height# = height# / 2
v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),0,0)
v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),1,0)
v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),1,1)
v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),0,1)


AddTriangle(tmpsurf,v3,v4,v2)
AddTriangle(tmpsurf,v2,v4,v1)

;EntityColor tmpentity,r,g,b

UpdateNormals tmpentity

EntityTexture tmpentity, tmptex

HideEntity tmpentity

Return tmp.NTGsprite

End Function



Function NTGLoadImage.NTGsprite(imageext$,texw = 64)

tmpimg = LoadImage(imageext$)
width# = ImageWidth(tmpimg)
height# = ImageHeight(tmpimg)

ResizeImage tmpimg,texw,texw

tmptex = CreateTexture(texw,texw)
SetBuffer TextureBuffer(tmptex)

DrawImage tmpimg,1,1

SetBuffer BackBuffer()

tmp.NTGsprite = New NTGsprite
tmpentity = CreateMesh()

tmpsurf = CreateSurface(tmpentity)
width# = width# / 2
height# = height# / 2
v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),0,0)
v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),1,0)
v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),1,1)
v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),0,1)


AddTriangle(tmpsurf,v3,v4,v2)
AddTriangle(tmpsurf,v2,v4,v1)

;EntityColor tmpentity,r,g,b

UpdateNormals tmpentity

EntityTexture tmpentity, tmptex

HideEntity tmpentity

Return tmp.NTGsprite



End Function






Function NTGinit2dAlpha(maxrng# = 1000)

NTGcam = CreateCamera()
NTGinit = True

If NTGcam = 0 Then RuntimeError("Camera does not exist.")

NTGplane = CreatePlane()

TurnEntity NTGplane,-90,0,0
MoveEntity NTGplane,0,-2,0
EntityParent NTGplane,NTGcam
EntityAlpha NTGplane,0
EntityPickMode NTGplane,2

CameraRange NTGcam,.01,maxrng#
TurnEntity NTGcam,90,0,0
MoveEntity NTGcam,0,0,100
CameraZoom NTGcam,3
CameraClsMode NTGcam,0,1

CameraPick NTGcam,1,1

x1# = PickedX()
z1# = PickedZ()
NTGheight# = PickedY()

CameraPick NTGcam,GraphicsWidth(),GraphicsHeight()

x2# = PickedX()
z2# = PickedZ()


NTGox# = x1#
NTGoz# = z1#

NTGpixelwidth# = (x2#-x1#)/GraphicsWidth()
NTGpixelheight# = (z2#-z1#)/GraphicsHeight()

End Function
Oh... and By the way... I would recomend loading all sprites before the game not ingame because they use resize image which causes major slowdown.If anyone has anything they want me to add please tell me. I love a challenge.


Nate the Great(Posted 1+ years ago)

 Here is the final file... the file that you should include if you use it.
Code: [Select]
Global NTGox#
Global NTGoz#
Global NTGpixelwidth#
Global NTGpixelheight#
Global NTGinit = False
Global NTGplane
Global NTGcam
Global NTGheight#
Global NTGrotation#
Global NTGscalex# = 1
Global NTGscaley# = 1
Global NTGalpha# = 1
Global NTGblend = 1
Global NTGBlue = 255
Global NTGGreen = 255
Global NTGRed = 255
Global NTGorder = 0

Type NTGsprite
Field entity,active,tex
End Type






Function DrawNTG(hand.NTGsprite,x#,y#,frm = 0)

ShowEntity handentity
handactive = True
PositionEntity handentity,NTGox# + x#*NTGpixelwidth#,0,NTGoz# + y#*NTGpixelheight
RotateEntity handentity,0,NTGrotation#,0
ScaleEntity handentity, NTGscalex#,1,NTGscaley#
EntityAlpha handentity, NTGalpha#
EntityBlend handentity, NTGblend
EntityColor handentity, NTGRed, NTGGreen, NTGBlue
EntityTexture handentity,hand ex,frm
EntityOrder handentity,NTGorder
NTGorder = NTGorder - 1

End Function


Function UpdateNTG()

For s.NTGsprite = Each NTGsprite
sactive = False
HideEntity sentity
Next

NTGorder = 0

End Function

Function NTGsetcolor(r,g,b)

NTGred = r
NTGgreen = g
NTGblue = b

End Function

Function NTGSetBlend(bld)
NTGblend = bld
End Function

Function NTGSetRotation(Rot# = 0)
NTGrotation = rot#
End Function

Function NTGsetscale(sclx# = 1,scly# = 1)
NTGscalex# = sclx#
NTGscaley# = scly#
End Function

Function NTGsetalpha(alph# = 1)
NTGalpha# = alph#
End Function








Function NTGCreateRect.NTGsprite(width#,height#,r = 255,g = 255,b = 255)

tmptex = CreateTexture(64,64)
SetBuffer TextureBuffer(tmptex)

Color r,g,b
Rect 0,0,65,65,1

SetBuffer BackBuffer()

tmp.NTGsprite = New NTGsprite
tmpentity = CreateMesh()

tmpsurf = CreateSurface(tmpentity)
width# = width# / 2
height# = height# / 2
v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),0,0)
v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),1,0)
v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),1,1)
v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),0,1)


AddTriangle(tmpsurf,v3,v4,v2)
AddTriangle(tmpsurf,v2,v4,v1)

;EntityColor tmpentity,r,g,b

UpdateNormals tmpentity

EntityTexture tmpentity, tmptex
tmp ex = tmptex

HideEntity tmpentity

Return tmp.NTGsprite

End Function













Function NTGLoadImage.NTGsprite(imageext$)

tmpimg = LoadImage(imageext$)
width# = ImageWidth(tmpimg)
height# = ImageHeight(tmpimg)


tmptex = LoadTexture(imageext$,4)

tmp.NTGsprite = New NTGsprite
tmpentity = CreateMesh()
tmp ex = tmptex
tmpsurf = CreateSurface(tmpentity)
width# = width# / 2
height# = height# / 2
v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),0,0)
v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),1,0)
v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),1,1)
v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),0,1)


AddTriangle(tmpsurf,v3,v4,v2)
AddTriangle(tmpsurf,v2,v4,v1)

;EntityColor tmpentity,r,g,b

UpdateNormals tmpentity

EntityTexture tmpentity, tmptex

HideEntity tmpentity

Return tmp.NTGsprite



End Function










Function NTGLoadAnimImage.NTGsprite(imageext$,w,h,f,c)

tmpimg = LoadImage(imageext$)
width# = ImageWidth(tmpimg)
height# = ImageHeight(tmpimg)


tmptex = LoadAnimTexture(imageext$,4,w,h,f,c)

tmp.NTGsprite = New NTGsprite
tmpentity = CreateMesh()
tmp ex = tmptex

tmpsurf = CreateSurface(tmpentity)
width# = width# / 2
height# = height# / 2
v1 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),0,0)
v2 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,0-(height#*NTGpixelheight#),1,0)
v3 = AddVertex(tmpsurf,(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),1,1)
v4 = AddVertex(tmpsurf,0-(width#*NTGpixelwidth),NTGheight#,(height#*NTGpixelheight#),0,1)


AddTriangle(tmpsurf,v3,v4,v2)
AddTriangle(tmpsurf,v2,v4,v1)

;EntityColor tmpentity,r,g,b

UpdateNormals tmpentity

EntityTexture tmpentity, tmptex

HideEntity tmpentity

Return tmp.NTGsprite



End Function











Function NTGinit2dAlpha(maxrng# = 1000)

NTGcam = CreateCamera()
NTGinit = True

If NTGcam = 0 Then RuntimeError("Camera does not exist.")

NTGplane = CreatePlane()

TurnEntity NTGplane,-90,0,0
MoveEntity NTGplane,0,-2,0
EntityParent NTGplane,NTGcam
EntityAlpha NTGplane,0
EntityPickMode NTGplane,2

CameraRange NTGcam,.01,maxrng#
TurnEntity NTGcam,90,0,0
MoveEntity NTGcam,0,0,100
CameraZoom NTGcam,3
CameraClsMode NTGcam,0,1

CameraPick NTGcam,1,1

x1# = PickedX()
z1# = PickedZ()
NTGheight# = PickedY()

CameraPick NTGcam,GraphicsWidth(),GraphicsHeight()

x2# = PickedX()
z2# = PickedZ()


NTGox# = x1#
NTGoz# = z1#

NTGpixelwidth# = (x2#-x1#)/GraphicsWidth()
NTGpixelheight# = (z2#-z1#)/GraphicsHeight()


lit = CreateLight(3)

MoveEntity lit,0,-101,0
TurnEntity lit,90,0,0

End Function






Function EndNTG()

For n.NTGsprite = Each NTGsprite
FreeEntity nentity
Delete n.NTGsprite
Next

End Function






Function ScaleImageFast(SrcImage, ScaleX#, ScaleY#, ExactSize=False)

Local SrcWidth,  SrcHeight
Local DestWidth, DestHeight
Local ScratchImage, DestImage
Local SrcBuffer, ScratchBuffer, DestBuffer
Local X1, Y1, X2, Y2

; Get the width and height of the source image.
SrcWidth  = ImageWidth(SrcImage)
SrcHeight = ImageHeight(SrcImage)

; Calculate the width and height of the dest image, or the scale.
If ExactSize = False

DestWidth  = Floor(SrcWidth  * ScaleX#)
DestHeight = Floor(SrcHeight * ScaleY#)

Else

DestWidth  = ScaleX#
DestHeight = ScaleY#

ScaleX# = Float(DestWidth)  / Float(SrcWidth)
ScaleY# = Float(DestHeight) / Float(SrcHeight)

EndIf

; If the image does not need to be scaled, just copy the image and exit the function.
If (SrcWidth = DestWidth) And (SrcHeight = DestHeight) Then Return CopyImage(SrcImage)

; Create a scratch image that is as tall as the source image, and as wide as the destination image.
ScratchImage = CreateImage(DestWidth, SrcHeight)

; Create the destination image.
DestImage = CreateImage(DestWidth, DestHeight)

; Get pointers to the image buffers.
SrcBuffer     = ImageBuffer(SrcImage)
ScratchBuffer = ImageBuffer(ScratchImage)
DestBuffer    = ImageBuffer(DestImage)

; Duplicate columns from source image to scratch image.
For X2 = 0 To DestWidth-1
X1 = Floor(X2 / ScaleX#)
CopyRect X1, 0, 1, SrcHeight, X2, 0, SrcBuffer, ScratchBuffer
Next

; Duplicate rows from scratch image to destination image.
For Y2 = 0 To DestHeight-1
Y1 = Floor(Y2 / ScaleY#)
CopyRect 0, Y1, DestWidth, 1, 0, Y2, ScratchBuffer, DestBuffer
Next

; Free the scratch image.
FreeImage ScratchImage

; Return the new image.
Return DestImage

End Function
for a sample download the following 3 files sorry I couldn't zip them.  run the one called test.bbhttp://files.filefront.com/NTG+imagebb/;12232060;/fileinfo.htmlhttp://files.filefront.com/shippng/;12232059;/fileinfo.htmlhttp://files.filefront.com/testbb/;12232057;/fileinfo.html [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal