SFML community forums

General => Feature requests => Topic started by: Rybens on April 14, 2010, 05:55:43 pm

Title: Sending 3D Vector to Sprite's Position
Post by: Rybens on April 14, 2010, 05:55:43 pm
It's my first post up here so I want to say Hello to all SFML users :)

Right now I'm writing 2.5D engine with SFML 2. I want to mix functions from SFML and OpenGL and use Shaders for normal mapping and calculating depth of all pixels.

Normal mapping works fine using functions from SFML, but depth testing not realy... it just draws sprites like before (One on other). And here's my question:

Is it possible to add ability to turn on depth buffer in sf::RenderWindow and then sending position of my sprites with Vector3f?

PS. And it would be very useful for some users, because of easy sorting of Sprites using Z-Buffer.
Title: Sending 3D Vector to Sprite's Position
Post by: Laurent on April 14, 2010, 06:37:04 pm
Hi

Depth sorting for sprites is not supported and will never be, sorry.
Title: Sending 3D Vector to Sprite's Position
Post by: Ashenwraith on April 14, 2010, 07:03:58 pm
I can see why depth sorting would not be enabled for sprites because of how the rendering is optimized for 2D.

What were you planning on using for collision, 'cubes' (or pseudo cubes)?
Title: Sending 3D Vector to Sprite's Position
Post by: RetroX on April 17, 2010, 05:38:53 am
You could do this with STL rather easily.

Code: [Select]
struct depthdrawable
  {
  sf::Drawable* todraw;
  int depth;
  };

int sortdepth(depthdrawable x, depthdrawable y)
  {
  if (x.depth==y.depth)
    {
    return 0;
    }
  else if (x.depth<y.depth)
    {
    return -1;
    }
  else
    {
    return 1;
    }
  }

// other code

std::list<depthdrawable> draw;
// pretend that I add stuff to that
draw.sort(sortdepth);


That is, if you're using C++.  This won't be available in C.
Title: Sending 3D Vector to Sprite's Position
Post by: Laurent on April 17, 2010, 10:02:06 am
I think he rather wants to use the OpenGL depth-buffer to avoid manual sorting on the CPU, and possibly to be able to mix with custom OpenGL 2D/3D geometry which have a depth.
Title: Sending 3D Vector to Sprite's Position
Post by: Rybens on April 17, 2010, 11:15:03 pm
No, I mean something more complicated ;)

I wanted to use shaders to calculate all pixels depth by seperate depth map. ( like here: http://www.youtube.com/watch?v=-Q6ISVaM5Ww )
For doing so I need depth buffer enabled, if you Laurent dont want to add that ability to SFML I will use OpenGL, no problem. :)

Sorry for not anwsering so long, so many things to do and not much time...

Rybens
Title: Sending 3D Vector to Sprite's Position
Post by: Ashenwraith on April 18, 2010, 05:02:51 am
I'd like to do something like that minus the 3D.