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 Studio Chat / [SOLVED] object depth issue

Author
Message
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 21st Sep 2019 22:57
I have a window made out of sprites and an object behind it. I also want an object in front of the sprite. The problem is i cant figure out how to do this. there is no way to set the depth of an object, only sprites, so all objects are drawn behind the sprite or in front. I also tried to manually update render draw and swap the sync cycle but im not having luck with it.

The author of this post has marked a post as an answer.

Go to answer

Onomatopoesie
4
Years of Service
User Offline
Joined: 6th Aug 2019
Location: Germany
Posted: 22nd Sep 2019 05:12
You have tried update3d, update2d, update3d again, right? Not working? What is about a walk around with render to image and placing it always in front of the camera? There you should have the perfect control about the depth, I think.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Sep 2019 05:14
All objects appear at the back of sprites this cant be changed
but you could briefly turn off the sprites render the background
to an image turn on sprites and have the rendered image wherever
you want it as a sprite
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 22nd Sep 2019 05:38 Edited at: 22nd Sep 2019 05:39
Well the issue is i have layers as you can see a 2d background with 3d in front then a 2d wall, then a ship that needs to be in front have 6 layers im working with. if i move the ship to the front the asteroid field follows i am unable to seperate them.

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Sep 2019 10:47 Edited at: 22nd Sep 2019 11:14
This post has been marked by the post author as the answer.
You can have as many layers as you would want to and there are a few ways to do it...

in your case, you can break up sync() into

update()
Render()
Cleardepthbuffer()
SetObjectvisible(ship,1)
Drawobject(ship)
SetObjectvisible(ship,0)
swap()

this way the ship is drawn on top of all the 2d

There's a few other ways to do this generally

1) As stated above by others, you can render 3d objects to a renderimage and then show the render image on sprites with different depths so that you have the layers you want. You can use DrawObject() to draw only one item to the render image, then use sync() as normal to display the sprites on screen.

2) Alternatively you can break up AGK's rendering into 6 layers. By default, AppGameKit has 3 layers (2DBack, 3D, 2DFront) but if you break up the render command into multiple calls of Render2DFront() and render3d() then you can add layers of 2d or 3d and have any number of layers that you want. You will have to change the view (2d offset or camera) or hide sprites in between render calls to draw what you need to on each layer.

Some very simple example code showing 6 layers (3x 3d and 3x 2d) - Press left mouse to turn the layers semi transparent


3) similar to 2 above - you can individually call DrawSprite() and DrawObject() in stead of using Render commands to get the draw order that you want.
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 22nd Sep 2019 13:38 Edited at: 22nd Sep 2019 13:42
Or.... couldn't you use Planes to turn the Sprites into Objects, face them looking towards the camera, and position them as far out or as close as you want?
Then your 2d background would be 3d and there wouldn't bee any problem, just like a skybox or billboards.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Sep 2019 13:43 Edited at: 22nd Sep 2019 13:45
Quote: "Or.... couldn't you use Planes to turn the Sprites into Objects, face them looking towards the camera, and position them as far out or as close as you want?
Then your 2d background would be 3d and there wouldn't bee any problem, just like a skybox."


Hes got text in the image above which is very difficult to produce in 3d without rendering to an image.

if you were only using sprites and 3d objects then you can put the sprites images onto planes like you say and do it that way.
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 22nd Sep 2019 16:05
well i actually put 1 layer on a plane last nite to help with the issue. the remaining problem is the real time sprite impact event wall. it draws behind the asteroids.
Quote: "
update()
Render()
Cleardepthbuffer()
SetObjectvisible(ship,1)
Drawobject(ship)
SetObjectvisible(ship,0)
swap() "

i ll try playing with this code pretty sure cleardepthbuffer is no longer a command.

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 22nd Sep 2019 16:59 Edited at: 22nd Sep 2019 17:00
Quote: "
Hes got text in the image above which is very difficult to produce in 3d without rendering to an image."

That is in the foreground though (HUD), so it can just stay a sprite like it is,

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Sep 2019 17:03 Edited at: 22nd Sep 2019 17:05
Your right ! ClearDepthBuffer() doesn't work in studio

I didnt realise I was posting in the studio forum (rather than classic). Oops

I thought he wanted a 3d ship on top of the view above...so on top of the text?

Anyway...It Looks like using using planes and render images is the only option ...or manually controlling draw order with drawsprite() and drawobject calls
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 22nd Sep 2019 17:45
there are 6 layers. ui layer2d scenebackdrop3d sprite window2d background environment 3d and background image2d. ive been unable to get a render image to work right thus far. i will attempt to manually draw objects and sprites i suppose and let you know the outcome.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 22nd Sep 2019 18:29
It Works! manually set all the draw events. thanks guys!!

janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 24th Sep 2019 14:42
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 25th Sep 2019 03:41
setglobal3ddepth sets everything to same depth jambo. i need to draw at different depths. problems been marked as solved by manually drawing sprites and objects in a specific order

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 25th Sep 2019 06:58 Edited at: 25th Sep 2019 06:59
I know its solved but the command janbo stated is another method

Sets the position of all 3D objects relative to 2D objects. For example using a global 3D depth of 100 would mean that all sprites at a depth less than or equal to 100 would appear above any 3D objects whilst sprites at a depth greater than 100 would appear below any 3D objects.


you can set several depth layers
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 25th Sep 2019 16:12 Edited at: 25th Sep 2019 16:16
Original Poster - Smerf wrote: "I have a window made out of sprites and an object behind it. I also want an object in front of the sprite."


Quote: "I know its solved but the command janbo stated is another method.... you can set several depth layers"


SetGlobal3DDepth() does not allow you to have some 3d objects behind sprites and some in front of them as was the original request. So, its not really another method of doing it unless you know of some special way of using that command?

AGK's default setup (using Render()) allows for just 3 layers (2DBack, 3D, 2D front). This can be overidden by using multiple render3d() commands and render2DFront() with different viewpoints or additional calls to DrawObject() after using Render().

The lack of a cleardepthbuffer() command in studio is worrying as thats needed to do 3d layering properly and ive used it in a few projects. I will be sticking to classic for a while it seems even though i own studio. Vulkan has a command to clear the depth buffer or stencil buffer etc... so I have no idea why it it was removed?

Login to post a reply

Server time is: 2024-03-29 00:42:34
Your offset time is: 2024-03-29 00:42:34