opening a console window in freebasic is easy.
but the only way i know of is to use the windows api. its the same process in fb/c++.
here is my ascii windows frame work.
#Include "windows.bi"
#include "win\mmsystem.bi"
#Include "crt.bi"
Type AsciiWindow
Origin As COORD
Dimensions As SMALL_RECT
CHwnd As HANDLE
Size As COORD
WndPtr As CHAR_INFO Ptr
End Type
Const Black = 0
Const Blue = 1
Const Green = 2
Const Cyan = 3
Const Red = 4
Const Magenta = 5
Const Brown = 6
Const White = 7
Const Grey = 8
Const BBlue = 9
Const BGreen = 10
Const BCyan = 11
Const BRed = 12
Const Pink = 13
Const Yellow = 14
Const BWhite = 15
Declare Sub FlipAsciiBuffers( Buffer As AsciiWindow Ptr )
Declare Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
Declare Sub KillAsciiWindow( AscWindow As AsciiWindow Ptr )
Declare Function SetUpAsciiWindow( ByVal X As Integer = 0 , ByVal Y As Integer = 0 , Byval Wdth As Integer = 80 , ByVal Hght As Integer = 50 ) As AsciiWindow Ptr
Declare Function AsRgb( ByVal FCol As Integer , ByVal BCol As Integer )
Declare Function GetFRgb( Buffer As WORD ) As Ubyte
Declare Function GetBRgb( Buffer As WORD ) As Integer
Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
Dim As Integer Y
For Y = 0 To (Buffer->Size.X) * (Buffer->Size.Y)
Buffer->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
Buffer->WndPtr[Y].Attributes = AsRgb( Black , Black )
Next
End Sub
Sub FlipAsciiBuffers( Buffer As AsciiWindow Ptr )
WriteConsoleOutput( Buffer->CHwnd , Buffer->WndPtr , Buffer->Size , Buffer->Origin , @Buffer->Dimensions )
End Sub
Function AsRgb( ByVal FCol As Integer , ByVal BCol As Integer )
Return FCol + ( BCol Shl 4 )
End Function
Function GetFRgb( Buffer As WORD ) As Ubyte
Return Buffer and &H0f
End Function
Function GetBRgb( Buffer As WORD ) As Integer
Return Buffer shr 4
End Function
Function SetUpAsciiWindow( ByVal X As Integer = 0 ,ByVal Y As Integer = 0 , Byval Wdth As Integer = 80 , ByVal Hght As Integer = 50 ) As AsciiWindow Ptr
Dim As AsciiWindow Ptr TmpWindow
TmpWindow = CAllocate( SizeOf( AsciiWindow ) )
TmpWindow->WndPtr = CAllocate( Wdth * Hght * Sizeof( AsciiWindow ) )
TmpWindow->Size.X = Wdth
TmpWindow->Size.Y = Hght
TmpWindow->Origin.X = X
TmpWindow->Origin.Y = Y
TmpWindow->Dimensions.Left = 0
TmpWindow->Dimensions.Top = 0
TmpWindow->Dimensions.Right = Wdth - 1
TmpWindow->Dimensions.Bottom = Hght - 1
TmpWindow->CHwnd = CreateConsoleScreenBuffer( GENERIC_WRITE Or GENERIC_READ , 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL)
SetConsoleActiveScreenBuffer( TmpWindow->CHwnd )
SetConsoleScreenBufferSize( TmpWindow->CHwnd, TmpWindow->Size )
SetConsoleWindowInfo( TmpWindow->CHwnd, TRUE, @TmpWindow->Dimensions )
Return TmpWindow
End Function
Sub KillAsciiWindow( AscWindow As AsciiWindow Ptr )
If ( AscWindow ) Then
If ( AscWindow->WndPtr ) Then
Deallocate( AscWindow->WndPtr )
End If
Deallocate( AscWindow )
End If
End Sub
the main point of interest being setupaciiwindow and flip ascii buffers if you rip that stuff out and put the flip ascii buffer in your main loop and setupsciiwindow above your main loop. you will have a perfect console ready for drawing on. this is how pretty much everyone does it regardless of the laungage.
now to draw onto the screen
Buffer->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 ) 'ascii char you want to draw
Buffer->WndPtr[Y].Attributes = AsRgb( Black , Black ) 'forground and background color you want to draw your char
i know my code can be a bit hard too follow as i have my own way of writting it but i can come up with a simple example for you if needed that doesnt use pointers or types to let you see better whats going on.
remeber the transition comp i entered an ascii demo with full source that has conversion routines i know you probably wont want to use any of the code but its more than worth a look you should be able to get some ideas from it
