Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Plotting and Dot(x,y) etc....

Author
Message
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 26th Jan 2018 00:01 Edited at: 29th Jan 2018 21:18
There seems to be a few people asking for a Plot(x,y) function or a Dot(x,y) function to plot a pixel on the screen. I would assume that people want this to continually edit a backbuffer without deleting it?? im not sure really?

I'm sure the developers could add this functionality in the future which would be fine.

There are a few ways of doing this in AppGameKit already though.....each way has its merits.

One way is keeping a memblock and updating an image each frame like in the code below. It should be simple enough to understand.




This is a simple but fun drawing/Tron program. It looks nice too if you lower the virtual resolution so you get a nice pixel blur effect Its not mega fast but it works.

You can also just nor clear the actual backbuffer but it makes printing and other things hard.

Another way of doing plotting on and continually editing on a render target. You can then draw single pixels (Plot()/Dot()) on it. You can also draw sprites DrawSprite() and DrawLine() and DrawBox() on it too if you wanted to. I can do an example of that tomorrow if anyone is actually interested?? I guess people might just want the simple built in functions?? I just didnt want people to think that its not possible to do simple plotting type operations in AGK. Im sure alot of people already knew how to do it... so sorry for wasting your time.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Jan 2018 00:10
Ha! Very clever!
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 26th Jan 2018 01:07
Why not just use DrawBox with width and height of 1?
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 26th Jan 2018 09:13 Edited at: 26th Jan 2018 09:22
For 3 reasons

1) Because you dont keep the backbuffer that way - you have to continually draw your rectangles. The idea was how to keep the contents to modify them again and again without having to redraw it all.
2) Using a membuffer allows you to get at the existing pixel values - GetPixel(x,y) etc... (some people wanted that)
3) You can print text on top of this image or even display sprites on top of it etc.... where as drawing using DrawBox goes onto the backbuffer which is cleared and dissapears again so you have to draw it next frame....or you dont clear the backbuffer and you have the previous print operations still on it. This was about keeping a buffer of the image that you can work on (plot - clearing etc).

You could also call drawsprite with a 1x1 pixel sprite too but it has the same issues.

There are many ways of doing it ....some ways are quick , some are slow...some allow easy access to pixels some are not as easy but faster etc... A Render Image would allow the same sort of thing but quicker and still allow 3D and 2D to be mixed with it

Anyway...was just an idea,
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 26th Jan 2018 12:46
I believe you had to continually redraw dot(x,y) also.

I'm not arguing against using a memblock mind you, just comparing more directly with the original dot command being emulated
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
LillyByte
6
Years of Service
User Offline
Joined: 30th Oct 2017
Location:
Posted: 27th Jan 2018 00:44
I'm kinda surprised we don't have SetColor and SetPixel/GetPixel API functions; you'd almost think for 2D, they would be one of the very core functions you'd have access to.
~~ LillyByte ~~
http://www.dymoria.com
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 27th Jan 2018 14:33
Nice one. Now only need to save the memblock to disk as a picture or so and we can edit pictures.

Can convert to image using CreateImageFromMemblock(), which is one thing, but then to the correct picture format specifications, which is a bit harder I guess.
Would be nice if AppGameKit had build in something like SaveImageFromMemblock("path+image_name", ImageFormat ) function. [AGK team: Hint-hint..? ]
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 27th Jan 2018 14:38 Edited at: 27th Jan 2018 14:39
We dont really need SaveImageFromMemblock as we already have the SaveImage() command (jpg's and png's). Convert your memblock to an image and save it. Its 2 lines of code instead of one. Would be very easy to turn that into a function in no time.
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 28th Jan 2018 11:14
Ah wasn't aware of that. Thanks, pretty cool stuff.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Jan 2018 14:46
In DBP, dot() had to be constantly redrawn. I variant of the dot command was created to draw to the backbuffer directly by getting a memory pointer, this was done for speed and not for leaving pixels in the buffer.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 29th Jan 2018 15:07 Edited at: 29th Jan 2018 21:20
A Drawline() 1 pixel long or a DrawBox() 1 pixel wide or a DrawSprite() with a 1x1 pxel sprite does the same as the original Dot() command in AGK2... So, we already kind of have a dot command (or 3 of them!).

It was for speed and the fact that you then have a buffered/consistant image buffer that I did it that way above...plus you get to have a GetPixel() command too as its just a lookup into the memblock....

It was merely an interesting exercise is all to show how easy it is... I was thinking along the lines of how someone would go about doing a "scorched tanks" game or "lemmings" or even a paint editor in agk.

I wasn't suggesting that this is how the original Dot() worked.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Jan 2018 16:15
Quote: "A Drawline() 1 pixel long or a DrawBox() 1 pixel wide or a DrawSprite() with a 1x1 pxel sprite does the same as the original Dot() command in AGK2"


Visually perhaps, but drawLine likely has extra calculations in it that might cause it to be slower than using box, which doesn't need to worry about drawing diagonally.

Quote: "I wasn't suggesting that this is how the original Dot() worked."

Oh, gotcha.

In DBP, I did an image editor for one of competition challenges. I had layers and tried imitate Photoshop as much as I could. I started working on a filter system using matrices but never completed it. This was all done without DB plugins like ImageKit, so I think something similar would be doable in AGK. I would probably draw directly to memblocks (I have a large set of functions for doing that already). I haven't done a lot with memblock images in AppGameKit yet, so I don't know what the speed would be like converting back to an image constantly. Or, if writing directly to the memblock an image/sprite uses would update automatically. (be cool if it did)
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Jan 2018 17:14 Edited at: 30th Jan 2018 17:19
Quote: "Visually perhaps, but drawLine likely has extra calculations in it that might cause it to be slower than using box, which doesn't need to worry about drawing diagonally."


Thats depends on if they send a line to be drawn by open gl on the GPU? If so thats faster then the 4x line draw commands sent to draw the box as its the GPU thats doing the hard work. Truth is, I dont know and Id be interested in knowing whats faster...DrawSprite(1x1) vs DrawBox(1x1) vs DrawLine(1x1)?? Ive not tested but might check it one day.... Im currently programming 3D for a customer so not going to try that right now.

Quote: "I haven't done a lot with memblock images in AppGameKit yet, so I don't know what the speed would be like converting back to an image constantly. Or, if writing directly to the memblock an image/sprite uses would update automatically. (be cool if it did)"


Im doing the conversion every frame in that sample above. No, it definately doesnt update the sprite automatically, It's necessary to call CreateImageFromMemblock(1,Im) in every cycle above to transfer the memblock to the image, but that just gives us the control to choose if and when we do it. It is slow especially if the image is large but its the price of editing pixels on the cpu. The GPU is much quicker but we dont necessarily have the control that we want.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Jan 2018 18:43
It'd probably be difficult for AppGameKit to have direct access to the GPU due to how many different platforms it runs on. That'd be my guess anyway.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
GaborD
6
Years of Service
User Offline
Joined: 3rd Dec 2017
Location:
Posted: 30th Jan 2018 19:59 Edited at: 30th Jan 2018 20:00
Just do it fully on the GPU. Should work as long as the platform supports rendertextures.

Here is a very quick implementation, nothing fancy.
Just pingpongs the image in two textures (because simultaniously reading and writing in the same texture would be 65536 years of bad luck).
I set it up so that it draws a Lissajous curve, but you can draw anything.
The function is plot(x, y, r, g, b)
x and y are the actual pixel coordinates in the image and r, g and b are the usual 0-255 rgb values. The shader converts it all to uv positions and 0.0-1.0 color values.
Demo has no exe, it's virus safe. Just tier1 code and 2 shaders. (the second shader just copies the image)
Runs at 5000+ FPS for me, so it should be fast enough for any platform I guess.

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Jan 2018 20:21 Edited at: 30th Jan 2018 20:36
Yes, Thats pretty much what I said in the first post in this thread...

Quote: "Another way of doing plotting on is continually editing on a render target. You can then draw single pixels (Plot()/Dot()) onto it."


Very nice... Thanks, you saved me a job of doing it.

The only downside to the render target is that some people wanted a GetPixel() command which cant be done (easily) when its on the GPU. We dont have any lockrendertarget commands. We can convert to a memblock or use GetImage but that really is slow.

In any case its nice to see that it can be done fairly quick...all though I wouldnt want to draw a whole screen load of pixels each frame quickly. I guess its just an outdated way of drawing these days...using the CPU when there are hundreds of GPU cores waiting to do the job.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Jan 2018 21:29
I doubt anyone is interested but i wrote a very quick test program generating random x,y coords and then plotting a single pixel at each position.

I ran it for the three easy ways of generating a pixel...DrawSprite(), DrawBox() and Drawline()



DrawLine was the fastest... So, if you do want to do a load of plotting that looks like the way to go.
puzzler2018
User Banned
Posted: 30th Jan 2018 21:32
Speed is everything - good investigating work Bengismo
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Jan 2018 23:19
Draw line doesn't include alpha, however, box(I think) and sprite do account for alpha. That could slow rendering time.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Jan 2018 23:42 Edited at: 30th Jan 2018 23:45
Quote: "Draw line doesn't include alpha, however, box(I think) and sprite do account for alpha. That could slow rendering time."


DrawBox() does not include any alpha. (It doesnt matter what the highbyte is set to...only the R,G,B are actually used.)

Login to post a reply

Server time is: 2024-04-25 13:30:18
Your offset time is: 2024-04-25 13:30:18