Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Shockwave on December 24, 2008
-
I was looking at this demo today;
(http://www.pouet.net/screenshots/52319.png)
http://www.pouet.net/prod.php?which=52319 (http://www.pouet.net/prod.php?which=52319)
I've always had a real soft spot for textmode demos, Probably Northern dragons Signal To Droids and Clockwerk are my favourites.
This one be Crimson shine just re-kindles the flame though.
The Northern Dragons released a "kit" a while ago to allow people to take part in TMDC 2008, that was not for me though.
I don't want to use a kit, I want to develop my own engine in Freebasic. The reason for this is really because I made so many software routines for drawing vectors and polygons that I think it would be easy for me to convert them to run with text.
I've seen it done in Freebasic, what I would love to be able to do first of all is to be able to open a text mode screen, and define the colours of that screen.
I don't think I need source code how to do it, I just need pointing the right way for now.
Any takers? :)
Thanks.
(I have looked at the screen command and it just seems to be gfx modes).
-
Ps. If it's better that I write it in C ++ or Fasm it would make very littel difference :)
-
Delphi has a crt unit that can display the full color set in a console window. I'll post the code; it may give you some ideas. This would be windows only though, which might rule it out.
EDIT: Sorry about the mess. I've attached a zip of the source. The main thing to look at here is the api for the console. It gives a good idea of what you need to do and in what order. MSDN also has a full scection on the console as well.
-
@shockwave:
ah cool to see you are interested in coding textmode stuff.. i am very interested in this too since some years.. my mainproblem is how to convert the colors to charsets... for example like the simplest way to convert RGB greytones from 0 to 255... :P
something i found out in one the TMD which could be possible something like the converted chars...
. .. ....::::;=;=tftf%$%$&KSZWXGM@@@@8888####????
@rdc:
Wow, i saw you posted a very long source while i wrote this.. (your source seems not be not comlete)... i will check your source now, is there a way to give a compiled version? thx
-
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 ;)
-
Maybe sol's engine might be of interest. It comes full
full c++ source code to study and learn from :
http://sol.gfxile.net/zip/textfx5.zip (http://sol.gfxile.net/zip/textfx5.zip)
-
Ooh, Delphi, C++ and Freebasic code examples to work with :) Thank you so much RDC, Nino and Benny.
I think that I am going to go for the Freebasic or C++ route.
Vain, interesting that you have that strip of letters, I once spoke to Tetra about this and he had written a routine that analyzed the pixel densities of all the letters in the default font and it produced a similar kind of thing to what you have there.
This will be more than enough to get me started.
Thanks chaps :)
-
don't know if those charts help in any way, i hope they do :)
(http://img407.imageshack.us/img407/7944/ascii1cf9.gif)
(http://img407.imageshack.us/img407/8810/asciids8.gif)
-
Just a bump to let you know I updated my previous post and attached the source file to the message. This is the version I extended and my additions are marked with { rdc} . I needed the extra functionality in my little virtual machine, Atom, I wrote in Delphi.
-
np shockwave,
but remember the way i open the ascii window and draw on it in my post is the way everyone does it even the tmdc guys. its the only way to get smooth console animations in c++/freebasic that i know of.
-
Cool, this is also something that I am quite interested in. The compo we did was also neat.
I dont want to bootleg this topic, so just a short few pennies worth. The thing I'm interested in is how to express the colours ( shades / density ) like they do in those TMDC 3D demos.
-
A lot of the TMDC entries seem to be downsampled framebuffers.
I talked to Tetra about this too and he was very interested in making textmode demos so he wrote a program to analyze the pixel density of every letter in the charset to enable his renderer to choose the right letter.
I am guessing that you could render very high graphics to a frramebuffer and treat it as a set of cells, examining what pixels are set and the weight of the colours to determine what ascii character you cast to the dos window.
A more elegant way of doing it would be to write some routines to draw polygons, textures, lines, sprites etc in proper ascii.
I am exploring the second method at the moment :)
I will be releasing something at Sundown this year and it is going to be a textmode demo.
-
Cool. Definately sounds interesting. Keep us informed here (http://www.dbfinteractive.com/forum/index.php/board,8.0.html).
-
Another facet I've been pondering over, is are textmode demos ascii or ansi, or perhaps a mixture? And what is the difference; if anyone can shed some light.
Cheers.
-
Here Clyde..
This link explains the process really well.
http://sol.gfxile.net/textfx/ (http://sol.gfxile.net/textfx/)
-
i dont know why... but last night i had two times the dream that i have worked on a textmode demo effect - checkerboard O.O strange!
-
Yeah, sol is well known and next to the fantastic explanation
he provides also handy libs to use : TextFX textmode graphics library (http://sol.gfxile.net/code.html) ;-)
-
@Shockie: Cool and thankyou.