InfoScreen..

Everything related to 3D programming
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

InfoScreen..

Post by DK_PETER »

Edit:

Code: Select all

;Still room for improvements and lots of ideas to implement.
;Simple gui infoscreen example - Could easily be a button, progressbar etc...
;Click the infoscreen's 'X' button to hide infoscreen and SPACEBAR to show it again
;Click anywhere on the entity to toggle scrolling lines
;A + D to rotate the infoscreen
;Escape key = Exit

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

Structure Vector3D
  x.f
  y.f
  z.f
EndStructure

Structure _Object
  id.i
  ma.i
  ms.i
  tx.i[2] ;Max two textures per entity 
  hide.i
EndStructure

Structure _Gui
  cube._Object
  infoScreen._Object
  sp.i ;Sprite crsr
EndStructure

Declare.i CreateScene()
Declare.i ExamineID(ID.i, *v.vector3D)

Global s._Gui, NewID.i, v.Vector3D, pressed.i = #False

OpenWindow(0, 0, 0, 1024, 768, "Simple GUI texture (rotate A-D) (SPACEBAR-SHOW) (LEFT CLICK - TOGGLE LINES)", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 20)
CreateLight(0, $FFFFFF, -20, -20, 30)

CreateScene()

Repeat
  Repeat : ev = WindowEvent() : Until ev = 0
  ExamineMouse() : ExamineKeyboard()
  If MouseButton(#PB_MouseButton_Left) > 0 And pressed = #False
    If s\infoScreen\hide = #False
      NewID = MouseRayCast(0, MouseX(), MouseY(), #PB_Ignore) 
      If NewID = s\infoScreen\id
        v\x = PickX() : v\y = PickY() : v\z = PickZ()
        ExamineID(NewID, v)
      EndIf
    EndIf 
    pressed = #True
  ElseIf MouseButton(#PB_MouseButton_Left) = 0
    pressed = #False
  EndIf
  If KeyboardReleased(#PB_Key_Space)
    If s\infoScreen\hide = #True
      HideEntity(s\infoScreen\id, #False)
      s\infoScreen\hide = #False
    EndIf
  EndIf
  If KeyboardPushed(#PB_Key_A)
    RotateEntity(s\infoScreen\id, 0, 0, 0.1, #PB_Relative)
  ElseIf KeyboardPushed(#PB_Key_D)
    RotateEntity(s\infoScreen\id, 0, 0, -0.1, #PB_Relative)
  EndIf
  RotateEntity(s\cube\id, 0.1, 0.3, -0.2, #PB_Relative)
  RenderWorld()
  DisplayTransparentSprite(s\sp, MouseX(), MouseY())
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

Procedure.i CreateScene()
  Protected fo.i = LoadFont(#PB_Any, "Arial", 24)
  Protected x.i, y.i, tx.s
  s\sp = CreateSprite(#PB_Any, 20, 20)
  StartDrawing(SpriteOutput(s\sp))
  LineXY(0, 0, 10, 0, $FF6900)
  LineXY(0, 0, 0, 10, $FF6900)
  LineXY(10, 0, 20, 20, $FF6900)
  LineXY(0, 10, 20, 20, $FF6900)
  FillArea(2, 2, $FF6900,$FF6900)
  StopDrawing()
  TransparentSpriteColor(S\sp, 0)
  
  With s\infoScreen
    \ms = CreatePlane(#PB_Any, 15, 8, 1, 1, 1, 1)
    \tx[0] = CreateTexture(#PB_Any, 1024, 1024, "Info")
    StartDrawing(TextureOutput(\tx[0]))
    DrawingFont(FontID(fo))
    RoundBox(0, 0, 950, 90, 5, 5, $B6B6B6)
    RoundBox(954, 0, 70, 90, 5, 5, $9B9B9B)
    RoundBox(0, 100, 1024, 924, 5, 5, $B6B6B6)
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(5, 20, "This is a small text for the GUI.", $111111)
    DrawText(975, 20, "X", $111111)
    Restore Text
    For x = 0 To 10
      Read.s tx
      DrawText(5, 105 + (x*60), tx, $0E0E0E)
    Next x
    StopDrawing()
    \tx[1] = CreateTexture(#PB_Any, 1024, 1024, "InfoLines")
    StartDrawing(TextureOutput(\tx[1]))
    For y = 0 To 1024 Step 16
      Box(0, y, 1024, 2, $888888)
    Next y
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
    MaterialFilteringMode(\ma, #PB_Material_Bilinear)
    MaterialCullingMode(\ma, #PB_Material_NoCulling)
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
    RotateEntity(\id, 90, 0, -180)
    \hide = #False
  EndWith
  
  With s\cube
    \ms = CreateCube(#PB_Any, 1)
    \tx[0] = CreateTexture(#PB_Any, 50, 50, "CubeLines")
    StartDrawing(TextureOutput(\tx[0]))
    DrawingMode(#PB_2DDrawing_Outlined)
    RoundBox(2, 2, 46, 46, 3, 3, $69FE31)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    MaterialFilteringMode(\ma, #PB_Material_Trilinear)
    \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, -50)
    ScaleEntity(\id, 10, 10, 10)
  EndWith
EndProcedure

Procedure.i ExamineID(ID.i, *v.vector3D)
  Protected x.f, y.f
  If ID = s\infoScreen\id
    ConvertWorldToLocalPosition(EntityID(ID), *v\x, *v\y, *v\z) 
    x = (1 - GetX()) * 7.5
    y = (1 - GetZ()) * 4 
    If x > 55.7 And x < 63.6 And y > -11.9 And y < -9  
      If s\infoScreen\hide = #False
        HideEntity(s\infoScreen\id, #True)
        s\infoScreen\hide = #True
      EndIf
    Else
      If CountMaterialLayers(s\infoScreen\ma) > 1
        RemoveMaterialLayer(s\infoScreen\ma)
      Else
        AddMaterialLayer(s\infoScreen\ma, TextureID(s\infoScreen\tx[1]), #PB_Material_Add)
        ScrollMaterial(s\infoScreen\ma, 0, 0.08, #PB_Material_Animated, 1)
      EndIf
    EndIf
  EndIf
EndProcedure

DataSection
  Text:
  Data.s "Your time is limited, so don't waste it living someone else's life."
  Data.s "Don't be trapped by dogma - which is living with the results of"
  Data.s "other people's thinking. Don't let the noise of others' opinions"
  Data.s "drown out your own inner voice. And most important, have the courage"
  Data.s "to follow your heart and intuition."
  Data.s " -Steve Jobs"
  Data.s " "
  Data.s "“It had long since come to my attention that people of accomplishment"
  Data.s "rarely sat back and let things happen to them. "
  Data.s "They went out and happened to things.”"
  Data.s " -Leonardo Da Vinci"
EndDataSection
Last edited by DK_PETER on Thu Jul 05, 2018 8:03 am, edited 2 times in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: InfoScreen..

Post by RSBasic »

The cube is nice. Image
Image
Image
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: InfoScreen..

Post by Comtois »

;This only works if stationary - Vector values changes on entity rotation
Look at example 'ConvertWorldToLocalPosition.pb'
Please correct my english
http://purebasic.developpez.com/
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: InfoScreen..

Post by DK_PETER »

@Comtois
You're right, it had slipped my mind. Thanks for the hint. :)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InfoScreen..

Post by Kwai chang caine »

Very very nice :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: InfoScreen..

Post by djes »

8)
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: InfoScreen..

Post by luis »

Mouse pointer's movements using DisplayTransparentSprite() are erratic and jumpy on my PC.
It's as if 50% of the tracking data from the mouse were lost.
I saw the same in practically every example using PB OGRE, yet everywhere else (games or whatever) my mouse movements are smooth as silk.
Reducing the DPI of the mouse makes the problem less noticeable but it's still present, cursor movement it's not fluid.
I like the style of the cube.

Code: Select all

Data.s "But most important of all, take advantage of your friends if you can"
Data.s "and use their abilities to look good."
Data.s " -Steve Jobs"
https://www.ibtimes.co.uk/steve-wozniak ... nus-267711
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
tft
User
User
Posts: 84
Joined: Mon Dec 29, 2008 9:34 am

Re: InfoScreen..

Post by tft »

Hallo,

On my W10 computer with GFX Titan and 3 monitors the mouse does not work. There are breaks in the movement.
TFT seid 1989
Aktuelles Projekte : Driving School Evergarden
YouTube : Pure Basic to go
FaceBook : Temuçin SourceMagic Games
DISCORD : SourceMagic
W10 , i9 9900K ,32 GB Ram , GTX Titan , 3 Monitore FHD
ARDUINO Freak :-)
Post Reply