Page 1 of 1

ClearScreen doesn't work with Engine3D?

Posted: Sat Oct 22, 2011 5:05 pm
by kenmo
OK I'll admit, all the improvements to the 3D library lately are giving me some ideas for 3D games again... 8)

I was playing with the idea of splitscreen / multiple cameras, and I noticed ClearScreen() was having no effect in a loop that uses the Engine3D.

This screenshot is from the BillboardGrass.pb demo, in which ClearScreen(RGB(0,0,0)) is used:

Image

I made these camera modifications (although it has the same problem with just one camera):

Code: Select all

    ; create camera
    CreateCamera(0, 0, 0, 50, 50)
      CameraLocate(0, 200, 400, 900)
      CameraLookAt(0, 0, 100, 0)
    CreateCamera(1, 50, 50, 100, 100)
      CameraLocate(1, 200, 400, 900)
      CameraLookAt(1, 0, 100, 0)
Happens for me in both Windowed and Fullscreen, XP Pro, default subsystem and OpenGL.

EDIT: There seems to be a few ClearScreen() bugs reported, many of them fixed, but this seems specific to InitEngine3D().

Re: [4.60 RC2] ClearScreen doesn't work with Engine3D?

Posted: Wed Mar 12, 2014 10:45 am
by Fred
Could you post a small snippet showing the issue ?

Re: [4.60 RC2] ClearScreen doesn't work with Engine3D?

Posted: Wed Mar 12, 2014 11:18 am
by Samuel
Should ClearScreen(Color) even be used with the 3D engine? You can't exactly erase an entity with it. The 3D engine will just continue to draw it until you free or hide the entity.
Maybe there is a good reason to use it in the 3D world, but at the moment I can't think of one.

Re: [4.60 RC2] ClearScreen doesn't work with Engine3D?

Posted: Wed Mar 12, 2014 11:29 am
by Fred
True, CameraBackground() should be used instead.

Re: [4.60 RC2] ClearScreen doesn't work with Engine3D?

Posted: Wed Mar 12, 2014 9:47 pm
by kenmo
Hello Fred + Samuel,

You are right that ClearScreen doesn't make sense if a Camera is filling the whole screen.

But what if it doesn't fill the whole screen? The help file says:
If a camera is created with a height of 50% then it will always fill 50% of the height of the screen, irrespective of whether you use a screen which is 640*480 or 1600*1200.
It also says:
Once the RenderWorld() function has been performed, it's possible to use regular 2D functions like DisplaySprite() to display 2D sprites over the 3D world.
What if you want to render small screens (like a multi-player console game) but also draw a GUI using 2D sprites? ClearScreen doesn't seem to work if Engine3D is used... example:

Code: Select all

; Create windowed screen
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))

; Create two cameras
CreateCamera(0, 0, 0, 50, 50)
CameraBackColor(0, $FF0000)
CreateCamera(1, 50, 50, 50, 50)
CameraBackColor(1, $0000FF)

; Create 2D sprite
CreateSprite(0, 32, 32)
If (StartDrawing(SpriteOutput(0)))
  Box(0, 0, OutputWidth(), OutputHeight(), $00FF00)
  Box(OutputWidth()/4, OutputWidth()/4, OutputWidth()/2, OutputHeight()/2, $FF00FF)
  StopDrawing()
EndIf

Repeat
  Event = WindowEvent()
  While (Event)
    If (Event = #PB_Event_CloseWindow)
      Done = #True
    EndIf
    Event = WindowEvent()
  Wend
  
  ; ClearScreen doesn't do anything here
  ClearScreen($FFFFFF)
  
  RenderWorld()
  
  ; doesn't do anything here either
  ClearScreen($FFFFFF)
  
  ; we can draw sprites around the cameras, but not clear them
  DisplaySprite(0, 320 + Cos(ElapsedMilliseconds()/777)*160 - 16, 240 + Sin(ElapsedMilliseconds()/1000)*120 - 16)
  
  ; one more try, doesn't clear the sprite
  ClearScreen($FFFFFF)
  
  FlipBuffers()
Until Done
With PB 5.21 LTS on Windows 7 I see a moving green sprite on a black background, but it never gets erased by any of the white ClearScreen calls.


Thanks for asking about this!

Re: [4.60 RC2] ClearScreen doesn't work with Engine3D?

Posted: Wed Mar 12, 2014 11:34 pm
by Samuel
I'm assuming this is related the the whole don't use ScreenOutput() with the 3D engine thing.
The 3D engine must somehow conflict with it. My guess is they are separate rendering systems both trying to use the same screen.
Which would be a bit of a no no.

To fix this you can create a camera that covers the entire rendering screen.
Then create your other two cameras on top of it.

Like this.

Code: Select all

; Create windowed screen
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))

; Create three cameras
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, $FFFFFF)
CreateCamera(1, 0, 0, 50, 50)
CameraBackColor(1, $FF0000)
CreateCamera(2, 50, 50, 50, 50)
CameraBackColor(2, $0000FF)

; Create 2D sprite
CreateSprite(0, 32, 32)
If (StartDrawing(SpriteOutput(0)))
  Box(0, 0, OutputWidth(), OutputHeight(), $00FF00)
  Box(OutputWidth()/4, OutputWidth()/4, OutputWidth()/2, OutputHeight()/2, $FF00FF)
  StopDrawing()
EndIf

Repeat
  Event = WindowEvent()
  While (Event)
    If (Event = #PB_Event_CloseWindow)
      Done = #True
    EndIf
    Event = WindowEvent()
  Wend
 
  RenderWorld()
  DisplaySprite(0, 320 + Cos(ElapsedMilliseconds()/777)*160 - 16, 240 + Sin(ElapsedMilliseconds()/1000)*120 - 16)
  FlipBuffers()
Until Done