Resizing Sprites

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Resizing Sprites

Post by Paul »

There is ResizeImage() for images and ZoomSprite3D() for 3D sprites...

It would really be nice to have a ResizeSprite() or ZoomSprite() command for sizing regular Sprites.
Image Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Yes,

and RotateSprite() for 2D Sprites too.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

really missing... dont only want have this for 3D Sprites!

please please add this command for the 2d commands too ^^ thx!

http://www.purebasic.fr/english/viewtop ... sizesprite
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Maybe this code could be an inspiration for Fred ;-)

Code: Select all

; 2005 Stefan (<-- brilliant DX-Progger sign. Hroudtwolf)
; PB-Club.de
; PB 4.00

#DDBLT_WAIT=16777216

Structure PB_Sprite
  Sprite.l
  Width.w
  Height.w
  Depth.w
  Mode.w
  FileName.l
  RealWidth.w
  RealHeight.w
  ClipX.w
  ClipY.w
EndStructure


Procedure ResizeSprite(Sprite,Width,Height);Gibt bei Fehlern 0 zurück.
  If Width<=0 Or Height<=0:ProcedureReturn 0:EndIf
 
  *Sprite.PB_Sprite=IsSprite(Sprite)
  If *Sprite=0:ProcedureReturn 0:EndIf
 
  *DDS.IDirectDrawSurface7=*Sprite\Sprite
  If *DDS=0:ProcedureReturn 0:EndIf
 
  *DDS\GetDDInterface(@*DD.IDirectDraw7)
  If *DD=0:ProcedureReturn 0:EndIf
 
  DDSD=AllocateMemory(124)
  If DDSD=0:ProcedureReturn 0:EndIf
 
  PokeL(DDSD,124)
  If *DDS\GetSurfaceDesc(DDSD):FreeMemory(DDSD):ProcedureReturn 0:EndIf
  PokeL(DDSD+8,Height)
  PokeL(DDSD+12,Width)
 
  If *DD\CreateSurface(DDSD,@*DDS2.IDirectDrawSurface7,0):FreeMemory(DDSD):ProcedureReturn 0:EndIf
 
  rect.RECT
  rect\left=0
  rect\right=Width
  rect\top=0
  rect\bottom=Height
  If *DDS2\Blt(rect,*DDS,0,#DDBLT_WAIT,0):FreeMemory(DDSD):*DDS\Release():ProcedureReturn 0:EndIf
 
  FreeMemory(DDSD)
  *DDS\Release()
  *Sprite\Sprite=*DDS2
  *Sprite\Width=Width
  *Sprite\Height=Height
  *Sprite\RealWidth=Width
  *Sprite\RealHeight=Height
  *Sprite\ClipX=0
  *Sprite\ClipY=0
  ProcedureReturn *DDS2
EndProcedure


;Test:
InitSprite()
InitKeyboard()

OpenScreen(800,600,16,"ResizeSprite()")

CreateSprite(1,128,128)
StartDrawing(SpriteOutput(1))
For M=0 To 500
  Circle(Random(128),Random(128),10,Random($FFFFFF))
Next

DrawingFont(GetStockObject_(#ANSI_VAR_FONT))
DrawText(0,0,"Press enter to quit.",$FEFEFE,$000000)
StopDrawing()


DisplaySprite(1,0,0)

ResizeSprite(1,256,128)
DisplaySprite(1,128,0)

ResizeSprite(1,256,256)
DisplaySprite(1,384,0)

ResizeSprite(1,100,100)
DisplaySprite(1,640,0)

FlipBuffers()

Repeat
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Return)

va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

thanks! i will test it in a few minutes.. first i have to check server updated and talking live with some party guys... check out www.secretly.de cool party releases! check out the "No Copy" video (german) ;)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

@Hroudtwolf:
works fine here... but it would be great, if there is one more parameter... becuase i need to resize the image with doubling pixels and not with interpolation ;) an optional function would be nice ;)

if you can post any example for resizing (also zooming like paint) it would be great! thanks! :)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Post by SoulReaper »

@Hroudtwolf

Great example of how it should be done in Pure Basic using Direct x :)

Regards
Kevin :wink:
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

This source was writen by Stefan.
He is a great Guru of DX-Programming in PureBasic.

There are a lot of examples by him in the forums (german,english and pb-lounge)
Post Reply