Using Mojo2 Readpixels and Writepixels

Monkey Forums/Monkey Beginners/Using Mojo2 Readpixels and Writepixels

Pierrou(Posted 2015) [#1]
Hi,
I'm discovering Mojo2, it looks nice and all. I've begun to write a very simple android app allowing the user to draw single letters on the screen. Then, when the user stops touching the screen for some time, the letter drawn on the canvas is stored using ReadPixels, then the canvas is cleared and the letters get concatenated one after the other on top of the screen to form words and short sentences. It is aimed at people who are not able to speak anymore and have trouble moving their arm to point letters/words/pictures but can still draw a few simple shapes using their finger (I think at least one of my patients could benefit from it).

The code below is not complete at all since I really can't figure out how to use databuffer/ReadPixels/WritePixels. When trying to write the pixels on an image using WritePixels (not included in the code snippet below), all I get is a black image. I guess and I hope someone knows how to deal with databuffers and will be able to help. Thanks in advance!




soXes(Posted 2015) [#2]
I have the same issue. When I do WritePixels, in result I'm getting only black image. But I see such behaviour only for glfw target (under OSX in my case). The same code works fine on ios somehow. Spent quite time to find out the root of the issue, but no success yet.


soXes(Posted 2015) [#3]
It is funny when you write message to forums, and in 10min after that solution appears :)
In method WritePixels of Texture class at the end has to be added UpdateMipmaps method call. That solved black images for me)

Regards


Pierrou(Posted 2015) [#4]
Sorry for not updating this post, since I've found what I was looking for another way. For myself, since I just need black & white pixels this time, I ended just using a two dimension Bool array matching the resolution of the screen to store data every time the user touches the screen.
I'm using this method

to store circular "brushes" (rayonautour being the radius, xautour and yautour being the coordinates of the pixel being touched) instead of single pixels in that array and then I can draw them again on another canvas. It seems to work fast enough to be usable on my cheap Android tab, I don't need more at the moment. When I really need ReadPixels/WritePixels I'll try again to get it working.


DruggedBunny(Posted 2015) [#5]
Nice idea. I'd like to see it in action (ie. try it!) -- just out of interest.


Pierrou(Posted 2015) [#6]
Thanks... Well I might post it to the infamous Apps section when it's finished but I'm not satisfied with the app yet. I still have one remaining problem with the main display, i.e. when the patient is drawing the letter.
You can't just draw a circle at the coordinates TouchX, TouchY in the OnRender() Method, since the result is almost never a continuous line. So I've decided to draw a line made of circles between the current point (TouchX, TouchY) and the previous one (PreviousTouchX, PreviousTouchY) using a very simple y=ax+b formula.
At the moment it looks like that
and depending on variable a (=the slope) neither does it lead to a continuous since it just draws single points by incremeting x.
When the user moves slowly (which is not necessary the case with such neurological patients who have trouble controlling their moves) nothing goes wrong but if it goes faster with quasi-vertical slopes the lines are broken. If I could just use some magical "LineWidth" Function written by someone else I'd be done for a long time. :)

I could probably use some trigonometry to draw parallel lines between two circles but I was searching for a simpler solution first (maybe there's an obvious solution I'm missing?)


Pierrou(Posted 2015) [#7]
I'd like to see it in action (ie. try it!) -- just out of interest.

Hi,

You can try the HTML5 version here : http://pierrou.free.fr/ecritureaudoigt.htm
Its quite simple and raw at the moment, and not particularly interesting.
You can draw letters (or whatever you want, after all) inside the box, and after 2.5s, the screen is cleared and the letters are displayed on top of the screen to form words and sentences.

Touch the left side of the left blue margin or the right side of the right blue margin to add a space. You can delete a letter by clicking on it and delete the whole word/sentence by clicking on the very first letter.

You can increase displaytime by clicking on the right lower corner and decrease it by clicking on the left lower corner.

By the way I couldn't find a way to get the controls working right if I inserted the HTML5 code somewhere in the middle of the page so I put it at the very top, which sucks a bit (didn't search for a solution yet).