Page 7 of 9

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

Posted: 29 Mar 2018 14:12
by misol101
Moved from elsewhere:

Coincidentally, I had just made a bouncing ball script using the "opposite" of "pure batch" - javascript for logic and cmdgfx for rendering. Here is a screenshot with 50 balls, with a shadow for each ball, running at 76 FPS:

Image

Archive is here: http://www.mediafire.com/file/ihbnkm2wy ... bounce.zip

By the way, this is an interesting way to test the speed of your machine (CPU). Press Cursor left to remove 10 balls, and cursor right to add 10 balls. Then observe the top left text within paranthesis. As long as it is 76 or more, you are still running at full frame rate.

On my Win7 machine, I can do 340 balls before FPS starts going down. At 500 balls (maximum) it's down to 46 FPS.

And code:

Code: Select all

@if (true == false) @end /*
@echo off
if defined __ goto :START
set __=.
cmdgfx_input.exe knW13x | call %0 %* | cmdgfx_gdi "" Sf0:0,0,320,220,240,100G16,16
set __=
cmdwiz showcursor 1 & goto :eof

:START
cmdwiz setfont 6 & cls & mode 120,50 & cmdwiz showcursor 0
cscript //nologo //e:javascript "%~dpnx0" %*
::cmdwiz getch & rem Enable this line to see jscript parse errors
mode 80,50
echo "cmdgfx: quit"
title input:Q
exit /b 0 */

var maxBalls=500, nofShownBalls=50, w=240, h=100
var ballsX=[], ballsY=[], ballsSX=[], ballsI=[], ballsYC=[], ballsYH=[], ballsSXcale=[], ballsCol=[]
var bI = ["ball4-t.gxy"], bIw = [13,11,9], bIh = [10,8,6]

var multiCol=1, shadow=1, extraFlag=""
var showHelp=1, helpMsg="text 7 0 0 SPACE\\-ENTER\\-\\g11\\g10\\-p\\-h 1,98", skip=["rem "," "]

for (i = 0; i < maxBalls; i++) {
	ballsX.push(Math.floor(Math.random() * w))
	ballsY.push(Math.floor(Math.random() * h))
	ballsSX.push(Math.random() * 1.8 + 0.1)
	ballsYC.push(Math.random() * Math.PI + Math.PI);
	ballsYH.push(Math.floor(Math.random() * 50) + 45);
	ballsI.push(Math.floor(Math.random() * bI.length))
	ballsSXcale.push(Math.floor(Math.random() * bIw.length))
	ballsCol.push(Math.floor(Math.random() * 6))
}

WScript.Echo("\"cmdgfx: fbox 1 0 X & image ball4-t.gxy 0 0 0 -1 260,0 & image ball4-t.gxy 0 0 0 -1 282,2 0 0 11,8 & image ball4-t.gxy 0 0 0 -1 303,4 0 0 9,6" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,10 -1 0 0 c4??=91??,?4??=?1??,c???=9???,?c??=?9??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,20 -1 0 0 c4??=a2??,?4??=?2??,c???=a???,?c??=?a??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,30 -1 0 0 c4??=d5??,?4??=?5??,c???=d???,?c??=?d??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,40 -1 0 0 c4??=e6??,?4??=?6??,c???=e???,?c??=?e??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,50 -1 0 0 c4??=78??,?4??=?8??,c???=7???,?c??=?7??" + "\" ")
WScript.Echo("\"cmdgfx: block 0 260,0,60,10 260,60 -1 0 0 c4??=b3??,?4??=?3??,c???=b???,?c??=?b??" + "\" ")

while(true) {
	outString="fbox 1 0 b1 0,0," + w + "," + h + " & fbox 1 0 b0 0," + (h-8) + "," + w + ",8"
	for (i = 0; i < nofShownBalls; i++) {
		ballsX[i] = (ballsX[i] + ballsSX[i]);
		if (ballsX[i] > w || ballsX[i] < 0) ballsSX[i] = -ballsSX[i];
		ballsY[i] = Math.floor(Math.sin(ballsYC[i]) * ballsYH[i]) + 95;
		ballsYC[i] += 0.025; if (ballsYC[i] > Math.PI*2) { ballsYC[i] = Math.PI; } // ballsYH[i]*=0.7;
		outString += "& block 0 " + (260 + ballsSXcale[i]*20) + "," + (ballsCol[i] * 10 * multiCol) + ",13,10 " + Math.floor(ballsX[i]-bIw[ballsI[i]]/2) + "," + Math.floor(ballsY[i]-bIh[ballsI[i]]/2) + " 58"
	}
	if (shadow==1) outString += " & block 0 0,0," + w + "," + h + " 0," + h + " -1 0 0 10b1=1058" + " & block 0 0,0," + w + "," + h + " 8,-2 -1 0 0 10b?=10b1,????=10b0" + " & block 0 0," + h + "," + w + "," + h + " 0,0 58" ;
	WScript.Echo("\"cmdgfx:" + outString + " & " + skip[showHelp] + helpMsg + " & text a 0 0 " + nofShownBalls + ":_[FRAMECOUNT] 1,1" + "\" " + extraFlag)
	extraFlag=""

	var input = WScript.StdIn.ReadLine()
	var ti = input.split(" ")
	if (ti[3] == "1")
	{
		var key=ti[5]
		if (key == "27") break
		if (key == "32") multiCol = 1 - multiCol
		if (key == "13") shadow = 1 - shadow
		if (key == "104") showHelp = 1 - showHelp
		if (key == "331") { nofShownBalls-=10; if (nofShownBalls <= 0) nofShownBalls = 1; extraFlag="C" }
		if (key == "333") { nofShownBalls+=10; if (nofShownBalls > maxBalls) nofShownBalls = maxBalls; extraFlag="C" }
		if (key == "112") WScript.Echo("\"cmdgfx: \" K")
	}
}
If speed is the aim, I'd strongly recommend a Javascript / batch hybrid. We are talking magntitudes of 10-100 times faster than Batch. Still not as fast as compiled C of course, but still...

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

Posted: 29 Mar 2018 14:22
by IcarusLives
I am absolutely in love with your graphics and animations! Excellent work, my friend!

Re: Cmdgfx - draw graphic primitives (polygons,circles etc) in cmd line window

Posted: 06 Jun 2018 20:43
by misol101
Repo and archive was updated. Most importantly, this version brings added speed to the GDI version, especially for when running fullscreen or with large windows.

For example, on my Win10 machine, the fullscreen example script servH-zoom-maximized-custom-palette.bat can now run at 80 FPS (previously 33) on my 1920x1080 desktop.

( On a technical note, I found that CreateDIBSection and manipulating the bitmap directly was much faster than calling CreateBitmap every frame)

Full list of changes:

1. Cmdgfx_gdi.exe output speed improved
2. Performance for textures with transparency ('3d/tpoly' operations) was improved (see e.g. servH-sphere-texture.bat)
3. 'fbox' operation now accepts three params only to clear entire buffer
4. 'Image' and 'text' operation: possible to precede text color with '\' to mean that '\' codes should not be treated specially at all (=plaintext)
5. Forcing foreground or background color now supported for 'text' operation also (by preceding color with a '-' character)
6. 'G' flag minimum now 16,16 (plus bug fix)
7. Bug fix: starting cmdgfx with 'fc' font no longer captures a screenshot
8. When reading gxy files, tab(9) is now written as space if encountered plain (not if written as \g09)
9. The 'image', 'tpoly', and '3d' operations now has a workaround to support spaces in filenames. All spaces must be replaced with a '~' character when provided to these operations

As for the scripts, all remaining dependencies on BG.exe was finally removed completely. The window manager BWin (viewtopic.php?f=3&t=8484) was added to the archive, as well as the scripts 'server-objsplit.bat' (image below), and 'server-bounce-js.bat' (image above)

Image

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window

Posted: 21 Aug 2018 18:37
by misol101
Repo and archive was updated.

This is a minor release, but it still has a fairly large number of changes:

1. cmdgfx_input: Added 'R' flag to report on the dimensions of the current window, since in Win10 any cmd window can be resized with the mouse. When 'R' is enabled, event data sent by cmdgfx_input has the following extra data added: RESIZE_EVENT 0 W 220 H 75. If RESIZE_EVENT was 1, then the window was just resized and we can respond to this from within our script. The window manager BWin (included in the archive) now uses this functionality, as well as new example script 'server-checkerbox-resizeable.bat'. Another more lazy way of dealing with resizing of console windows is to disable this functionality for the current window: use cmdwiz setwindowstyle clear standard 0x00040000L

2. Added a window title for all server script examples and games (not sure why I didn't earlier). Also, for pixel font examples, I added a list of available keys in the title

3. New flag 'U' for cmdgfx_gdi to draw not into console window but anywhere on desktop! This can be used for example to force fullscreen even on Windows 7. Beware though, it really draws on top of everything else. (Note that "cmdwiz fullscreen" operation is now using official 100% fullscreen API, but it does not work on Windows 7)
4. New flag 'I' to to enable using title bar for cmdgfx (same as cmdgfx_input can do), to avoid file writes to 'servercmd.dat'. Title must be set as output: "operations" flags. Use output: "" flags to only set flags. (Former 'I' flag is now 'J')
5. New flag 'Ln,n' to affect light calculations for 3d operation in mode 1, draw option 0 (used in 'server-lsystem-js-3d.bat')
6. New flag 'd' for error messages, to write out the actual full erroneous operation in case of an error

7. Bug fix: If a material was set in an obj file and a face with two points was encountered, nothing was drawn. Now draws a line like it should (ignoring the bitmap)
8. Bug fix: Draw single vertex face in mode 1(z-sourced light) as bitmap if material set (as in mode 0,5,6). Still not drawn for mode 2-4 (not possible in mode 2, not logical in mode 3-4)

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window

Posted: 15 Nov 2018 01:58
by misol101
Archive and repo update

Actually, the cmdgfx executable(s) hardly changed at all. The only changes were: 1. A few bug fixes regarding cmdblock 2. Added resource info to the executables 3. Cmdwiz (the companion program) had 'getfullscreen' operation added.

Fullscreen / resizable effects
Every single script (except 4, where it was too cumbersome) was changed to support the 'R' flag. This means that all those scripts can now be freely window resized, and switched to fullscreen (using either Alt-Enter on Win10, or Ctrl-Enter on Win7). Naturally, running fullscreen requires more CPU power, and especially some of the heavier scripts are very likely to stutter on slower machines.

Screensavers
11 of the scripts were duplicated to become 'screensaver' scripts (with script name starting with 'ScreenSaver'). This just means that these scripts start fullscreen,and that they are shut down if any key or mouse key is pressed. In order to actually use these scripts as Window screensavers, download "Screen Launcher" from http://www.softpedia.com/get/Desktop-En ... cher.shtml, and then choose ScreenLauncher from Windows screensaver settings and point it to any of the ScreenSaver scripts.

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window

Posted: 15 Mar 2019 17:17
by misol101
Well well, here goes version 1.0. It was finally time to give it a number :)

What's new?

1. In-program help was greatly expanded. It is now possible to get specific info on any operation, e.g. block, by writing cmdgfx /? block. Also, there are specific sections on flags, server, palette, comparing cmdgfx with cmdgfx_cgi etc. Some of these pages (like 3d and block) are perhaps rather long to read in a cmd window. However, I also put all this new help on the github page: https://github.com/misol1/cmdgfx (scroll past the file list)

2. Z-buffer support for 3d operation (not all modes). This basically means that 3d objects are depth-sorted automatically, whereas previously this sorting had to be done maually. Turn on with B flag. By default, it is only enabled for perspective-corrected texturemapped polygons (3d mode 5). By also enabling the s flag, mode 0,1,4 for flat color polygons also get Z-buffer support (but speed suffers a little). Example scripts: server-Z-buffer-test.bat, server-Z-buffer-test2.bat, servH-3dworld3_1280-Z-buffer-enemy.bat (this last one is interesting because it is so much more efficient to be able to add a single object to show an enemy than to, as previously, have to write a large file to disk every frame. It might even be feasible to make a Doom-clone now... :wink: )

3. The block operation had scaling and rotation (only 90,180, 270 degrees) added. Examples: server-block-scale-rotate-test.bat, server-plasma-scaled.bat. Try cursor right/left in both

4. Bug fixes for setting palette and for block move with expressions

Image Image

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24 bit RGB support!)

Posted: 07 Apr 2019 12:49
by misol101
Next-gen cmdgfx has arrived: cmdgfx_RGB! :)

Image

As the name suggests cmdgfx_RGB is a new executable, which has support for 24-bit real color input/output. Like cmdgfx_gdi the output is a bitmap rather than actual text in the buffer, which means: 1. It should work with Windows versions from at least Windows 7 and up. 2. Only the 10 cmd raster fonts (and 3 pixel fonts) are supported for output.

There are 13 new scripts available (RGB-*.bat), showing everything from images alpha blended on top of kaleidoscope effects to full color shadebobs and a 24-bit color FPS world.

Reading the operation summary help, cmdgfx_RGB will seem awfully similar, which it also is. The operations are more or less exactly the same, with a few changes. Summarized as:

1. Fgcol and bgcol (foreground and background color) can still be specified as index into the 16 color palette, but *also* as RRGGBB values. Example: cmdgfx_RGB "fbox ff9966 4466dd fe" to fill the buffer with pink characters on top of a baby blue background. Similarly to fgcol and bgcol, operations taking a transparent color as input can also be given in RRGGBB format.

2. Operations taking images as input (image, tpoly, 3d with textures) can still take txt,pcx and gxy files, but *also* 24-bit uncompressed BMP images, as well as the new format BXY, which is simply a way to save/load both RGB fgcol/bgcol and characters into a single binary file. BXY files can currently only be created by taking a snapshot with the 'c' flag.

3. Speaking of the c flag, it can no longer save gxy files (as gxy does not support more than 16 colors). By default it now saves bxy files (which tend to be pretty large), but it can also save txt (format 0), and bmp (format 2) files (bmp files will have only foreground color saved, not bgcolor or characters).

4. Some operations have support for alpha blending and other types of color mixing. It would be too much work and bloat the gfx library to support it for all operations. Anyway, ipoly has support for 6 new "bitop" modes, and it can draw all kinds of shapes like pixels, circles, etc (with some extra effort). Also keep in mind that when drawing flat color polys, the 3d operation can set a bitop, which means that 3d can also use these 6 new modes for color mixing. When using alpha blending (bitop modes 20 and 21), fgcol and bgcol should be provided in the form AARRGGBB, where AA is the opacity used when drawing (0-255).

5. The block operation has changed in various ways, both positive and "negative". As for the latter, using color search/replace for the transform parameter will no longer work and cause very strange results (characters can still be search/replaced). On the positive side, the block operation now has support for alpha blending. To use it, follow the mode parameter with a comma followed by a decimal value 0-255 to specify the opacity.

6. Moreover, since color values are now 24 bit, the colExpr of block had a number of help functions added to deal with this. Please note that currently, due to lack of precision, ONLY fgcol values can be changed and even *preserved* in colExpr for cmdgfx_RGB! The bgcol for values set in colExpr will ALWAYS be (re)set to 0.

New colExpr functions: 1. shade(col,r,g,b) to add (or decrease if negative) the values r,g,b to the color col (typically col would be replaced by e.g. fgcol(x,y)). 2. blend(col, a,r,g,b) to alpha blend col with color r,g,b using opacity a (all values in range 0-255). 3. makecol(r,g,b) to construct a color from r,g,b values in range 0-255. 4. fgr(col),fgg(col),fgb(col) to get a color's red,green or blue value (0-255). See RGB-bounce-js.bat for some examples of how to use these (used to add contrast, inverse, convert to grayscale, tint, etc)


Regarding speed: Cmdgfx_RGB writes 8 times (!) as much data as cmdgfx_gdi (theoretically it should only need to be 4 times but it would be too much of a rewrite to organize things like that). This doesn't necessarily mean that it is 8 times slower, but obviously it should still only be used for situations where 24 bit color is actually needed.


Repo and archive download link are the same as before.

Enjoy!

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 20 Apr 2019 04:12
by misol101
(Unsurprisingly) the first version of cmdgfx_RGB had some bugs.

Most importantly, new bitopmodes for alpha blending did not work at all for 3d (that's what happens when you just assume something will work without a test). It was fixed and tested in the new RGB-balls.bat script.

Also min/max functions were added to expressions, and some other minor stuff.

Cmdwiz (companion program) had its gxyinfo operation extended to be able to report dimensions on bmp, bxy, and pcx files as well (used in my upcoming post)

Repo and archive was updated.

Image

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 26 Apr 2019 13:31
by misol101
Don't use Photoshop... (or even ImageMagick :D )

Cmdgfx_RGB - the poor man's image processing tool 8)

Image

With the addition of loading/saving RGB, it's now possible to manipulate real color images in many ways.

The block operation with color expression is handy to make (simple) filters, like to turn an image into grayscale: "store(fgcol(x,y),0)+store((fgr(s0)*0.2126+fgg(s0)*0.7152+fgb(s0)*0.0722),1)+makecol(s1,s1,s1)"

The above images were done using a script already in the archive called bmp_convert.bat, and the picture shows which parameters creates what result.Interestingly, you can also use the x/y variables and expressions as parameters.For example, try "bmp_convert 6hld.bmp light (x*2-255)" to get a light transition from dark to bright.

The resulting image is saved in same folder as original with -2 added to name, and both before/after pictures are shown in the cmd window for easy comparison.

Or, use cmdgfx operations directly with "custom" filter, like:

Image

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 30 May 2019 11:56
by misol101
Archive/repo update: Version 1.1 of cmdgfx/cmdgfx_gdi and 1.2 of cmdgfx_RGB.

There were no big changes, except adding 'X' flag for cmdgfx_RGB to convert RGB to 16 color palette at the end of each frame. Now why would anybody in their right mind do that, you might wonder, having just added support for 24-bit color to the program??? Well, actually that's what many "text demos" (such as "Lickweed") actually do: the renderer just renders to a 24-bit bitmap, and then finally converts to a 16 color palette using a set of characters from full foreground color to full background color. So, to emulate this, there is now the X flag.

There was also a bug fix of the L flag (could not be set/changed after startup), and 'cmdcolblock' was added to obj format which in contrast to 'cmdblock' picks up colors only for a texture, no characters.

Image

From top-left to bottom right:

1. RGB-Balls2.bat and RGB-Balls3.bat are scripts used to test conversion from 24-bit to 16 colors. Press 'x' while running to switch between the two.

2. RGB-Fractal.bat which shows no new functionality, just me testing if I could make Mandelbrot/Julia fractals using expressions,despite no support for iteration or recursion. It is quite inefficient (because it always runs MAX_ITERATIONS per point) but still animates at 30 FPS on my machine

3. RGB-PixelDraw.bat is a fullscreen image editing batch script which allows to draw freely in 24-bit color, set opacity/color and brush size, and save the drawn image as a bitmap. It even has a color picker and two filters (grayscale/invert). It uses carlos pixelfnt.exe tool to set a 1-pixel font in order to get pixel-perfect mouse input.

4. RGB-Kaleidoscope.bat is an old script, I just added conversion to 16 color by pressing 'x'. The same is also true of RGB-Kaleidoscope-Blended.bat and RGB-Texture-Cube.bat

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 14 Jun 2019 17:22
by misol101
Archive/repo update: Version 1.3 of all cmdgfx versions

There are now 4 cmdgfx executables, as cmdgfx_VT was added. The output of this version uses VT-100 escape codes, so it obviously only works with Windows 10 machines. Like cmdgfx_RGB, it supports 24-bit color. The obvious advantage of the VT version is that any font can be used and that text is actually put in the buffer. The disadvantage is that it is much, much slower (see VT-Test-Simple.bat and VT-Texture-Cube-Rough.bat for examples. In the latter, press 'x' to see how fewer color changes improves speed)

Image

Other changes:

1. Removed X flag to convert to 16 color in RGB versions. Instead, a new color16 operation was added. The advantage is that we can draw to the buffer *after* conversion too.

2. New flag 'v' which enables 'delta mode polygons'. In this mode, only the first coordinate of the poly operations is a position coordinate, the rest are deltas from this position.

3. New flag 'V' which enables 'origo mode boxes'. In this mode, the position is the center, around which the box is drawn.

4. Text op: Possible to precede fgcolor with / to mean ignore/hide all gxy codes completely (as opposed to \ which ignores but prints the codes)

5. Added support for reduced buffer output size (outw/outh) for the 'f' flag of cmdgfx/cmdgfx_VT (previously this was only available for cmdgfx_gdi/cmdgfx_RGB)

6. Bugfix of forcing fgcol and/or bgcol for the image and text operation

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 16 Jun 2019 10:02
by carlos
Is very nice project misol101.
About the use of pixelfnt how is the performance using that with 1x1 (console screen buffer) compared with the use of gdi (paint pixels to window) ?

Carlos.

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 17 Jun 2019 03:36
by misol101
Thank you Carlos.

1x1 pixel font (also with 24 bit color in this case, so using VT-100 codes) is copious amounts slower than gdi bitmap output. I have not measured but would not be surprised if it’s 15-30 times slower or more (again, as has been discussed in this thread before, it is also heavily dependant on how many color changes there are. If only a single color is used for all text it might be similar in speed).

But just to clarify, I did not use your pixelfnt program in order to be able to output pixel characters into the buffer. The reason I needed pixelfnt was in order to ”trick” the Windows Console mouse API to give me pixel perfect mouse *input* coordinates (in order to draw to cmdgfx’s internal buffer, which is then output as a 24-bit pixel gdi bitmap)

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 28 Jun 2019 09:47
by misol101
Version 1.4 for all the cmdgfx variants. Archive and repo links are the same as always.

It is likely to be the last version for quite some time, perhaps ever.

What's new:

1. cmdgfx_GDI/cmdgfx_RGB: By specifying an optional font index to the text operation, it is now possible to write "big" versions of all 10 raster fonts (one character per pixel). The main use is to enable writing text in pixel mode, but also makes it possible to draw big fonts in non-pixel modes. Error messages are now readable in pixel mode, as well as frame count. See server-bigfont-splitscreen.bat, RGB-PixelDraw.bat, and RGB-Kaleidoscope-Pixel.bat for example uses.

2. Z-buffer was not working properly when using transparent textures, fixed now. See RGB-Balls2.bat for a script where this is used

3. Improved precision of 3d rotation (less jerky). Affects all rotation but is most obvious in RGB-Kaleidoscope-Pixel.bat

Image

Image

Image

Re: Cmdgfx - draw 3d and graphic primitives (polygons,circles etc) in cmd window (now with 24-bit RGB support!)

Posted: 28 Jun 2019 12:15
by Aacini
Wow! The writing of text is fantastic! This remembers me my old method to write text in pixel mode. Where do you get the definition of the raster fonts, so you can read them?

Antonio