DirectX9 not working as it should.

Started by Pfaber11, August 17, 2022, 19:07:21

Previous topic - Next topic

Pfaber11

StartDrawing(ScreenOutput())
    DrawText(50,200,"help = " + StrD (EntityZ(1)))
   StopDrawing()


Hello . I use the above code in directx9 and it does not work . If however I run it in OpenGL it works fine but as Terrain does not work with OpenGL at the moment I need to use directx9 . What I really would like to see is OpenGL fully operational . Does anybody know how to do the equivalent of the above code and it work in DirectX9.
Thanks for reading. 
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Naughty Alien

#1
There ya go..


If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't initialize GFX card", 0)
  End
EndIf

If OpenScreen(800, 600, 32, "Pfaber rulez")
  Repeat 
    FlipBuffers()
    StartDrawing(ScreenOutput())
    DrawText(50,200,"YAY !")
    StopDrawing()
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape)   
EndIf

Pfaber11

I should add that DrawText() doesn't work when using Ogre with openscreen and DirectX9.
The answer would be to use OpenGL however at the moment the terrain is not rendering with this.
What I would like is to know how I could do the score using sprites or some other method.
Thanks for reading .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Naughty Alien

..can you post part of code where you initializing OGL and 3Dscreen??

Pfaber11

OK I'll put some code up so you can see what is happening .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

Here it is what I am making is a sort of cheat program similar to a cheat sheet.

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

UsePNGImageDecoder()
UsePNGImageEncoder()

Add3DArchive("3darchive",#PB_3DArchive_FileSystem)


ExamineDesktops()
OpenScreen(DesktopWidth(0),DesktopHeight(0),32,"pf555",#PB_Screen_SmartSynchronization,60)
LoadSprite(4,"sprite4.png")
LoadTexture(3,"paul3.png")

CreateLight(1,RGB(200,200,200),0,1000,0,#PB_Light_Point)
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0,540,0, #PB_Absolute)
    CameraRange(0,0,14000)
    SetupTerrains(LightID(1),8000,#PB_Terrain_Lightmap)
    CreateTerrain(0,1025, 8000,300, 1, "TerrainGroup", "dat")
    AddTerrainTexture(0,  0,8000,"maptext.png","maptext.png")
   
      DefineTerrainTile(0,0,0, "paul3.png", FlipCoordinatesx,FlipCoordinatesy ) 
   
    BuildTerrain(0)     
    SkyBox("box03.png")
   
   


LoadSprite(2,"sprite2.png")
LoadSprite(4,"sprite4.png")

LoadMesh(1,"pfwindow_dae.mesh")
LoadTexture(1,"pfwindowtexture.png")
CreateMaterial(1,TextureID(1))
CreateEntity(1,MeshID(1),MaterialID(1),0,450,0,#PB_Absolute)
ScaleEntity(1,7,7,7)     

RenderWorld()


FlipBuffers()

Repeat
  maincode:
   
     
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_P)
    Goto pf279
    EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
  End
EndIf

jump5:   
; DisplaySprite(7,-360+a,100)
score=score+1
If score>=999999
   score=0
EndIf
RenderWorld()
DisplayTransparentSprite(2,700,200)

ExamineKeyboard()
    If KeyboardPushed(#PB_Key_A)     
        RotateEntity(1,0,1,0,#PB_Relative)
      EndIf
     
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_D)
          RotateEntity(1,0,-1,0,#PB_Relative)
        EndIf
       
     ExamineKeyboard()
    If KeyboardPushed(#PB_Key_W)
      MoveEntity(1,0,0,-4,#PB_Absolute|#PB_Local)
    EndIf
   
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_S)
      MoveEntity(1,0,0,4,#PB_Absolute|#PB_Local)
    EndIf

    If EntityZ(1) < -3800
      MoveEntity(1,EntityX(1),EntityY(1),3800,#PB_Absolute)
    EndIf
    If EntityZ(1) >3800
     
      MoveEntity(1,EntityX(1),EntityY(1),-3800,#PB_Absolute)
    EndIf
    If EntityX(1) < - 3800
      MoveEntity(1,3800,EntityY(1),EntityZ(1),#PB_Absolute)
    EndIf
   
     If EntityX(1) >  3800
      MoveEntity(1,-3800,EntityY(1),EntityZ(1),#PB_Absolute)
    EndIf 
    MoveEntity(1,EntityX(1),400, EntityZ(1),#PB_Absolute)
    CameraFollow(0, EntityID(1),0, EntityY(1)+5, 80, 0.1, 0.1,#True)
   
    StartDrawing(ScreenOutput())
    DrawingMode(#PB_2DDrawing_Transparent )
     DrawText(50,180,"Score = " + Str(score))
    DrawText(50,200,"X = " + Str (EntityX(1)))
    DrawText(50,220,"Y = " + Str (EntityY(1)))
    DrawText(50,240,"Z = " + Str (EntityZ(1)))   
   StopDrawing()
 
FlipBuffers()
ForEver
pf279:
Repeat
RenderWorld()
DisplaySprite(4,0,0)
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_R)
  RenderWorld()
  DisplaySprite(4,1921,1081)
  FlipBuffers()
  Goto maincode
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
  End
  EndIf
ForEver
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

If I comment out startdrawing() through to enddrawing() it does work fine but how do I put my score onto  the screen without using DrawText() .
Thanks for reading .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Coder Apprentice

#7
This has nothing to do with directx9. You can't do ScreenOuput() if you use the 3D engine. You have to render your text on a sprite. Use SpriteOuput()...

This code works with Ogre both with default OpenGL or DirectX9.

 
    InitEngine3D()
    InitSprite()
    InitKeyboard()

    OpenScreen(1366,768,32,"")

    CreateCube(1,2)

    CreateEntity(1,MeshID(1),#PB_Material_None)
    CreateCamera(1,0,0,100,100)
    MoveCamera(1,0,0,-10)
    CreateLight(1,RGB(255,255,255),10,10,1)
    CameraRange(1,1,100)
    CameraBackColor(1,#Blue)

    CameraLookAt(1,0,0,0)

    CreateSprite(1,355,20)
    SpriteQuality(#PB_Sprite_BilinearFiltering)
    ZoomSprite(1,1065,60)
   
     
   Repeat
     
     ExamineKeyboard()
       
      RotateEntity(1,x+2,y+3,z+1,#PB_Relative)

      spritelocation=spritelocation+1
     
      If spritelocation>800
         spritelocation=-60
      EndIf
     
      RenderWorld()
     
      DisplaySprite(1,spritelocation,spritelocation)

      StartDrawing(SpriteOutput(1))
        DrawingMode(#PB_2DDrawing_Default)
        DrawText(5,0,"This is a 2D sprite over the 3D engine render screen! ",RGB(255,255,255))
      StopDrawing()
     
      FlipBuffers()
     
   Until KeyboardPushed(#PB_Key_Escape)


Pfaber11

#8
Hi kris yes I get it now what I did was make a transparent sprite the size of the screen and render on that . There we are job done . The interesting thing is when using OpenGL I don't have to use that method as I can render 2d straight to the screen with no giant sprite or sprite whatsoever. Anyway thanks for your time and enjoy your day. I'm happy using DirectX9 at the moment now it is working ok (probably)
I hope there are no more surprises along the way(probably gonna be a few ) and looking forward to using OpenGL although I don't mind what we have right now . I think if PB can be made available for Android  that would be a good thing and if they can do it for Raspberry pi then I think it can . In fact the more platforms the better . I know about spider basic but it does not do 3D so for me it's a non starter.
   Anyway it's late and happy to be in a position where I can use PureBasic . It's taken me nearly 4 months to get into PB and feel confident that I made the right choice . I sent  the PureBasic people an email wanting to know how long for OpenGL terrain to be fixed , at the time it seemed I  could not use 3d in PureBasic because opengl and directx both had problems . OpenGL  would not render terrain and DirectX9 would not put 2d onto the screen for scores etc.  It is now sorted the DirectX thing anyway I guess we'll just have to wait for OpenGL to be fixed. Long post sorry.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Naughty Alien

#9
QuoteYou can't do ScreenOuput() if you use the 3D engine. You have to render your text on a sprite. Use SpriteOuput()...

..strangely enough, here it seems to work just fine with ScreenOutput()..


If InitEngine3D()=0 Or InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't initialize GFX card", 0)
  End
EndIf

OpenScreen(800,600,32,"TEST")
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,2,-20):CameraBackColor(0,$ff4444)

CreateCube(1,2)

CreateEntity(1,MeshID(1),#PB_Material_None)
CameraLookAt(0,EntityX(1),EntityY(1),EntityZ(1))


Repeat 
  RenderWorld()
  RotateEntity(1,1,1,1,#PB_Relative)
  StartDrawing(ScreenOutput())
   DrawText(10,10,"YAY !")
   StopDrawing()
  FlipBuffers()


  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)   




Coder Apprentice

#10
Pfaber11 I'm glad you sorted it all out.

Oh yes, it's working with OpenGL now, I totally missed that. Thanks for the correction. It was a very well known limitation in PureBasic up until now. If you guys have fast enough GPUs then it might not be obvious but even now that it's working it's quite a performance hog drawing text directly on the 3D screen in PB. I would avoid it if performance is critical.