Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sending 3D Vector to Sprite's Position  (Read 4546 times)

0 Members and 1 Guest are viewing this topic.

Rybens

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sending 3D Vector to Sprite's Position
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sending 3D Vector to Sprite's Position
« Reply #1 on: April 14, 2010, 06:37:04 pm »
Hi

Depth sorting for sprites is not supported and will never be, sorry.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Sending 3D Vector to Sprite's Position
« Reply #2 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)?

RetroX

  • Newbie
  • *
  • Posts: 13
    • View Profile
Sending 3D Vector to Sprite's Position
« Reply #3 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sending 3D Vector to Sprite's Position
« Reply #4 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.
Laurent Gomila - SFML developer

Rybens

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sending 3D Vector to Sprite's Position
« Reply #5 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: )
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

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Sending 3D Vector to Sprite's Position
« Reply #6 on: April 18, 2010, 05:02:51 am »
I'd like to do something like that minus the 3D.