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 / Why DrawSprite does not take into account the depth of the sprite

Author
Message
metamorpho
7
Years of Service
User Offline
Joined: 17th Oct 2016
Location: Planet Earth
Posted: 27th Apr 2019 18:02


Why does what the DrawSprite team draws does not take into account the established depth of the sprite?
Is there any way to influence this?
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 27th Apr 2019 20:28
DrawSprite () draws a sprite on top of what is already drawn, it occurs imeadiately so no depth ordering occurs. No depth testing occurs.

When you call render() , all the sprites are drawn from back to front so the depth is correctly drawn. The depth of each sprite is drawn correctly as sprite drawing is ordered by the depth of each sprite.

So if you want to ensure a sprite is drawn with a correct depth, then create the sprite and set its depth properly then let render() draw it where it needs to be.

DrawSprite() simply gets drawn on top of what is already there and so doesnt fit into the depth ordering.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 27th Apr 2019 21:26
Quote: "Why does what the DrawSprite team draws does not take into account the established depth of the sprite?"


Because the 2D Draw System has some strange quirks to it.
You should only use DrawSprite( ) if you want to immediately Draw the Sprite on the Screen (Back Buffer) … as such the Depth is no longer used.

Now keep in mind IF you use DrawSprite( ) it REMOVES it from the Draw Queue for that Frame., so when you call Render( ) or Render2D( ) it won't be Redrawn.
What you want to use instead are the commands:
SetSpriteVisible( SpriteID, True ? False ) … this lets the Render Pipeline know if you want it to be Drawn that Frame
SetSpriteActive( SpriteID, True ? False ) … this lets the Physics and Animation Pipeline if it needs to Update it that Frame

These are entirely independent.
You can then use Render( ) Render2DBack( ), Render2DFront( ) or Sync( ) to Render that Frame.
Note that the Render Commands will ONLY Render what has NOT YET been Drawn that Frame... thus anything you use DrawSprite( ) on will be ignored.
Render( ) Draws all of the 2D / 3D Objects...
Render2DBack( ) Draws 2D Sprites with Depth > MaxDepth / 2 (Max Depth can be 5000 or 10000 and switched based upon what you set)
Render2DFront( ) Draws 2D Sprites with Depth < MaxDepth / 2
Sync( ) Updates and Renders everything.

It's a "unique" approach to handling Sprites, especially given Sprites are not being used for Particles and the Depth is exclusively to how the Sprites are drawn in relation to other Sprites... NOT how they're Drawn in Relation to the Scene Depth (Z-Depth) Buffer.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 28th Apr 2019 10:27 Edited at: 28th Apr 2019 10:28
Raven wrote: "
Now keep in mind IF you use DrawSprite( ) it REMOVES it from the Draw Queue for that Frame., so when you call Render( ) or Render2D( ) it won't be Redrawn.

Note that the Render Commands will ONLY Render what has NOT YET been Drawn that Frame... thus anything you use DrawSprite( ) on will be ignored. "


Sorry but you are wrong....if you call DrawSprite(), that sprite is still rendered if you call Render() or Sync() etc...

Heres some sample code to show it....there are two red squares drawn but only one red sprite - proving that render() does still draw any sprites that have had drawsprite()used on them


Raven wrote: "
Render2DBack( ) Draws 2D Sprites with Depth > MaxDepth / 2 (Max Depth can be 5000 or 10000 and switched based upon what you set)
Render2DFront( ) Draws 2D Sprites with Depth < MaxDepth / 2
"


This is not quite correct either.... (I dont think you meant Maxdepth / 2)

Render2DBack( ) draws any sprites/text that are behind the global 3d depth
SetGlobal3DDepth() is used to control that depth and is 5000 by default but can be anything from 0-10,000
Render2DFront( ) draws any sprites/text that are in front of the global 3d depth as well as boxes, elipses etc... (any line based item)


So the screen is drawn as layers, from back to front they are...

1) BackgroundSprites/text/particles
2) 3d objects
3) Front Sprites/text/particles
4) Any DrawBox,DrawEllipse or DrawLine commands
5) Print commands

(3,4,5 are all done in Render2dfront())
metamorpho
7
Years of Service
User Offline
Joined: 17th Oct 2016
Location: Planet Earth
Posted: 28th Apr 2019 14:38
Bengismo, Raven, thanks !!
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 5th May 2019 07:38
@Bengismo

Bengismo wrote: "
So the screen is drawn as layers, from back to front they are...

1) BackgroundSprites/text/particles
2) 3d objects
3) Front Sprites/text/particles
4) Any DrawBox,DrawEllipse or DrawLine commands
5) Print commands

(3,4,5 are all done in Render2dfront())
"


How would I implement a GUI? My GUI could not have text on a DrawBox?

And another question is, how would it be possible, to have maybe 2.5D with Sprites in the 3D space? Would we have to use Planes for the Sprites instead?
Would we have to create maybe buttons and GUI elements more like drawing all together on a seperate Image in the Memory before we draw the complete thing on the screen?

batch some sprites together maybe?
blink0k
Moderator
11
Years of Service
Recently Online
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th May 2019 07:56
Quote: "Would we have to create maybe buttons and GUI elements more like drawing all together on a seperate Image in the Memory before we draw the complete thing on the screen?"


Maybe look at using a quad. Which operates pretty much like a second screen. So your quad has an image and you render to that image (similar to a 3d plane). The quad stretches across the entire screen.
Only thing to remember is that it is considered a 3D object (I think) and therefore you will need to be careful with depth sorting

Login to post a reply

Server time is: 2024-04-26 23:14:25
Your offset time is: 2024-04-26 23:14:25