It is currently Fri May 24, 2013 12:12 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Mixing 2d Sprites and 3D
PostPosted: Sun Oct 05, 2008 11:12 am 
Offline
User
User

Joined: Thu Jan 03, 2008 3:06 pm
Posts: 14
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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 10:36 am 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
yes, it is possible

i changed few lines in the particle.pb example
Code:
;
; ------------------------------------------------------------
;
;   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

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 10:47 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 8:51 am
Posts: 1299
Location: Germany: 49º 45' 21.96" N 10º 38' 4.04" E
Works not here.

_________________
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
http://chipmunk4purebasic.freeforums.org/index.php


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 12:39 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 8876
Location: France
You need to use DX9 subsystem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 12:46 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1334
Location: Pas-de-Calais, France
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().

_________________
The Shooting Crew ~> http://www.shootingcrew.com/
Bobble Puzzle, Purebreaker 3 ~> http://djes.free.fr


Last edited by djes on Tue Oct 07, 2008 12:57 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 12:57 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
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 ?

_________________
Please correct my english
http://purebasic.developpez.com/


Last edited by Comtois on Tue Oct 07, 2008 12:59 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 12:59 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1334
Location: Pas-de-Calais, France
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.

_________________
The Shooting Crew ~> http://www.shootingcrew.com/
Bobble Puzzle, Purebreaker 3 ~> http://djes.free.fr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 1:21 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 8876
Location: France
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 1:22 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
i get this, and particle follow the sprite.

Image

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 1:29 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1334
Location: Pas-de-Calais, France
Here's mine Image
You see the little dots and the fx behind.

_________________
The Shooting Crew ~> http://www.shootingcrew.com/
Bobble Puzzle, Purebreaker 3 ~> http://djes.free.fr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 1:51 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 8876
Location: France
CameraBackgroundColor() with -1 parameter isn't useful anymore as you can't put anything behind the 3d scene. It's now removed.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 2:13 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1334
Location: Pas-de-Calais, France
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()

_________________
The Shooting Crew ~> http://www.shootingcrew.com/
Bobble Puzzle, Purebreaker 3 ~> http://djes.free.fr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 9:19 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
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/

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2008 4:42 am 
Offline
Addict
Addict
User avatar

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 2704
Is it any slower to draw using 2D commands on the 3D screen than it would be to use actual 3D sprites?

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 11:05 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:06 pm
Posts: 255
Location: Gummersbach - Germany
Seems to work here. I'll get about 2100 fps.

_________________
The Human Code Machine / Masters' Design Group


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye