LB Booster
Programming >> Liberty BASIC language >> Graphics: White on Black
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1430064976

Graphics: White on Black
Post by datwill on Apr 26th, 2015, 4:16pm

I seem to be having this problem where I try to draw white text on a black background. It makes white rectangles and resembles nothing of text at all. Do you know what the problem is?
EDIT: I'm using LBB v.3
EDIT: Here's some example code, trying to keep as best I can to the conditions of the time I found this when I came across it while coding my computer game:

Code:
nomainwin
WindowWidth = DisplayWidth: WindowHeight = DisplayHeight
open "test" for graphics_nf_nsb as #main
#main "trapclose [quit] ; color white ; font geogia italic 10 ; fill black ; home ; down"
#main "\testing text"
wait

[quit]
#main "cls": close #main 

Re: Graphics: White on Black
Post by Richard Russell on Apr 26th, 2015, 4:32pm

on Apr 26th, 2015, 4:16pm, Daniel Atwill wrote:
I seem to be having this problem where I try to draw white text on a black background. It makes white rectangles and resembles nothing of text at all. Do you know what the problem is?

It's impossible even to guess what the problem might be without seeing some code! A trivial example of white text on a black background works OK here:

Code:
    open "Test" for graphics as #w
    #w "backcolor black; color white"
    #w "\\This is some text"
    wait 

It's perhaps worth noting that in LBB (and in LB 4.5 when it is released) you can also create white-on-black text in a texteditor:

Code:
    open "Test" for text as #w
    #w "!backcolor black"
    #w "!forecolor white"
    #w "This is some text"
    wait 

Re: Graphics: White on Black
Post by Richard Russell on Apr 26th, 2015, 5:27pm

on Apr 26th, 2015, 4:16pm, Daniel Atwill wrote:
EDIT: Here's some example code

There's no backcolor command, so you're drawing white-on-white text!

Richard.

Re: Graphics: White on Black
Post by datwill on Apr 26th, 2015, 7:56pm

OH grin grin silly me! rolleyes
Re: Graphics: White on Black
Post by datwill on Apr 26th, 2015, 8:14pm

Thanks for the text thing, but I'm still having trouble. One with the timer statement in LBB, and a scrolling text issue...
OK, I have some code that's directly from my game. What I want to do is make a "poem" (yeah, it's not that good ::) and don't take any notice of it's contents ;D), scroll form bottom to top, beginning off the screen beyond the bottom, all the way off the top. But something's DEFINITELY not right! Here's some edited code from my game, adding a few lines to make it work. This happens once you wish to play the game with the selected file. It waits for 5 seconds (which it is - good) then begins the scrolling, but the poem suddenly appears near the TOP of the screen :-/ I've notice an issue with the timer statement trying to use it in my progammes, it doesn't time right:
Code:
WindowWidth = DisplayWidth: WindowHeight = DisplayHeight
nomainwin: open "test" for graphics_nf_nsb as #main
#main "trapclose [quit] ; cls ; fill black ; backcolor black ; color white ; font georgia italic 10"
timer 5000, [startToScroll] 'This is actually 5 seconds...
wait
[continueAfterTimer]
timer 1, [startToScroll] '... YET THIS IS SUPPOSED TO BE A MILISECOND (not what I will use in the actual game), BUT LOOK AT HOW SLOW IT IS!
originalTextPos = DisplayHeight+751
[startToScroll]
originalTextPos -= 5
#main "cls ; fill black ; place 400 ";originalTextPos
#main "\There was once a guardian,"
#main "place 400 ";originalTextPos+15
#main "\Who was once the best of them all,"
#main "place 400 ";originalTextPos+30
#main "\But his gigantic pride,"
#main "place 400 ";originalTextPos+45
#main "\Lead to his downfall."
#main "place 400 ";originalTextPos+70
#main "\he formed a rebel group of other guardians,"
#main "place 400 ";originalTextPos+85
#main "\About a third of the whole population,"
#main "place 400 ";originalTextPos+100
#main "\Which turned against their Master,"
#main "place 400 ";originalTextPos+115
#main "\The very One which gave them their damnation."
#main "place 400 ";originalTextPos+140
#main "\Although He was angry against His rebel servants,"
#main "place 400 ";originalTextPos+155
#main "\He did not let this blind Him of the true prize,"
#main "place 400 ";originalTextPos+180
#main "\For, after six lights and darks,"
#main "place 400 ";originalTextPos+195
#main "\Once his eyes were opened, he made his rise -"
#main "place 400 ";originalTextPos+220
#main "\From the dust, you awake,"
#main "place 400 ";originalTextPos+235
#main "\To find you're in a flower bed,"
#main "place 400 ";originalTextPos+250
#main "\And what you saw was good, as He proclaimed,"
#main "place 400 ";originalTextPos+265
#main "\So you made a decision, to make the first tred..."
if originalTextPos = -325 then timer 0: goto [afterSequence]
wait

[quit]
#main "cls": close #main: end 

There must be something wrong.
Re: Graphics: White on Black
Post by datwill on Apr 26th, 2015, 8:25pm

I have found a problem, but don't know what's happening undecided

originalTextPos -= 5 'after [startToScroll]

This isn't taking away 5, it's ASSIGNING -5 to the variable! I found this out with the debugger. I tried the extended version:

originalTextPos = originalTextPos - 5

But is still assigning -5 for some reason.
Re: Graphics: White on Black
Post by tsh73 on Apr 26th, 2015, 9:20pm

No, that's all problems in program logic.
Code:
WindowWidth = DisplayWidth: WindowHeight = DisplayHeight
nomainwin: open "test" for graphics_nf_nsb as #main
#main "trapclose [quit] ; cls ; fill black ; backcolor black ; color white ; font georgia italic 10"
timer 5000, [continueAfterTimer]
 'This is actually 5 seconds...
'originalTextPos = DisplayHeight+751 'why?
originalTextPos = DisplayHeight

wait
[continueAfterTimer]
timer 1, [startToScroll] '... YET THIS IS SUPPOSED TO BE A MILISECOND (not what I will use in the actual game), BUT LOOK AT HOW SLOW IT IS!
wait
[startToScroll]
originalTextPos -= 5
#main "cls ; fill black ; place 400 ";originalTextPos
#main "place 40 40" 
#main "\";originalTextPos

#main "place 400 ";originalTextPos
#main "\There was once a guardian,"
#main "place 400 ";originalTextPos+15
#main "\Who was once the best of them all,"
#main "place 400 ";originalTextPos+30
#main "\But his gigantic pride,"
#main "place 400 ";originalTextPos+45
#main "\Lead to his downfall."
#main "place 400 ";originalTextPos+70
#main "\he formed a rebel group of other guardians,"
#main "place 400 ";originalTextPos+85
#main "\About a third of the whole population,"
#main "place 400 ";originalTextPos+100
#main "\Which turned against their Master,"
#main "place 400 ";originalTextPos+115
#main "\The very One which gave them their damnation."
#main "place 400 ";originalTextPos+140
#main "\Although He was angry against His rebel servants,"
#main "place 400 ";originalTextPos+155
#main "\He did not let this blind Him of the true prize,"
#main "place 400 ";originalTextPos+180
#main "\For, after six lights and darks,"
#main "place 400 ";originalTextPos+195
#main "\Once his eyes were opened, he made his rise -"
#main "place 400 ";originalTextPos+220
#main "\From the dust, you awake,"
#main "place 400 ";originalTextPos+235
#main "\To find you're in a flower bed,"
#main "place 400 ";originalTextPos+250
#main "\And what you saw was good, as He proclaimed,"
#main "place 400 ";originalTextPos+265
#main "\So you made a decision, to make the first tred..."
if originalTextPos < -325 then timer 0: goto [afterSequence]
wait

[quit]
#main "cls": close #main: end  


EDIT RE: 1ms
windows might support bigger time chunks. For XP it is 16 ms - it will do 16 even if you ask for 1
Re: Graphics: White on Black
Post by Richard Russell on Apr 26th, 2015, 9:24pm

on Apr 26th, 2015, 8:25pm, Daniel Atwill wrote:
This isn't taking away 5, it's ASSIGNING -5 to the variable! I found this out with the debugger.

I cannot reproduce that. I commented out the NOMAINWIN and added a diagnostic PRINT statement here:

Code:
originalTextPos -= 5
print originalTextPos ' debug 

This is what I get in the mainwin (a new number is printed every 5 seconds as expected):

Code:
-5
-10
-15
-20
-25 

So, here at least, it is definitely subtracting 5, not assigning -5. If you are seeing something different, I do not understand it.

Richard.
Re: Graphics: White on Black
Post by datwill on Apr 27th, 2015, 08:53am

tsh73
I assigned the originalTextPos to be greater than the DisplayHeight because doesn't, with text, the coordinates given relate to the LL corner of the block of text? If this is true, assigning the variable DisplayHeight, the first line will just appear at the bottom of the screen and not scroll on, not really what I want. But it is true that I shouldn't be adding 700 odd (why did I do that? undecided), I only need to add 15. Thank you for pointing that out.
I tried typing 1ms as the amount of time and LBB came up witht a syntax error sad. The time is more like a second...

Richard
That is true that it's taking away 5, but for some reason, after testing my programme out AGAIN after tsh73's advice about the DisplayHeight thing, it STILL comes out as -5. How is
originalTextPos = DisplayHeight+15
the same as
originalTextPos = -5
sad sad sad Me don't get...
Re: Graphics: White on Black
Post by tsh73 on Apr 27th, 2015, 09:02am

Daniel,
my advice was not about "DisplayHeight thing"

Run code from my post.
See how fast ot scrolls.

Pay attention to timer labels - there was error in program flow
(and I think originalTextPos cames as -5 not because it gets assigned, but rather because it wasn't assigned before: so it had value 0, and -=5 just decreased it to -5 (as should)
And it was not assigned again because of wrong program logic: it just never executes line
Code:
originalTextPos = DisplayHeight+751 

)
Re: Graphics: White on Black
Post by Richard Russell on Apr 27th, 2015, 09:51am

While you're making changes, please correct the spelling!

Code:
#main "\Lead to his downfall." 

My three top hates:
You might also want to consider putting the text strings in DATA statements and reading them in a loop, which is more efficient and easier to change (for example if you wanted to alter the line spacing).

Richard.

Re: Graphics: White on Black
Post by datwill on Apr 27th, 2015, 11:03am

Thank you Richard and tsh73, I've figured out that the code flow went to the wrong branch label (skipping the variable declaration so it equalled 0 when i took 5 from it resulting in -5) once the 5 seconds were up! and no wonder it was slow because the timer was 5000ms not 1ms! smiley smiley