Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: ninogenio on February 01, 2008
-
hey folks,
ive never done ascii before and i cant get it right at all.
i tried to make a simple 80*50 bufferd window like so.
Dim shared As String BackBuffer( 80 * 50 )
WIDTH 80, 50
Declare Sub FlipAsciiBuffers()
Declare Sub ClearAsciiBuffers()
While Not Inkey$ = chr(27)
For Y = 1 To 80 * 50
BackBuffer( Y ) = "~"
Next
FlipAsciiBuffers()
ClearAsciiBuffers()
Wend
Sub ClearAsciiBuffers()
For Y = 1 To 80 * 50
BackBuffer( Y ) = Chr( 219 )
Next
End Sub
Sub FlipAsciiBuffers()
Dim As String FrontBuffer
Locate 1,1
For Y = 1 to 80 * 50
FrontBuffer += BackBuffer( Y )
Next
color 1,3
Print FrontBuffer
End Sub
but there is a huge amount of tearing and the colors cant be set for individual cells so im wondering how other folks make ascii stuff.
i know in the windows api there is stuff like this CreateConsoleScreenBuffer but would this give a smooth animation and i still have no idea how to color individual cells any info would be much appreciated as im really curious how this stuff is done.
-
Yeah, under Windows you need to use the Console API otherwise you don't stand a chance.
Attached is the source for my ascii demo which sets that up. It does some other cool things too - it can play a video using the multimedia APIs and colour match it to the limited set of ascii letters/colours I chose.
Jim
-
cool thanks very much jim k+,
ill have a play around and see what i come up with.
-
thanks very much again jim it all works great now im using your setup and blitting code :)
#include "windows.bi"
Const ScreenWidth = 80
Const ScreenHeight = 50
Declare Sub FlipAsciiBuffers()
Declare Sub ClearAsciiBuffers()
Dim Shared As COORD origin = ( 0 , 0 )
Dim Shared As SMALL_RECT di = ( 0 , 0 , SCREENWIDTH - 1 , SCREENHEIGHT - 1 )
Dim Shared As HANDLE outp
Dim Shared As COORD Size = ( SCREENWIDTH , SCREENHEIGHT )
Dim Shared As CONSOLE_FONT_INFO fonti
Dim Shared As CHAR_INFO scr( SCREENWIDTH * SCREENHEIGHT)
outp = CreateConsoleScreenBuffer( GENERIC_WRITE Or GENERIC_READ , 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL)
SetConsoleActiveScreenBuffer( outp )
SetConsoleScreenBufferSize( outp, Size )
While Not Inkey$ = chr(27)
For Y = 1 to 80 * 50
scr(Y).Char.AsciiChar = 219
scr(Y).Attributes = 1+(Rnd(1)*14)
Next
FlipAsciiBuffers()
ClearAsciiBuffers()
Wend
Sub ClearAsciiBuffers()
For Y = 1 To 80 * 50
scr(Y).Char.AsciiChar = 219
scr(Y).Attributes = 0
Next
End Sub
Sub FlipAsciiBuffers()
WriteConsoleOutput(outp, @scr(0), size, origin, @di)
End Sub
-
Check out libcaca (http://libcaca.zoy.org/).
For URYA (http://www.pouet.net/prod.php?which=1869), which I wrote in Turbo Pascal (yuk), I simply drew directly in the segment $b800 . Each character is stored in a WORD. The first BYTE for the color ( in the 4 LSB ) and background color ( in the 4 MSB) , the second BYTE contains the ASCII code of the character.
HTH
-
Check out libcaca (http://libcaca.zoy.org/).
For URYA (http://www.pouet.net/prod.php?which=1869), which I wrote in Turbo Pascal (yuk), I simply drew directly in the segment $b800 . Each character is stored in a WORD. The first BYTE for the color ( in the 4 LSB ) and background color ( in the 4 MSB) , the second BYTE contains the ASCII code of the character.
HTH
I never knew you'd made an ascii demo pO1, and 1996, hehe, 12 years ago doesn't time fly?
hey folks,
ive never done ascii before and i cant get it right at all.
but there is a huge amount of tearing and the colors cant be set for individual cells so im wondering how other folks make ascii stuff.
i know in the windows api there is stuff like this CreateConsoleScreenBuffer but would this give a smooth animation and i still have no idea how to color individual cells any info would be much appreciated as im really curious how this stuff is done.
You know, once you have your console window working properly, there are a few things you can do to make your ascii demo look really cool. Bearing in mind that most ascii demos released today are straight framebuffer - textscreen conversions (this is the easy route but maybe not the best looking), you could analysie the default font to establish a good range of character densities, ie. how many dots make up each letter, this will pay dividends later as in your frame buffer - text screen conversion you'll want to be able to give each cell "weight" according to what you converted there.
If you are going to release it into the demo scene you might want to use the default palette because some purists (not many these days) frown upon ascii demos that use thier own palettes.
here are some really cool textmode demos from tdmc
linky (http://www.taat.fi/tmdc/)
-
@pO1 thats very handy cheers mate!
i will take some time and look at all my possible options but that lib looks rather good.
@shockwave again some handy advice cheers mate!
i was on tmdc till about 4am last night going through all the demos and trying to get a feel for the art.
if i do ascii stuff it will be always in a console window only no double bufferd gfx mode.and when you say standerd pallette mode is that the 0 - 15 colors 0 = black 15 = white?
from what ive seen the code behind the demos isnt that complicated its getting the demos to look good that is the hard part, i think ill start of right at the begining and try to find out what i like the look of best.
-
You can have as many buffers as you want, in memory. It's not like you'll notice a chunk of 80x50x2 byte more or less.
Libcaca is usually provided in the TMDC. And AFAIK it works in 32 bits, then convert that to some ANSI characters with the standard EGA palette and blit to the standard output ( segment b800 )
-
yeah i noticed you can have more than one buffer set up and then its just a case of setting the one you wish to be visable. which could prove handy for a couple of things.
im going to try and steer clear of using any libs although some of the code in the libs looks very usfull so i might use bits out of them. ill need to experiment a bit but what ever i come up with ill post.
-
right ive had a spare half hour so here is my framework for the console window cleaned up a bit.
the reason im posting this is for anyone else to look at/use before i go and add some demo specific stuff.
#include "windows.bi"
Type AsciiWindow
ScreenWidth As Integer
ScreenHeight As Integer
Origin As COORD
Dimensions As SMALL_RECT
CHwnd As HANDLE
Size As COORD
WndPtr As CHAR_INFO Ptr
End Type
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 )
Dim Shared MyTextWnd As AsciiWindow Ptr
MyTextWnd = SetUpAsciiWindow( 0, 0, 80, 50 )
While Not Inkey$ = chr(27)
For Y = 0 to 80 * 50
If Y And 1 Then
MyTextWnd->WndPtr[Y].Char.AsciiChar = cast( CHAR , 40 )
MyTextWnd->WndPtr[Y].Attributes = AsRgb( 1 + ( rnd( 1 ) * 14 ) , 4 )
Else
MyTextWnd->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
MyTextWnd->WndPtr[Y].Attributes = AsRgb( 1 + ( rnd( 1 ) * 14 ) , 1 )
End If
Next
FlipAsciiBuffers( MyTextWnd )
ClearAsciiBuffers( MyTextWnd )
Wend
KillAsciiWindow( MyTextWnd )
Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
For Y = 1 To 80 * 50
Buffer->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
Buffer->WndPtr[Y].Attributes = 0
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 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->ScreenWidth = Wdth
TmpWindow->ScreenHeight = Hght
TmpWindow->WndPtr = CAllocate( TmpWindow->ScreenWidth * TmpWindow->ScreenHeight * Sizeof( AsciiWindow ) )
TmpWindow->Size.X = TmpWindow->ScreenWidth
TmpWindow->Size.Y = TmpWindow->ScreenHeight
TmpWindow->Origin.X = X
TmpWindow->Origin.Y = Y
TmpWindow->Dimensions.Left = 0
TmpWindow->Dimensions.Top = 0
TmpWindow->Dimensions.Right = TmpWindow->ScreenWidth - 1
TmpWindow->Dimensions.Bottom = TmpWindow->ScreenHeight - 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
-
First ascii framework we've had here in Freebasic I think Nino :)
That has to be worth some good karma! It will be great to see what you do with it now.
I tried making some ascii effects myself but they didn't open a proper console window like you, they were just drawn on a regular graphics screen.
-
cheers shockwave.
yeah i saw some of your ascii stuff in the comp that was run, i thought it was really cool and if i manage anything like that ill be well happy.
im really enjoing tinkering so far though and if i come up with anything worth while ill post it up.
-
here is a little update on my progress its just a hedra sphere and my font engine im struggling with the limited colors so any tips you guys could give me would be handy.
i need to know also how it runs on your comp as i had a lot of tearing at first but ive got it running smooth on my system by using system timers and clamping the frame rate at 59.1 but im curious if it will be similarily smooth on other comps.
-
@ninogenio:
wow, very nice and amazing for a first ascii demo! *thumbs up*
i am still looking forward to see more of your ascii demos in the future!
PS:
Just one question... does the scene is something like an included animation or is it/there something realtime (3D cube) ? However, very very nice work! I really like it! *respect*
-
cheers vain!
its all realtime with 3d projection in a double buffered console window.
im glad you like it mate but tbh my colors are really crappy and thats what im working on now trying to make stuff look good with 16 colors.
ill post the source soon its all a bit of a mess atm and im working on alpha blending my hedra sphere.
-
It works well and Im also impressed by the fact you got nice stuff displayed first time.
One thing to work on is that on my computer the ascii window opened with a scrollbar at the side, and I guess thats not what it should do. It means half the demo appeared to be missing from the bottom of the screen. I had to reszie the window by hand.
Taj
-
cheers taj,
that's strange that's one thing that should'nt happen i codded it to open the full 80*50 res. is it vista your on as i may be doing something that it doesn't like.
-
@nino:
Congratz, works very well. Opens here correctly on
Vista!
-
wonder why it opens windowed on taj's system?,
anywho cheers for trying it benny and im glad you like it too. this is just really a test to see if im on the right track with the refresh rate and my colors.
once i get my alpha blending going ill make something worth looking at.
-
Fabulous looking first ascii mate, welldone indeed.
Cheers and all the best,
Clyde.
-
Works fine and smooth here too Nino, great first ascii thing :) Next add plasmas, music, metaballs, raycaster and then enter the next tdmc! :cheers:
-
What shocky says.
-
cheers taj,
that's strange that's one thing that should'nt happen i codded it to open the full 80*50 res. is it vista your on as i may be doing something that it doesn't like.
Actually just XP. Hmmm weird. I also noticed another ascii demo do this recently from northern dragons.
BTW is it legal in an ascii competition to open an ascii window and an opengl window (offscreen). Render to the hidden opengl window, capture the image and display in ascii window? I mean if you did it right, who would know anyway?
-
@taj:
afaik its not legal to use an invisble OGL / DX screen to render scenes, capture and displaying then on the console window. However you need to convert the captured image to ascii and display the ascii text/stuff on the console! I think its legal to render scene directly into an allocated memoryblock (like 80x80 pixel for eaxmple) and converting this pixels to final ascii values/chars you can display now on the console window... so you can precalculate things or doing things in realtime, if the rendered stuff -> ascii converting is fast enough. But at least afaik its not legal to use OGL, DX... just only Console and possible any DLL like bass, fmod to play music.
-
I am not clear on these rules either.
I don't think it would be illegal to do a straight conversion of some rendered framebuffer into an ascii picture, I thought that a lot of ascii demos do this anyway.. Anyway who's to say what api you should use to write a demo with?
-
I don't think it would be illegal to do a straight conversion of some rendered framebuffer into an ascii picture, I thought that a lot of ascii demos do this anyway
From what I can see they nearly all do this. The smarts in these demos come from working out the mapping from the hidden colour buffer to the ascii output.
That demo you linked to recently seemed to use a combination of this technique along with some graphics rendered directly in ascii.
Jim
-
yeah jims right ive looked at some of the demo sources and they draw to a full r g b buffer and then use algos to try and closely match the ascii buffer with the full color buffer.
i dont think its necessary however, i just do all the drawing in the ascii buffer and with some of the stuff im messing around with, anti alias and alpha blending. drawing directly to the ascii buffer can be made to look quite good.
-
yay i finaly got alpha going :)
i had some trouble with the colors and fillers though.
-
Awesome. Glenz Vector ASCII ... very cool.
Exists fine by pressing ESCAPE - crashes when
hitting the CLOSE WINDOW Button though...
-
cheers benny!
yeah the program doesnt like it when you hit the exit button so escape is prefered, not quite sure how to get around that.
-
Very nice nino, for what its worth that exit error is typical of DOS text mode consoles such as mode 3h. Are you using DOS or win32? Cos in DOS that error is due to the fact that the exit button passes through win32 and DOS emulation doesnt have access to win32 api
-
cheers mate,
that's what it will be then. good to know :cheers: