Page 1 of 1

ClipSprite3D()

Posted: Mon Sep 19, 2005 11:26 pm
by Joakim Christiansen
That would be quite handy for the isometric tile engine i'm making because it would then support sprite3d, and then I could create nice effects like alphablended walls and stuff...

Posted: Tue Sep 20, 2005 4:03 pm
by Trond
Doesn't the regular ClipSprite affect the Sprite3D derived thereof?

Posted: Tue Sep 20, 2005 5:32 pm
by Joakim Christiansen
Nope, and that's not what I want to do.

Posted: Tue Sep 20, 2005 7:54 pm
by Fou-Lu
But how would that exactly work? Would the sprite be drawn the same way but without the clipped areas or the selected area would become the new texture? :?

Posted: Tue Sep 20, 2005 9:06 pm
by Joakim Christiansen
That's up to Fred to decide if he makes that command.

I just want a ClipSprite() command that works with sprite3d, I don't care how it works.

Posted: Wed Sep 21, 2005 4:53 pm
by S.M.
I wrote such a function, some time ago.

Code: Select all

Structure DDPIXELFORMAT 
  dwSize.l 
  dwFlags.l 
  dwFourCC.l 
  dwRGBBitCount.l 
  dwRBitMask.l 
  dwGBitMask.l 
  dwBBitMask.l 
  dwRGBAlphaBitMask.l 
EndStructure 

Structure DDCOLORKEY 
  dwColorSpaceLowValue.l 
  dwColorSpaceHighValue.l 
EndStructure 

Structure DDSCAPS2 
  dwCaps.l 
  dwCaps2.l 
  dwCaps3.l 
  dwCaps4.l 
EndStructure 

Structure DDSURFACEDESC2 
  dwSize.l 
  dwFlags.l 
  dwHeight.l 
  dwWidth.l 
  lPitch.l 
  dwBackBufferCount.l 
  dwRefreshRate.l 
  dwAlphaBitDepth.l 
  dwReserved.l 
  lpSurface.l 
  ddckCKDestOverlay.DDCOLORKEY 
  ddckCKDestBlt.DDCOLORKEY 
  ddckCKSrcOverlay.DDCOLORKEY 
  ddckCKSrcBlt.DDCOLORKEY 
  ddpfPixelFormat.DDPIXELFORMAT 
  ddsCaps.DDSCAPS2 
  dwTextureStage.l 
EndStructure 

Structure D3DTLVERTEX
  sx.f
  sy.f
  sz.f
  rhw.f
  color.l
  specular.l
  tu.f
  tv.f
EndStructure

Structure PB_Sprite3D
  Texture.IDirectDrawSurface7 ; DirectDrawSurface7
  Vertice.D3DTLVERTEX[4]      ; The 4 vertices for the rectangle sprite
  Width.w			 ; width set with ZoomSprite3D()
  Height.w		 ; height set with ZoomSprite3D()
  unknown.l
EndStructure




Procedure ClipSprite3D(Sprite3D,ClipX,ClipY,ClipWidth,ClipHeight)
  *Sprite3D.PB_Sprite3D=IsSprite3D(Sprite3D)
  
  If *Sprite3D=0:ProcedureReturn 0:EndIf
  *DDS.IDirectDrawSurface7=*Sprite3D\Texture
  
  DDSDESC.DDSURFACEDESC2
  DDSDESC\dwSize=SizeOf(DDSURFACEDESC2)
  Result=*DDS\GetSurfaceDesc(DDSDESC)
  If Result:ProcedureReturn 0:EndIf
  
  *Sprite3D\Vertice[0]\tu=ClipX/DDSDESC\dwWidth
  *Sprite3D\Vertice[0]\tv=ClipY/DDSDESC\dwHeight
  
  *Sprite3D\Vertice[1]\tu=(ClipX+ClipWidth)/DDSDESC\dwWidth
  *Sprite3D\Vertice[1]\tv=ClipY/DDSDESC\dwHeight
  
  *Sprite3D\Vertice[2]\tu=ClipX/DDSDESC\dwWidth
  *Sprite3D\Vertice[2]\tv=(ClipY+ClipHeight)/DDSDESC\dwHeight
  
  *Sprite3D\Vertice[3]\tu=(ClipX+ClipWidth)/DDSDESC\dwWidth
  *Sprite3D\Vertice[3]\tv=(ClipY+ClipHeight)/DDSDESC\dwHeight
  
  ProcedureReturn 1 ; return success
EndProcedure




;Example:
InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(1024,768,32,"Clip sprite3D")

CreateSprite(1,256,256,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
Box(0,0,256,256,#Blue)
Box(0,0,50,50,#Yellow)
Box(50,50,50,50,#Red)
StopDrawing()

CreateSprite3D(1,1)


ClipSprite3D(1,0,0,100,100)

Repeat
  
  ClearScreen(0,0,0)
  
  Start3D()
  
  RotateSprite3D(1,1,1)
  DisplaySprite3D(1,200,200)
  Stop3D()
  
  FlipBuffers()
  
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape)

Posted: Wed Sep 21, 2005 7:49 pm
by Joakim Christiansen
Thank you S.M! :D
I hope it's very fast, because I have to use it for every tile i display.
EDIT:
It messed up the graphix... weird... :cry:

Posted: Sat Aug 25, 2007 10:02 pm
by Fluid Byte
* BUMP *

@S.M.:
Is it safe to clip a Sprite3D to a non-proportional size? E.g. like 120x177 or has to be in 2^N format?
Joakim Christiansen wrote:EDIT:
It messed up the graphix... weird... :cry:
I think your you refering to the aspect ratio. The sprite will be clipped with this code but it gets sized to. After you clipped a sprite you need to use zoomSprite3D() using the same dimensions you used when clipping it. At least if you want a pixel-perfect display.

Posted: Fri Mar 06, 2009 2:09 am
by Fluid Byte
How much I need to pay to Fantaisie Software to implement this command which 100% compatible with DirectX7 and the DirectX9 subsystem ASAP?

Don't think I'm kidding here, I mean business. This command is so essential to game development like the air to breath and I'm puzzled it's still not implemented after all these years.

Posted: Fri Mar 06, 2009 2:36 am
by Kaeru Gaman
to be honest, I would prefer a natively set for the U/V coordinates.
"Clip" is a very special use of this, only horizontal/vertical sides.
setting of U/V bears much more possibilities.

Posted: Fri Mar 06, 2009 6:18 pm
by Fluid Byte
I don't care how it's called or implemented. I just want this feature to be added natively ASAP and I am willing to pay for it.

Re: ClipSprite3D()

Posted: Fri Jul 29, 2011 9:28 am
by DoubleDutch
ClipSprite3D is needed for all formats to make game programming easier (and the drawing faster). It can be done from code on the forum for DirectX - but can it be done for OpenGl (Mac/Linux)?

Also, the DirectX starup needs to be modified so that the back of a texture is displayed - so you can do h and v flips - if possible this should be done on OpenGl too (for Mac/Linux).

Hopefully the ability to set the sprite3D drawing destination buffer will come back (drawing a texture to a texture) - this way we can create some nice effects.

In general the Sprite3D library needs beefing up so you don't have to go to Ogre to get these abilities.