DisplaySprite3D and clipping

Advanced game related topics
andreyu
User
User
Posts: 16
Joined: Sun Oct 01, 2006 7:12 pm
Location: Belarus
Contact:

DisplaySprite3D and clipping

Post by andreyu »

How to make clip for CreateSprite3D? I wish to place many fragments on one texture (animation for one object on one texture, for example) because texture switching is slow.
Regards, _Andrey_
http://www.wegroup.org
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Thanx to Dr. Dri ;)

Code: Select all

Structure D3DVIEWPORT7
  dwX.l
  dwY.l
  dwWidth.l
  dwHeight.l
  dvMinZ.f
  dvMaxZ.f
EndStructure

ProcedureDLL.l ScreenWidth()
  !extrn _PB_Screen_Width
  !MOV   eax, [_PB_Screen_Width]
  ProcedureReturn
EndProcedure

ProcedureDLL.l ScreenHeight()
  !extrn _PB_Screen_Height
  !MOV   eax, [_PB_Screen_Height]
  ProcedureReturn
EndProcedure

ProcedureDLL.l ScreenDepth()
  !extrn _PB_Screen_Depth
  !MOV   eax, [_PB_Screen_Depth]
  ProcedureReturn
EndProcedure

ProcedureDLL.l ClipScreen3D()
  Protected Clip.l, *ViewPort.D3DVIEWPORT7
  Protected Sprite3DDevice.IDirect3DDevice7
 
  !extrn _PB_Direct3D_Device
  !MOV eax, dword [_PB_Direct3D_Device]
  !MOV dword [p.v_Sprite3DDevice], eax
 
  !extrn _PB_3DViewPort
  !MOV dword [p.p_ViewPort], _PB_3DViewPort
 
  *ViewPort\dwX = 0
  *ViewPort\dwY = 0
  *ViewPort\dwWidth  = ScreenWidth()
  *ViewPort\dwHeight = ScreenHeight()
  *ViewPort\dvMinZ = 0.0
  *ViewPort\dvMaxZ = 1.0
 
  If Sprite3DDevice\SetViewport(*ViewPort) = #S_OK
    Clip = #True
  EndIf
 
  ProcedureReturn Clip
EndProcedure

ProcedureDLL.l ClipScreen3D2(x.l, y.l, Width.l, Height.l)
  Protected Clip.l, *ViewPort.D3DVIEWPORT7
  Protected Sprite3DDevice.IDirect3DDevice7
 
  !MOV eax, dword [_PB_Direct3D_Device]
  !MOV dword [p.v_Sprite3DDevice], eax
 
  !MOV dword [p.p_ViewPort], _PB_3DViewPort
 
  *ViewPort\dwX = x
  *ViewPort\dwY = y
  *ViewPort\dwWidth  = Width
  *ViewPort\dwHeight = Height
  *ViewPort\dvMinZ = 0.0
  *ViewPort\dvMaxZ = 1.0
 
  If Sprite3DDevice\SetViewport(*ViewPort) = #S_OK
    Clip = #True
  EndIf
 
  ProcedureReturn Clip
EndProcedure

ProcedureDLL.l ClipScreen3D3(x.l, y.l, Width.l, Height.l, MinZ.f, MaxZ.f)
  Protected Clip.l, *ViewPort.D3DVIEWPORT7
  Protected Sprite3DDevice.IDirect3DDevice7
 
  !MOV eax, dword [_PB_Direct3D_Device]
  !MOV dword [p.v_Sprite3DDevice], eax
 
  !MOV dword [p.p_ViewPort], _PB_3DViewPort
 
  *ViewPort\dwX = x
  *ViewPort\dwY = y
  *ViewPort\dwWidth  = Width
  *ViewPort\dwHeight = Height
  *ViewPort\dvMinZ = MinZ
  *ViewPort\dvMaxZ = MaxZ
 
  If Sprite3DDevice\SetViewport(*ViewPort) = #S_OK
    Clip = #True
  EndIf
 
  ProcedureReturn Clip
EndProcedure

InitSprite()
InitSprite3D()

OpenWindow(0, 0, 0, 640, 480, "ClipScreen3D")
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)

CreateSprite(0, 128, 128, #PB_Sprite_Texture)
If StartDrawing( SpriteOutput(0) )
  Box(0, 0, 128, 128, #Green)
  Circle(64, 64, 64, #Red)
  StopDrawing()
EndIf

CreateSprite3D(0, 0)

If Start3D()
 
  ;ClipScreen3D2(0, 0, 100, 100)
 
  DisplaySprite3D(0, 50, 50)
 
  Stop3D()
EndIf

FlipBuffers()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
andreyu
User
User
Posts: 16
Joined: Sun Oct 01, 2006 7:12 pm
Location: Belarus
Contact:

Post by andreyu »

djes wrote:Thanx to Dr. Dri ;)
This is not good for me because this code utilize DirectX. I need cross-platform solution.
Regards, _Andrey_
http://www.wegroup.org
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Bad news...

Sprite3d is windows only.. Because it's DX based...
White Eagle
Enthusiast
Enthusiast
Posts: 215
Joined: Sun Jan 04, 2004 3:38 am
Location: Maryland

Post by White Eagle »

Sprite3d is windows only.. Because it's DX based...
Correct me if I am wrong, but isn't that only true if you are using DX. With 4.0, if you are using the OpenGL subsystem, doesn't Sprite3D use OpenGL and won't it be cross-platform as soon as the Linux & Mac versions of 4.0 appear?
andreyu
User
User
Posts: 16
Joined: Sun Oct 01, 2006 7:12 pm
Location: Belarus
Contact:

Post by andreyu »

White Eagle wrote:
Sprite3d is windows only.. Because it's DX based...
Correct me if I am wrong, but isn't that only true if you are using DX. With 4.0, if you are using the OpenGL subsystem, doesn't Sprite3D use OpenGL and won't it be cross-platform as soon as the Linux & Mac versions of 4.0 appear?
As i know linux version should support Sprite3D in future. But linux does not support DirectX.
Regards, _Andrey_
http://www.wegroup.org
andreyu
User
User
Posts: 16
Joined: Sun Oct 01, 2006 7:12 pm
Location: Belarus
Contact:

Post by andreyu »

Fred, may be you can help me? Or, may be, you plan to add this functionality?
Regards, _Andrey_
http://www.wegroup.org
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Num3 wrote:Bad news...

Sprite3d is windows only...

not anymore, enter 4.x on Tux... ;)
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply