3D Sprite render with USEBUFFER()

Just starting out? Need help? Post your questions and find answers here.
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

3D Sprite render with USEBUFFER()

Post by newart »

This no work. (black screen)
Why? :oops:

Code: Select all

UsePNGImageDecoder()

#frate = 60
#scrw = 256                               
#scrh = 256                          
#scrd = 32

InitSprite()
InitKeyboard()
InitSprite3D()

If OpenWindow(0,0,0,#scrw,#scrh,#PB_Window_ScreenCentered|#PB_Window_SystemMenu , "") = 0: End: EndIf
If OpenWindowedScreen(WindowID(),0,0,#scrw,#scrh,0,0,0) = 0: End: EndIf
  
SetFrameRate(#frate) 
Gosub loadsprite

Repeat
FlipBuffers():ExamineKeyboard(): Event = WindowEvent()         

UseBuffer(1)
Start3D()
DisplaySprite3D(0,0,0,255)
Stop3D()
UseBuffer(-1)
DisplaySprite(1,0,0)

Until KeyboardReleased(#PB_Key_Escape) 
End


loadsprite:
LoadSprite(0,"scr.png",#PB_Sprite_Texture)
CreateSprite3D(0,0)
CreateSprite(1,256,256,0)
Return
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Code: Select all

UsePNGImageDecoder()

#frate = 60
#scrw = 256                               
#scrh = 256                         
#scrd = 32

InitSprite()
InitKeyboard()
InitSprite3D()

If OpenWindow(0,0,0,#scrw,#scrh,#PB_Window_ScreenCentered|#PB_Window_SystemMenu , "") = 0: End: EndIf
If OpenWindowedScreen(WindowID(),0,0,#scrw,#scrh,0,0,0) = 0: End: EndIf
 
SetFrameRate(#frate)
Gosub loadsprite

Repeat
FlipBuffers():ExamineKeyboard(): Event = WindowEvent()         

UseBuffer(1)
DisplaySprite(0,0,0)
; Start3D()
; DisplaySprite3D(0,0,0,255)
; Stop3D()
UseBuffer(-1)
DisplaySprite(1,0,0)

Until KeyboardReleased(#PB_Key_Escape) Or Event=#PB_Event_CloseWindow
End


loadsprite:
CreateSprite(0,256,256,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(0))
Box(0,0,256,256,$FFFF)
StopDrawing()
CreateSprite3D(0,0)
CreateSprite(1,256,256,0)
Return
Please correct my english
http://purebasic.developpez.com/
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

Post by newart »

Comtois wrote:

Code: Select all

UseBuffer(1)
DisplaySprite(0,0,0)
; Start3D()
; DisplaySprite3D(0,0,0,255)
; Stop3D()
UseBuffer(-1)
DisplaySprite(1,0,0)
I need only 3D sprite with Rotate, Zoom, ETC.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

I was sure you will say that :)

So, i dont know if it's possible with Sprite3D().
Please correct my english
http://purebasic.developpez.com/
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

Post by newart »

Comtois wrote:I was sure you will say that :)

So, i dont know if it's possible with Sprite3D().
Fred clear please a situation. :o
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

What you try to achieve is not supported for now. You can still use the main buffer and GrabSprite(), it should be fast.
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

Post by newart »

Fred wrote:What you try to achieve is not supported for now. You can still use the main buffer and GrabSprite(), it should be fast.
Thanks!
But I hope in PB 4. X in due course it will be realized.
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post by S.M. »

If you want it a bit easier you could use this:

Code: Select all

;Collision between 3D-Sprites.
;*****************************
;Adapted for PB 4.0

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 PB_Sprite 
  Sprite.l 
  Width.w 
  Height.w 
  Depth.w 
  Mode.w 
  FileName.l 
  RealWidth.w 
  RealHeight.w 
  ClipX.w 
  ClipY.w 
EndStructure 

#DDSD_WIDTH=4 
#DDSD_HEIGHT=2 
#DDSD_CAPS=1 
#DDSCAPS_3DDEVICE=8192 
#DDSCAPS_OFFSCREENPLAIN=64 

Global *D3DDevice.IDirect3DDevice7 
Global *BackBuffer.IDirectDrawSurface7 

Procedure CreateRenderSprite(Sprite,Width,Height) 
  Result=CreateSprite(Sprite,Width,Height) 
  If Result=0:ProcedureReturn 0:EndIf 
  *PBSprite.PB_Sprite=IsSprite(Sprite) 
  *DDS.IDirectDrawSurface7=*PBSprite\Sprite 
  *DDS\GetDDInterface(@*DD.IDirectDraw7) 
  *DDS\Release() 
  DDSD.DDSURFACEDESC2 
  DDSD\dwSize=SizeOf(DDSURFACEDESC2) 
  DDSD\dwFlags=#DDSD_WIDTH|#DDSD_HEIGHT|#DDSD_CAPS 
  DDSD\dwWidth=Width 
  DDSD\dwHeight=Height 
  DDSD\ddsCaps\dwCaps=#DDSCAPS_3DDEVICE|#DDSCAPS_OFFSCREENPLAIN 
  Result=*DD\CreateSurface(DDSD,*PBSprite,0) 
  *DD\Release()  
  If Result:ProcedureReturn 0:EndIf 
  ProcedureReturn *PBSprite\Sprite 
EndProcedure 

Procedure SelectRenderSprite(Sprite) 
  !extrn _PB_Direct3D_Device 
  !MOV Eax,[_PB_Direct3D_Device] 
  !MOV [p_D3DDevice],Eax 
  !extrn _PB_DirectX_BackBuffer 
  !MOV Eax,[_PB_DirectX_BackBuffer] 
  !MOV [p_BackBuffer],Eax 
  *D3DDevice\EndScene() 
  Select Sprite 
    Case -1 
      *D3DDevice\SetRenderTarget(*BackBuffer,2) 
    Default 
      *D3DDevice\SetRenderTarget(PeekL(IsSprite(Sprite)),2) 
  EndSelect 
  *D3DDevice\BeginScene() 
EndProcedure 






;Example: 

InitSprite() 
InitSprite3D() 


InitKeyboard() 
InitMouse() 
SetRefreshRate(60)
OpenScreen(1024,768,16,"Collision detection with 3D-Sprites") 

CreateRenderSprite(0,181,181) 
CreateRenderSprite(1,181,181) 


TransparentSpriteColor(0,#Magenta) 
TransparentSpriteColor(1,#Magenta) 

FontID=LoadFont(1,"Arial",20)

CreateSprite(5,128,128,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(5))
Ellipse(64,64,64,32,#Blue) 
DrawingMode(1) 
DrawingFont(FontID)
DrawText(10,48,"3D-Sprite",#Yellow) 
StopDrawing()

CreateSprite3D(5,5) 


Repeat 
  ExamineKeyboard() 
  ExamineMouse() 
  
  ClearScreen(#Black) 
  
  UseBuffer(0) 
  ClearScreen(#Magenta);Clear Sprite 0 
  UseBuffer(1) 
  ClearScreen(#Magenta);Clear Sprite 1 
  UseBuffer(-1) 
  
  
  Start3D() 
  
  SelectRenderSprite(0);Draw the 3D-Sprite on Sprite 0 
  Angle1+2 
  RotateSprite3D(5,Angle1,0) 
  DisplaySprite3D(5,27,27) 
  
  
  SelectRenderSprite(1);Draw the 3D-Sprite on Sprite 1 
  Angle2-2 
  RotateSprite3D(5,Angle2,0) 
  DisplaySprite3D(5,27,27) 
  
  SelectRenderSprite(-1);Draw on Backbuffer 
  Stop3D() 
  
  
  DisplayTransparentSprite(0,MouseX(),MouseY()) 
  DisplayTransparentSprite(1,200,100) 
  
  If SpritePixelCollision(0,MouseX(),MouseY(),1,200,100) 
    StartDrawing(ScreenOutput()) 
    DrawingMode(1) 
    DrawingFont(FontID)
    DrawText(0,0,"Collision !",#Yellow) 
    StopDrawing() 
  EndIf 
  
  FlipBuffers() 
  
Until KeyboardPushed(#PB_Key_Escape) 
regards
Stefan
Post Reply