Initialising 3D changes screen behaviour

Just starting out? Need help? Post your questions and find answers here.
coco2
Enthusiast
Enthusiast
Posts: 472
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Initialising 3D changes screen behaviour

Post by coco2 »

Code: Select all

;InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 256, 256, "Test Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 256, 256)
Repeat
  Event = WindowEvent()
  Delay(1)
  ClearScreen(#Blue)
  FlipBuffers()
Until Event = #PB_Event_CloseWindow

This code shows a blue screen. If you uncomment InitEngine3D() there is no longer a blue screen. Why is the 3D initialise affecting the screen behaviour?
miso
Enthusiast
Enthusiast
Posts: 662
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Initialising 3D changes screen behaviour

Post by miso »

If initengine3d, you will need a camera, a camerabackcolor(color) and a renderworld() before flipbuffers to work. The two modes are not identical.

Also with screens don't:

Code: Select all

 Event = WindowEvent()
instead

Code: Select all

 repeat: until WindowEvent()=0
Or else soon you will backlog tracking for mouse events for example.

miso
coco2
Enthusiast
Enthusiast
Posts: 472
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Initialising 3D changes screen behaviour

Post by coco2 »

I couldn't get that working, can you show me?

Code: Select all

Define Quit.i = 0
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 256, 256, "Test Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 256, 256)
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, #Black)
Repeat
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until Event = 0
  Delay(1)
  RenderWorld()
  ClearScreen(#Blue)
  FlipBuffers()
Until Quit
miso
Enthusiast
Enthusiast
Posts: 662
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Initialising 3D changes screen behaviour

Post by miso »

It was almost perfect. No need for clearscreen though in 3d.

Code: Select all

Define Quit.i = 0
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 256, 256, "Test Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 256, 256)
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, #Blue)
Repeat
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until Event = 0

  RenderWorld()
  FlipBuffers()
  Delay(1)
Until Quit
If you use sprites or the new gui, render and draw them after renderworld() and before flipbuffers().
coco2
Enthusiast
Enthusiast
Posts: 472
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Initialising 3D changes screen behaviour

Post by coco2 »

Ok thanks, I think I know what I need to do now. I'm creating a "retro" 3D game engine where it renders the 3D world, then enlarges it so the pixels are some multiple. ClearScreen() was causing the problem.
miso
Enthusiast
Enthusiast
Posts: 662
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Initialising 3D changes screen behaviour

Post by miso »

You might check bug planet in game section. That pretty much do that with a quad. Looks 2d only because the orthographic camera, it's 3d in reality. Very messy code of mine though...

Or a bigger but clean and modular framework of mine in intro player has a ready to use setup for this in module sys. You just have to remove the pb version check, as it checks explicitly against version pb621 or something.
coco2
Enthusiast
Enthusiast
Posts: 472
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Initialising 3D changes screen behaviour

Post by coco2 »

Fun little game, althought I had to change line 445 to:

Code: Select all

OpenWindowedScreen(WindowID(#MAINWINDOW_H),0,0,WindowWidth(#MAINWINDOW_H)*DesktopResolutionX(),WindowHeight(#MAINWINDOW_H)*DesktopResolutionY(),#AUTOSTRETCH_ON,0,0,#SCREEN_FLAGS)
miso
Enthusiast
Enthusiast
Posts: 662
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Initialising 3D changes screen behaviour

Post by miso »

Oh. What OS do you use? I was sure it's dpi aware the way it is now... Now thats something I need as an information. ;)
coco2
Enthusiast
Enthusiast
Posts: 472
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Initialising 3D changes screen behaviour

Post by coco2 »

I'm using Windows 11 with a ultrawide screen 1.5x scaling.
miso
Enthusiast
Enthusiast
Posts: 662
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Initialising 3D changes screen behaviour

Post by miso »

coco2 wrote: Wed Dec 24, 2025 5:18 am I'm using Windows 11 with a ultrawide screen 1.5x scaling.
Thanks. Maybe we gamemakers should create a topic later in 3d and or in game creation with some simple instructions and codes like in this post, how to start, what to do, what to avoid and why. Without fancy extra additions. There are some pitfalls one can fall...
Post Reply