2D and 3D

Advanced game related topics
sampb
User
User
Posts: 51
Joined: Tue Feb 12, 2008 8:08 am

2D and 3D

Post by sampb »

Hi all,

Purebasic has built-in 2D commands and support OGRE.
Could we use these 2D commands in 3D engine?
Or, we need to use another set of 2D commands for 3D engine?

Thanks in advance
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

You can use both at the same time, they work together.

That is the reason OGRE PB has not been updated yet, because both 2D and 3D use DX7 and the newer OGRE engine is DX9!

I took the SkyBox.pb example and added some 2d, take a look:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - SkyBox
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; Thanks to Steve 'Sinbad' Streeting for the nice SkyBox !
;

#CameraSpeed = 15

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  Add3DArchive("Data\"          , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    CreateMaterial(0, LoadTexture(0, "r2skin.jpg"))
    CreateEntity(0, LoadMesh(0, "Robot.mesh"), MaterialID(0))
        
    SkyBox("desert07.jpg")

    CreateCamera(0,0,0,100,100)
    CameraLocate(0,0,0,100)
      
    Repeat
      Screen3DEvents()
            
      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()
        MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
      EndIf
      
      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()
      
      ;**** 2d Stuff here after you rendered the 3D world
      StartDrawing(ScreenOutput())
       Circle(50,50,30,$FFFF00)
      StopDrawing()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

if you want 3D on 2D use CameraBackColor(#Camera, -1).

and you can use 2D commands for createTexture

Code: Select all

;-Textures
#Texture = 0
CreateTexture(#Texture, 256, 256)
StartDrawing(TextureOutput(#Texture))
  Box(0, 0, TextureWidth(#Texture), TextureHeight(#Texture), $FFFFFF)
  DrawText(12,12,"Test",#Red)
StopDrawing()
And you can display sprite and 3D.
Please correct my english
http://purebasic.developpez.com/
sampb
User
User
Posts: 51
Joined: Tue Feb 12, 2008 8:08 am

Post by sampb »

@Num3 and Comtois: Does OGRE has its own 2D commands for displaying HUD (Head up display)? Or, I could just use purebasic built-in 2D commands to do HUD?

:)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

sampb wrote:@Num3 and Comtois: Does OGRE has its own 2D commands for displaying HUD (Head up display)? Or, I could just use purebasic built-in 2D commands to do HUD?

:)
Ogre doesn't have 2D commands .
Use purebasic built-in 2D commands to do HUD, it work fine.
You can also use Sprite3D for better effect.

[EDIT]
using example from Num3 , added Sprite3D

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - SkyBox
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; Thanks to Steve 'Sinbad' Streeting for the nice SkyBox !
;

#CameraSpeed = 15

Global ScreenWidth, ScreenHeight
IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  Add3DArchive("Data"          , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
 
  InitSprite()
  InitSprite3D()
  InitKeyboard()
  InitMouse()
 
  If Screen3DRequester()

    CreateMaterial(0,LoadTexture(0, "r2skin.jpg"))
    CreateEntity(0, LoadMesh(0, "Robot.mesh"), MaterialID(0))
       
    SkyBox("desert07.jpg")

    CreateCamera(0,0,0,100,100)
    CameraLocate(0,0,0,100)
    
    CreateSprite(0,ScreenWidth, ScreenHeight,#PB_Sprite_Texture)
    StartDrawing(SpriteOutput(0))
      Box(0,0,ScreenWidth,ScreenHeight,#Blue)
      Circle(ScreenWidth/2,ScreenHeight/2,ScreenHeight/3,#Black)
    StopDrawing()
    CreateSprite3D(0,0)
     
    Repeat
      Screen3DEvents()
           
      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()
        MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
      EndIf
     
      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, 0, KeyY)
     
      RenderWorld()
      Screen3DStats()
     
      ;**** 2d Stuff here after you rendered the 3D world
      Start3D()
        DisplaySprite3D(0,0,0,70)
      Stop3D()
      
     
      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/
sampb
User
User
Posts: 51
Joined: Tue Feb 12, 2008 8:08 am

Post by sampb »

Thank you, Num3 and Comtois.
Post Reply