Page 1 of 1

OpenWindowedScreen colour

Posted: Sun Jan 03, 2010 5:53 am
by IdeasVacuum
I thought there would be a simple way to do this: Change the OpenWindowedScreen colour from the default black to another colour of choice (Without disturbing the displayed entities).

I started off trying ClearScreen, for example ClearScreen(RGB($CC,$00,$00))

That does not do anything in terms of the screen colour so I tried a Billboard (Hide/UnHide) as a background. Sort of works but not satisfactory for my purpose. Surely this is a simple requirement.....? Is there a PB command specifically for this task that I have missed?

Re: OpenWindowedScreen colour

Posted: Sun Jan 03, 2010 12:22 pm
by citystate
clearscreen is the correct command, but to see it you need to flip the buffers (using flipbuffers(), strangely enough)

Re: OpenWindowedScreen colour

Posted: Sun Jan 03, 2010 1:15 pm
by Comtois
In 3D use CameraBackColor()

Re: OpenWindowedScreen colour

Posted: Sun Jan 03, 2010 3:45 pm
by blueznl
citystate wrote:clearscreen is the correct command, but to see it you need to flip the buffers (using flipbuffers(), strangely enough)
Why is that strange? You always draw on the hidden screen, which becomes only visibile after a FlipBuffers().

Re: OpenWindowedScreen colour

Posted: Sun Jan 03, 2010 11:23 pm
by citystate
is just my sense of humor - it's "strange" that to flip the buffers, you need to use flipbuffers(), in that it's not strange at all, but is stating the obvious on my part :P

Re: OpenWindowedScreen colour

Posted: Mon Jan 04, 2010 3:33 pm
by IdeasVacuum
Hello chaps

Thanks to everyone for helping, so quickly too. I had to try a lot of permutations before finally getting the desired result. ClearScreen definitely not working with OpenWindowedScreen (for the purpose of changing the screen colour), but I get the impression from the PB sample files that it should be - perhaps a bug this time and not a Newbie oversight?

CameraBackColor does do the job :D but only with supporting code as follows, which I hope will be of use to some other Newbie one day:

Code: Select all

        CameraBackColor(#Camera1, RGB(255, 255, 255))   ; White screen
        RenderWorld()
        FlipBuffers()
        RenderWorld()
        FlipBuffers()

Re: OpenWindowedScreen colour

Posted: Mon Jan 04, 2010 8:10 pm
by IdeasVacuum
....but, tiny issue in that the new screen colour is not applied to the last horizontal line of pixels. Being a Newbie, most problems are home-made of course but my gut feeling says it possibly isn't me this time..... :roll:

Re: OpenWindowedScreen colour

Posted: Mon Jan 04, 2010 9:13 pm
by Comtois
this code work fine

Code: Select all

InitEngine3D() 
InitSprite() 
InitKeyboard()
w = 800
h = 600
OpenWindow(0, 0, 0, w, h, "Test", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, w, h, 0, 0, 0, #PB_Screen_NoSynchronization)

CreateCamera(0, 0, 0, 100, 100)  
CameraBackColor(0, RGB(255,255,255))

Repeat
 	Repeat 
 	  Event = WindowEvent() 
 	  If Event = #PB_Event_CloseWindow
 	    Quit = 1
 	  EndIf  
 	Until Event  

  ExamineKeyboard()
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

Re: OpenWindowedScreen colour

Posted: Mon Jan 04, 2010 10:54 pm
by IdeasVacuum
Hi Comtois

...In my project, the problem manifests when the OpenWindowedScreen is set as re-sizable, it is smaller than the Parent Window (which has a Status Bar) and there is a Mesh Entity displayed. I see the issue when the screen colour is changed on-the-fly.

However, there must be a bug in my code. When my window is displayed, the OpenWindowedScreen is "displayed", but as though it were greyed-out. As soon as an Entity is loaded, the screen is displayed with the correct colour and from then on everything behaves as expected.

If I edit your sample code so that it is more similar to my project, it still works absolutely fine and the screen is displayed correctly from the get-go:

Code: Select all


Global igCurrentColour = 0

Declare ScreenColour()

#Window    = 0
#Camera1   = 1
#Btn          = 2
#StatusBar = 3

InitEngine3D()
InitSprite()
InitKeyboard()
w = 800
h = 600

OpenWindow(#Window, 0, 0, w, h, "Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)

 SetWindowColor(#Window, RGB(185,190,225))
CreateStatusBar(#StatusBar, WindowID(#Window))
   ButtonGadget(#Btn, 10, 10, 100, 24, "Screen Colour")

OpenWindowedScreen(WindowID(#Window), 50, 50, w-100, h-100, 1, 5, 30, #PB_Screen_NoSynchronization)

CreateCamera(#Camera1, 0, 0, 100, 100) 
CameraBackColor(#Camera1, igCurrentColour)
CameraProjectionMode(#Camera1, #PB_Camera_Perspective)
CameraLocate(#Camera1, 0, 0, 300)

Repeat
          Repeat
   
                  Event = WindowEvent()
              iGadgetID = EventGadget()
     
                   If Event = #PB_Event_CloseWindow
                      Quit = 1
       
                   ElseIf Event = #PB_Event_Gadget
                   
                            If iGadgetID = #Btn : ScreenColour() : EndIf
                            
                   EndIf
     
      
          Until Event 

          ExamineKeyboard()
          RenderWorld()
          FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1


Procedure ScreenColour()
;-----------------------

        iNewColour = ColorRequester(igCurrentColour)

        CameraBackColor(#Camera1, iNewColour)
        
        igCurrentColour = iNewColour

EndProcedure
Nothing to worry about but it is "another strange thing".

Re: OpenWindowedScreen colour

Posted: Tue Jan 05, 2010 12:41 am
by IdeasVacuum
....even stranger now because I can't get the fault to re-occur and I haven't changed the code!

Re: OpenWindowedScreen colour

Posted: Tue Jan 05, 2010 12:19 pm
by Kaeru Gaman
one essential mistake:

Code: Select all

Until Event 
your inner loop repeats until an event occurs.

this is the wrong way round:
it needs to repeat until NO event occurs. (read the examples more carefully)
so, change this line to

Code: Select all

Until Event = #Null 
and try again.

plus for the future, please mention in your postings when you use Engine3D.
from your first posts I was getting the impression it's a problem on the WindowedScreen without 3D.

Re: OpenWindowedScreen colour

Posted: Tue Jan 05, 2010 4:44 pm
by IdeasVacuum
Hello Kaeru
Until Event
True, but Comtois just threw the example together to show me that Camera Back Colour does work. There are many things in there that you would not have in your 'real' code. Of course for programming Newbies it could add to their confusion, though the help is pretty adamant about many important issues. What I do find on this forum is that more experienced Users like yourself are very kind with the amount of time you spend helping others. I try to be so too on forums for other languages but the PB forum experts are way ahead of the norm.

Yes, I should have mentioned using Engine3D because program behavior is different when using it :oops: , sorry. Another issue is the expectations of the environment. I'm not coding-up a game, I'm using PB to make some small apps for engineers and designers. I have a ton of CAD-CAM experience for engineering, using pretty hefty applications, so I tend to think in terms of what I can do when programming for them. When programing in C, you do find yourself re-inventing the wheel a bit. PB is much easier, so much is already done for you, but I'm finding I get caught-out sometimes because the PB ease of use triggers a shut-down of my other brain cell :D

Re: OpenWindowedScreen colour

Posted: Tue Jan 05, 2010 5:17 pm
by Kaeru Gaman
if you have a ton of CAD-CAM experience, you should perhaps also check out the other 3D Engines that could be set upon PB (Irrlicht, DreaMotion),
and have a look at NickTheQuick's RealTime Raytracing (it's a work in progress).

what I somethimes thought about was taking PureBasic for creating a script with solid primitives descriptions, and render the Pictures with POVRay.

sure, you also need practicing programming, but these may show you additional ways to obtain different goals.
POVRay is not suitable for realtime, but you can create posters with it, something that would look shitty with some standard D3D rendering.