Fbgfx , not erase txt console when closing graphic mode

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Fbgfx , not erase txt console when closing graphic mode

Post by marpon »

I've just found an interresting feature

I wanted to have the txt console and the graphic console active at the same time
i noticed when closing the graphic mode using the normal screen 0 command
the txt console was cleared , it was not what i wanted , because i used the txt console to collect info
before opening the graphic mode and wanted to be able to see that info after closing the graphic mode.


so i tried to avoid the txt suppression, and after looking the .c source of fbgfx ,
i've found a flag for the function fb_GfxScreen (screen in freebasic)
SCREEN_EXIT (wich is a define to value &h80000000)

if we use that value on screen 0 , 0 , 0 , &h80000000

the previous content of txt console is preserved.....

i"ve tested it on win xp (32) win vista (32) win 10 (32/64)

hope it will help some of you

test to reproduce

Code: Select all

'test_fbgfx.bas

'  compile with -s console flag  to verify


#include "fbgfx.bi"

function test_fbgfx()as long
	dim as string c
	Screen 11 , 32 , 4 
	do
		screenlock	
		' Prints "Hello World!" in the middle of the screen
		Locate 15 , 14
		Print "Escape key or close window to stop graphic mode"
		screenunlock
		Sleep 1 , 1
		c = inkey
		if c = chr(255) + "k" THEN exit do
	Loop while c <> chr(27)
	'SCREEN 0                                      'will erase the previous text console
	SCREEN 0, 0, 0, &h80000000                     'will keep the previous text console
	return 1
END FUNCTION





   print : Print "Before test graphic mode!" : print
	test_fbgfx()
	print : Print "After test graphic mode!" : print
	
	print "   Press any key to quit"
	Sleep

dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Fbgfx , not erase txt console when closing graphic mode

Post by dodicat »

Nice find.
The console is preserved (Vertical scroll also)
Win 10
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Re: Fbgfx , not erase txt console when closing graphic mode

Post by mrminecrafttnt »

"open cons" is working - nice for debugging :)
Example:

Code: Select all

'test_fbgfx.bas

'  compile with -s console flag  to verify


#include "fbgfx.bi"

dim shared as integer exitmode

sub t_counter
    dim as integer t
    do
        print #1,"SCREEN OPEN FOR ";STR(T);" Sec.."
        if T = 10 then
            print #1,"EASTEREGG FOUND - CHANGING COLOR :)"
            shell "color F0"
        end if
        
        sleep 1000,1
        t+=1
    loop until exitmode = 1
    print #1,"ESC PRESSED, PLEASE WAIT.."
end sub

function test_fbgfx()as long
   open cons for output as #1
   threadcall t_counter
   dim as string c
   dim as integer w,h,col
   print "Opening screen.."
   Screenres 640,480
   screeninfo w,h
      if w > 0 and h > 0 then 
          print #1,"SCREEN OPENED - Resulution is :";STR(W);"x";STR(H)
      else
          print #1,"SCREEN OPENING FAILED. OOPS!"
            
      end if
      
   do
      screenlock   
      ' Prints "Hello World!" in the middle of the screen
      Locate 15 , 14
      color col
      Print "Escape key or close window to stop graphic mode"
      
      screenunlock
      c = inkey
      if c = chr(255) + "k" THEN exitmode = 1:exit do
      
      Sleep 15 , 1
      col+=1

   Loop while c <> chr(27)
   'SCREEN 0                                      'will erase the previous text console
   SCREEN 0, 0, 0, &h80000000                     'will keep the previous text console
   close #1
   return 1
END FUNCTION





   print : Print "Before test graphic mode!" : print
   test_fbgfx()
   print : Print "After test graphic mode!" : print
   
   
   print "   Press any key to quit"
   Sleep
   end
Post Reply