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 / Questions for a painting app (eraser tool...)

Author
Message
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 20th Nov 2014 10:59 Edited at: 20th Nov 2014 11:08
Hi

I'm trying to developp a little painting application (see the screenshot in the botom).

I wonder if you know a way to do that :


1) an eraser tool : erase a renderimage with a sprite (only the alpha chanel of the sprite erase the alpha chanel of the renderimage, when I paint) ?

Perhap's the blendmode with source/destination would be a solution if AppGameKit allow this (instead of SetSpriteTransparency(sprite, mode), we could have SetSpriteTransparency(sprite, source, dest) ^^)


2) Brush size : do you think I should Use SetSpriteScale() or SetSpriteSize() to resize the sprite ? Do you think I have to resize the sprite in % or in pixel ?


3) RenderToimage bug ?
I have seen there seems to be a sort of "render bug" with renderImage, because when I paint (drawSprite on renderToimage) it had a color (the color of the clearscreen) when it should be transparent on the edge, like in this image :


So, do you know how I can correct this issue ?


4) Do you know a way to open a picture from the gallery on android?
For saving to SD card, I use Print command, but I don't know if there is a way to save a file on SD card and open an external file from SD.


5) Do you know if I can had the pressure from the tablet/smartphone (even only with a finger) with AppGameKit ? (I think it's not possible)


Thank you for your answer .

http://www.dracaena-studio.com
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 20th Nov 2014 11:57 Edited at: 20th Nov 2014 12:00
Hi Blendman,

1) You are probably doing some of the following but this is how I achieve an eraser tool

* Render to an image which just has the most recent sprites pasted to it.
* Set 2 textures to a quad object, 1st is composite of everything drawn so far, 2nd is your new image with most recent sprites.
* Set to render to a temp image(ideally you need to render to your composite image but not sure that is possible while the object is also textured with this image, so use temp and then copy it over to main composite afterwards).
* Use the following shader to use the most recent image as what should be removed from main composite image:


2) I think I use scale.
3) I noticed this too, simply set your clear colour to the brush colour each time you paste a sprite.
4) My android device asks if you want to open from gallery or pictures. Not 100% sure what your issue is here.
5) Not sure if that's possible.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 20th Nov 2014 12:33 Edited at: 20th Nov 2014 12:36
Hi Matty H, thank you very much for your answers.

1)I use Tier1, is your method working with tier1 ?
I will tried it.


2) ok, it's what I use for the moment ^^.

3) I have tried to change the clear color, but I use this code to draw on my rendertoimage, and I can't clear the screen when I want. Here is the code I use :



Have you a code which work ?


4) What is the function to open an image from the gallery ? Perhap's do you use C++, but I use Tier1, I don't know if it's possible with tier1 ^^.

Thank you again for your answers.

http://www.dracaena-studio.com
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 20th Nov 2014 13:05
3) You don't need to clear the screen, just SetClearColor() before you draw sprite.

4) ShowChooseImageScreen(), IsChoosingImage(), GetChosenImage()

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 20th Nov 2014 17:36
Thank you very much again Matty for your answer .

4) ok, it works great I didn't know this command, thanks.

3) I'm sorry, but it doesn't work when I do :


is that correct ?
Have you a little example to test your method ?

Thanks

http://www.dracaena-studio.com
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 20th Nov 2014 18:01
Quote: "is that correct ?
Have you a little example to test your method ?"


Yes that's correct although I have noticed it does not always work. I will need to investigate, I will post back if I find an answer.

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Nov 2014 09:49
One option I might consider, is to invert the image alpha before using the erase tool, so areas that are transparent would be shown as solid - but the erase could just be another brush that affects the image, albeit inverted. Then, when finished with the erase brush, you'd invert the alpha again. You could write a shader that displays your layer sprites with normal or inverted alpha.

This isn't ideal I know, inverting alpha on several images will cause a delay, but then it gives just the sort of control you need, otherwise the only way I can think off to make an erase tool is to do it with memblocks. The way I'm suggesting would let you switch between paint and erase mode, and use all the same brushes and tools because as far as your program is concerned, it's only ever painting - but paint on an image with inverted alpha and your actually erasing. Hope this makes sense, it's early still


Now, another idea, but relies on shaders and quite an extensive change to the way your working.... Why not have a separate alpha image for each layer? - greyscale, then write a shader to take the diffuse colour and the greyscale alpha level and use that rather than raw image data. A separate alpha image would let you paint away and erase without the issues that your facing now, like painting with black on the alpha image would be the same as erasing. This is perhaps something you could incorporate... like maybe a layer can have an option to only show the alpha channel, let users paint directly on that if they wish. This is actually a very powerful feature that would be useful. For example, say you have a picture of a flower that you want to turn into an alpha transparent sprite. It usually involves deleting the white space around the image, okay... but what if you could do that, then paint only onto the alpha channel to clean up the edges, and then paint only on the diffuse channel to spread the colours into the edges. You'd end up with a very professional looking flower sprite, without those horrible bright or sharp edges.
This is obviously quite involved, but I really think it's worth considering - there is a weakness with painting with sprites, and that's the ability to erase - but this method could resolve that issue and include powerful features that art package developers often overlook.

I am the one who knocks...
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 21st Nov 2014 15:57
Hi

@Van B : I have though about the alpha image (I have an alpha image for my layer, separate from the diffuse layer).

I have made a test with SetimageMask() :

It works, but it's very slow. So I will tried to find another method quicker/faster.
I think it's near the alpha chanel technic you have described.
I will tried the memblock with alpha chanel, and the shader technic of Matty_h, to see if it's faster.

http://www.dracaena-studio.com
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Nov 2014 16:11
I think you would need to draw to both images, so when you paste a sprite onto your main BG image, you'd paste the same exact thing onto the alpha image as well.

I still don't have AGK2, kinda holding off so I can buy it on Steam, but once I have it I'll be able to explain these more relevantly.

I am the one who knocks...
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 24th Nov 2014 14:33
Hi Blendman,

I just realised that due to my rendering pipeline I am clearing the screen(image) each time before I draw to it. This will be why SetClearColor() fixes the sprite transparency issue for me. Sorry, that should have been obvious to me earlier

How are you getting on, did you get eraser working etc?

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 25th Nov 2014 09:35
Hi Matty

I have made a little example of an eraser using setImageMask(), but it's very slow. So I would like to test your shader, I have to make an example which work ^^.

http://www.dracaena-studio.com
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 27th Nov 2014 15:47
Hi

I have made a new example with your shader (Matty) and it works great, it very fast !

Here the code (agk) :


The pixelshader "eraser.ps" (from Matty_H) :



and the Quad.vs (from agk source) :


I'm pretty sur it's possible to create a shader to paint and avoid the "black border" of my first image, I will tried to understand how to create that shader (a "simple" blend color, I think).


Again, thank you very much MATTY_H, your shader is excellent !

http://www.dracaena-studio.com
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 27th Nov 2014 16:09
Glad it is working for you

You can paint using the same method, this allows you to clear the TempLayer with the colour of your sprite(ink) and this should fix your other issue.

To paint instead of erase you just use a similar shader but add the final result at the end, instead of minus.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 28th Nov 2014 10:54 Edited at: 28th Nov 2014 11:35
Hi

I have changed a little the pixelshader, and it works better for an eraser :




And here is a new shader : keep_alpha.
You paint without changing the alpha of the image.


@MATTY_H : I have tried to change your shader to paint, but it doesn't work for the moment ^^.

http://www.dracaena-studio.com

Login to post a reply

Server time is: 2024-03-29 08:09:00
Your offset time is: 2024-03-29 08:09:00