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 / Help with grab image and shader

Author
Message
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 20th Mar 2016 14:03
Hi all!

I have a question:
I want to grab a part of rendered screen of my game (for apply a shader), but if I use quad take me all the full screen!
I don't use camera and i think it's impossible to use the command CreateObjectPlane!

To better explain my problem (because my english is terrible):

I wanto to grab the rect (red) zone, after I want to apply the shader to specific zone (grabbed zone) and paste the image over the original screen:


I add a little example, but I can not take the screen area in which to apply the shader!

Thanks far any help!

Attachments

Login to view attachments
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 20th Mar 2016 16:37 Edited at: 20th Mar 2016 16:45
I think you search for this command:


GetImage()
Description
Grabs a portion of the backbuffer and creates a new image from it. The position and size values must be in screen coordinates. Returns the ID of the new image, this must be deleted when you are done with it. To use this command effectively you must know how AppGameKit draws to the back buffer. When Sync is called AppGameKit updates the positions of all objects with Update, then draws them all to the back buffer with Render, without clearing it, then displays the back buffer to the screen with Swap. It then clears the back buffer and returns to your code, so if you were to call GetImage immediately after Sync you would get a blank image filled with the current clear color. Therefore if you want to grab an image of the current scene fully drawn you must call Render then GetImage then ClearScreen to clear the back buffer so Sync doesn't redraw everything over a fully drawn depth buffer. If you are already using Update, Render, and Swap yourself instead of Sync, then call GetImage between Render and Swap.

This also allows you to do things such as drawing lines to the back buffer, getting an image of the result and then clearing it so it doesn't effect what is displayed to the screen.

Calling GetImage is a slow command and it is not recommended that it be called every frame.

Note that the image produced by this command is not guaranteed to have the same width and height as those given to the command, this is because the image is created from a portion of the screen which has a different size on different devices. For example, with a virtual resolution of 480x360, you would get an image of the full screen by calling this command with a width of 480 and a height of 360, but on an iPod this would produce an image of 480x360 pixels, whilst on an iPad it would be around 1024x768 pixels. This should not effect how you use the image as applying it to a sprite and setting the sprite size to the same 480x360 will make the sprite fill the screen in both cases. It simply means that on the iPad you have a higher quality image to play with.

This also applies to the line drawing commands, drawing a line from 0,0 to 100,100 and then getting an image from 0,0 to 100,100 will produce a diagonal line image on all devices, but high resolution screen devices will produce an image of higher quality containing more pixels.

Use GetImageWidth and GetImageHeight if you need to know the actual size of the image produced in pixels.

Definition
GetImage( imageID, x, y, width, height )

void agk::GetImage( UINT imageID, float x, float y, float width, float height )

integer GetImage( x, y, width, height )

UINT agk::GetImage( float x, float y, float width, float height )

Parameters
•imageID - The image number that will contain the image captured
•x - The x coordinate of the top left corner of the box to copy
•y - The y coordinate of the top left corner of the box to copy
•width - The width of the box to copy
•height - The height of the box to copy



OR:

CreateRenderImage( width, height, format, mipmap )

Creates a blank image suitable for rendering and returns an ID to reference it. This can be used with SetRenderToImage to draw things to images. You can create RGBA images for normal rendering or depth images for capturing the depth buffer on devices that support it. You can also choose to use mipmapping on this image or not, this overrides the global SetGenerateMipmaps() command for this image only, this is because mipmaps on rendered images can be a performance hit so it should not be used unless necessary. Mipmaps should only be necessary if you intend to use this image to texture objects in your scene, if you are only using this image for full screen shaders you should not use mipmapping on it.


You can even set a shader directly to a sprite by using
SetSpriteShader()



Cheers, Jack

[/url]
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 20th Mar 2016 17:39
Hi Jack and thanks to reply!
It's possible to make a small example???

Five stars for your help

THANKS
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 21st Mar 2016 12:33
mmmm ....
I understand the commands, but I can not take the rect area that interests me, and then reattach over the original image!
I really confused ...

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 21st Mar 2016 13:26
I haven't had much experience with render images (yet), but I think that once you setrendertoimage, you can control what area of the 2d world to "grab" using the SetViewOffset command.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 21st Mar 2016 13:40
I found this guide to be very useful when hooking up to PHP: http://blog.naplandgames.com/2014/06/originally-published-in-tgc-newsletter.html As long as Python can read the post data in a similar way, it should be easy enough to follow.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 21st Mar 2016 14:12
Not sure how to do what you're trying to do, but I would think about WHY you're trying to do it.

If the image on the screen is originally a sprite (the turtle), you can apply the shader to the sprite itself rather than the image. Or..scale the sprite without a shader...that looks like the change you showed in the image.

Might be easier to go at the problem this way, especially in real time.
Born. Currently living.
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 21st Mar 2016 16:39 Edited at: 21st Mar 2016 16:42
Quote: "I found this guide to be very useful when hooking up to PHP: http://blog.naplandgames.com/2014/06/originally-published-in-tgc-newsletter.html As long as Python can read the post data in a similar way, it should be easy enough to follow."


I think it is not related to my thread ...



Quote: "Not sure how to do what you're trying to do, but I would think about WHY you're trying to do it.

If the image on the screen is originally a sprite (the turtle), you can apply the shader to the sprite itself rather than the image. Or..scale the sprite without a shader...that looks like the change you showed in the image.

Might be easier to go at the problem this way, especially in real time."


No, it's not just the sprite of the turtle, but there is also the background!
That's why I must first make a grab of the zone rect, then apply the shader, the image in memory and finally reposition the image!

See this video (between minute 1:26 and 1:27 the Warp explosion) : https://www.youtube.com/watch?v=ETRJ1XvprOQ
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 21st Mar 2016 16:57 Edited at: 21st Mar 2016 17:00
You can do this with a full-screen shader, centred on the action. Take a look in the Shader thread, I remember asking about this a couple of months ago and somebody posted the solution.

[Edit] here it is.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 21st Mar 2016 17:34
Quote: "You can do this with a full-screen shader, centred on the action. Take a look in the Shader thread, I remember asking about this a couple of months ago and somebody posted the solution.

[Edit] here it is."


Yes, but if you see my code, I use the same code of Swirl or Warp but this only work on a single sprite!

In game I have more explosion in different areas of the screen and I don't know how to solve this problem ....
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 21st Mar 2016 23:42
Quote: "I think it is not related to my thread "
Oops... Yes. Sorry about that. Was for a different thread.

Anyway, I have knocked up a really horrible example of grabbing just the bit of screen you want to manipulate as a render image. I don't like having to draw everything twice, but it makes for an interesting effect and might help point you to a better answer.

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 22nd Mar 2016 10:40
Thanks CJB!
Now I test your code ....
Wait for result!
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 22nd Mar 2016 12:14
mmmmm ....
using the commands:
- SetViewOffset
- SetViewZoom

unfortunately you can not maintain the correct value of scale 1: 1 of the image.

I attached the full example or simply see the code!

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Mar 2016 14:51
Quote: "unfortunately you can not maintain the correct value of scale 1: 1 of the image."


I haven't looked at your code in detail, but I think it is because of the renderImage. These are always powers of 2, so you need to adjust your calculations due to image and screen dimensions being different..
It really confuses me every time I use them!!!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 22nd Mar 2016 19:23
I test various way but the result are the same ....
I don't understand too many steps ....
For now I can not use that (It's all too confusing)!

I think the (only) best way, it's the AppGameKit Staff realizes various tutorial to understand how to use shaders!
- How to use a single shader on sprite or at fullscreen
- How to Mix one shader on sprite and one at fullscreen
- How to Mix more shaders at full screen
ecc.....

For not call too many times SetRenderToScreen or other commands and to have a clean code ...
I hope the AppGameKit Staff and the Community work in this way ...
Diegs
9
Years of Service
User Offline
Joined: 27th Oct 2015
Location:
Posted: 23rd Mar 2016 11:48
mmmmm .....
another question ....

How to use the same shader for use it several times simultaneously.
I'll explain my questions.

I use the Shader Shock Wave, but if I click with mouse they create a single Wave, if I click again the program stop the wave and restart it.
I want to create a multiple wave (one for each click)!
And if it's possible how to define the maximum wave size!

I think it's the solution at my problem!

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 08:37:03
Your offset time is: 2024-11-25 08:37:03