Page 1 of 2
Mixing 2d Sprites and 3D
Posted: Sun Oct 05, 2008 11:12 am
by adshead
I notice in the latest beta this apparently is now possible?. I am working on a 2D platform game using 2D sprites and would like to make use of the particle functionality already built into Purebasic 3d Engine alongside my 2d Sprites.
Is this possible?
Posted: Tue Oct 07, 2008 10:36 am
by Comtois
yes, it is possible
i changed few lines in the particle.pb example
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - Particle
;
; (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;
#CameraSpeed = 10
IncludeFile "Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
Add3DArchive("Data", #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
CreateSprite(0,64,64)
StartDrawing(SpriteOutput(0))
;Box(0,0,64,64,#Blue)
Circle(32,32,30,#Red)
StopDrawing()
LoadTexture(0, "flare.png")
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, 1)
MaterialBlendingMode (0, #PB_Material_Add)
CreateParticleEmitter(0, 10, 1, 1, 0)
ParticleMaterial (0, MaterialID(0))
ParticleTimeToLive (0, 2, 2)
ParticleEmissionRate(0, 20)
ParticleSize (0, 30, 30)
ParticleColorRange (0, RGB(255,0,0), RGB(255,0,255))
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0,-1)
CameraLocate(0,0,0,100)
Repeat
Screen3DEvents()
ClearScreen(RGB(0, 0, 0))
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
InputEvent3D(MouseX(), MouseY(), MouseButton(1), "")
PointPick(0,MouseX()+32,MouseY()+32)
MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
EndIf
;RotateCamera(0, MouseY, MouseX, RollZ, #PB_Relative)
;MoveCamera (0, KeyX, 0, KeyY)
ParticleEmitterLocate(0,CameraX(0)+PickX()*100,CameraY(0)+PickY()*100,CameraZ(0)+PickZ()*100)
RenderWorld()
Screen3DStats()
DisplayTransparentSprite(0,MouseX(),MouseY())
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Posted: Tue Oct 07, 2008 10:47 am
by IceSoft
Works not here.
Posted: Tue Oct 07, 2008 12:39 pm
by Fred
You need to use DX9 subsystem.
Posted: Tue Oct 07, 2008 12:46 pm
by djes
This example does not work here.
With directx9 subsystem, in windowed, the 3d seems to be behind a black screen, where's some random transparent pixels (and sometime a big part of the screen) are permitting to see the flares. By removing CameraBackColor(0,-1) it's ok.
In fullscreen, the program is hanging on createsprite(0, 64, 64) (invalid memory access) and we can't come back to the desktop :/
With directx7, the program is hanging on StartDrawing(SpriteOutput(0)) (specified sprite is not initialised), even with changing parameters of createsprite().
Posted: Tue Oct 07, 2008 12:57 pm
by Comtois
Well, i use subsystem directx9, and windowed mode (800x600).
I can see a sprite (red circle) and particle behind the sprite.
does original particle.pb example work, using directx9 for you ?
Posted: Tue Oct 07, 2008 12:59 pm
by djes
Comtois wrote:Well, i use subsystem directx9, and windowed mode (800x600).
I can see a sprite (red circle) and particle behind the sprite.
does original particle.pb example work, using directx9 for you ?
Yes, and even in fullscreen.
Posted: Tue Oct 07, 2008 1:21 pm
by Fred
djes wrote:With directx7, the program is hanging on StartDrawing(SpriteOutput(0)) (specified sprite is not initialised), even with changing parameters of createsprite().
DX7 isn't supported with 3d-2d mixing.
Posted: Tue Oct 07, 2008 1:22 pm
by Comtois
i get this, and particle follow the sprite.

Posted: Tue Oct 07, 2008 1:29 pm
by djes
Here's mine

You see the little dots and the fx behind.
Posted: Tue Oct 07, 2008 1:51 pm
by Fred
CameraBackgroundColor() with -1 parameter isn't useful anymore as you can't put anything behind the 3d scene. It's now removed.
Posted: Tue Oct 07, 2008 2:13 pm
by djes
Fred wrote:CameraBackgroundColor() with -1 parameter isn't useful anymore as you can't put anything behind the 3d scene. It's now removed.
Ok! Anyway, it still doesn't work in fullscreen, even without CameraBackgroundColor()
Posted: Tue Oct 07, 2008 9:19 pm
by netmaestro
Works beautifully here in windowed mode but causes an IMA at CreateSprite(0,64,64) in fullscreen. PB 4.3(x86) and DX9, latest beta Sprite lib from purebasic.com/beta/
Posted: Wed Oct 08, 2008 4:42 am
by Mistrel
Is it any slower to draw using 2D commands on the 3D screen than it would be to use actual 3D sprites?
Posted: Thu Oct 09, 2008 11:05 am
by THCM
Seems to work here. I'll get about 2100 fps.