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

Author Topic: The new graphics API in SFML 2  (Read 80059 times)

0 Members and 1 Guest are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
The new graphics API in SFML 2
« Reply #45 on: September 16, 2011, 05:16:31 pm »
Quote from: "Laurent"
Why do you think that meshes and high-level objects shouldn't share the same states?

For simplicity of the high-level objects, to keep their own state, or part of the state (texture, transform).

If high-level objects use the global state as is, then you'll have sprites/whatever without their own texture & transform.
You can still store their own state internally but you have to explicitly apply it to the render target if you don't want to use/mix with the current global state - resulting in more verbosity.
Code: [Select]
sf::Sprite sprite(someTexture);
sprite.SetPosition(200,100);
window.SetTexture(sprite.GetTexture()); // 1
window.SetTransform(sprite.GetTransform()); // 2
window.Draw(sprite); // 3


The naming issue previously said are to turn 1,2 and 3 in one step, with the side effect of no chance to use the current global texture and transform. As for the other properties like shader, those have to be shared. Again, how it sounds can be a question of function names.[/code]
Pluma - Plug-in Management Framework

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
The new graphics API in SFML 2
« Reply #46 on: September 16, 2011, 05:22:57 pm »
Quote from: "Laurent"
Why do you think that meshes and high-level objects shouldn't share the same states? I had the feeling that it would be better if they were mixed, high-level objects would just be a layer on top of the low-level API instead of a separate layer.
Why ? Because I'm getting confused !  :oops:

Quote from: "Laurent"
I can easily implement the old sf::Text, sf::Sprite and sf::Shape classes on top of this new API. But it would probably not be a good idea.
Quote from: "Laurent"
But higher-level objects need to have their own render states, otherwise they are pretty useless

Maybe I misunderstood your words but these two quotes seems to go the opposite way from one other.

A lot have been said and everybody has changed his mind at least three times. Maybe it would be a good idea to make a quick recap of which ideas seem good so far.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
The new graphics API in SFML 2
« Reply #47 on: September 16, 2011, 05:36:37 pm »
Quote
Code: [Select]
sf::Sprite sprite(someTexture);
sprite.SetPosition(200,100);
window.SetTexture(sprite.GetTexture()); // 1
window.SetTransform(sprite.GetTransform()); // 2
window.Draw(sprite); // 3

When the sprite is drawn it sets all its internal states first so you don't have to do 1 and 2.
That my point: high-level objects can set their own states (texture, transform) while being able to use other states that they don't care about (view, shader).

Quote
A lot have been said and everybody has changed his mind at least three times. Maybe it would be a good idea to make a quick recap of which ideas seem good so far.

Yup. So far, I'm still on the same solution as in my very first post.
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
The new graphics API in SFML 2
« Reply #48 on: September 16, 2011, 05:45:56 pm »
Quote from: "Laurent"
That my point: high-level objects can set their own states (texture, transform) while being able to use other states that they don't care about (view, shader).

That's what we have been talking about :lol:

Quote from: "Laurent"
In fact, if all we see for high-level objects is 'object.Draw(window)', I think it's already clear enough that this won't change global states.

So I think this is good enough, go for it. I feel like we have been talking in circles.
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
The new graphics API in SFML 2
« Reply #49 on: September 16, 2011, 05:51:07 pm »
:lol:

So:
Code: [Select]
sf::Sprite sprite;
sprite.SetTexture(...);
sprite.SetPosition(...);

window.SetTexture(...);
window.SetTransform(...);
window.SetShader(...);

window.Draw(sprite); // uses its own texture, transform and the global shader
window.Draw(mesh); // uses global texture, transform and shader

:?:
Laurent Gomila - SFML developer

danman

  • Hero Member
  • *****
  • Posts: 1121
    • View Profile
    • Email
The new graphics API in SFML 2
« Reply #50 on: September 17, 2011, 12:09:57 am »
I agree :)
Pointilleur professionnel

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
The new graphics API in SFML 2
« Reply #51 on: September 17, 2011, 12:39:35 am »
Either target.draw(object) or object.draw(target), do as it is best for SFML.
Pluma - Plug-in Management Framework

Zinlibs

  • Full Member
  • ***
  • Posts: 127
    • View Profile
The new graphics API in SFML 2
« Reply #52 on: September 17, 2011, 12:52:36 am »
I agree too :D
Zoost & Zoom libraries : An easy way to create and handle geometric objets, animate and use them for better graphics !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
The new graphics API in SFML 2
« Reply #53 on: September 17, 2011, 09:24:44 am »
Great.

Now we can focus on other questions, such as: should high-level objects have their own transform, and keep the same functions as now (Set/Get Position/Rotation/Scale/Origin)? If so, how would one make a sprite relative to a parent object, ie. multiply its own transform by it before passing it to the render target?
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
The new graphics API in SFML 2
« Reply #54 on: September 17, 2011, 10:54:20 am »
Add further functions, instead of having to GetTransform and SetTransform on the render target you have a MultiplyTransform, like how OpenGL have. Or you have PopTransform and PushTransform.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

otibom

  • Newbie
  • *
  • Posts: 6
    • View Profile
The new graphics API in SFML 2
« Reply #55 on: September 17, 2011, 12:28:03 pm »
Quote from: "Laurent"

If so, how would one make a sprite relative to a parent object, ie. multiply its own transform by it before passing it to the render target?


Is this a scene graph ?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
The new graphics API in SFML 2
« Reply #56 on: September 17, 2011, 12:39:46 pm »
No he's talking about the relationship of spaces trough matrixes/transforms.

For instance if we go from object space to world space we multiply by the object's transformation but if we want to go from world space to object space we use the inverse of the matrix.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
The new graphics API in SFML 2
« Reply #57 on: September 17, 2011, 01:34:58 pm »
Quote
Add further functions, instead of having to GetTransform and SetTransform on the render target you have a MultiplyTransform, like how OpenGL have. Or you have PopTransform and PushTransform.

Assuming both would have their own transforms(which I'm not 100% sure is the best approach), maybe SetTransformMode(enum TransformMode), where TransformMode can be Inherit, Override or Multiply?

I also feel tempted to suggest not having a global transform at all, and instead let only meshes, sprites, etc. have transforms, though I admit it might not be the simplest-to-use approach.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
The new graphics API in SFML 2
« Reply #58 on: September 18, 2011, 11:57:46 am »
Argh, I knew I would miss the most interesting discussion :D


Quote from: "Laurent"
BlendMode, Transform and View should always be handled by value (copy), whereas Texture and Shader should be handled by reference. To make it clear, the first three will be passed as const references and the last two will always be passed as const pointer to functions that use them.
The pointers are a good way to make clear that the arguments are referenced after the call and no temporaries are passed, but you should be careful that you don't mix two code styles. Until now, pointers in SFML interfaces imply the possibility of being NULL.


Quote from: "Laurent"
Now we can focus on other questions, such as: should high-level objects have their own transform, and keep the same functions as now (Set/Get Position/Rotation/Scale/Origin)? If so, how would one make a sprite relative to a parent object, ie. multiply its own transform by it before passing it to the render target?
Would the high-level objects also provide set/get functions for the transform itself? Then one could do this:
Code: [Select]
sf::Sprite sprite;
sf::Transform tf = sprite.GetTransform();
sprite.SetTransform(tf * other);

In principle, the interface is unnecessarily big with SetPosition() etc., but the above code is too unconvenient to be the standard way of positioning objects. Another option are free functions, even if you don't seem to like them too much in SFML ;)
Code: [Select]
sf::SetPosition(sprite, pos);
// semantically equivalent to the following, but optimizations are possible:
sf::Transform tf = sprite.GetTransform();
tf.SetTranslation(pos);
sprite.SetTransform(tf);

The big advantage is, you can write this function as a template and it works with all positionable entities. Plus, it can be overloaded for other classes, even ones not part of SFML. Member functions either need a common base class like sf::Drawable, or produce a huge code duplication.


By the way, I have read the thread and have tried to reconstruct the proposals and their implications. But I consider this topic quite complex and I fear that some consequences are only visible when experimenting around with them. So I would appreciate if you left the users some time to test the new API after you have a first working draft, instead of releasing SFML 2 immediately :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
The new graphics API in SFML 2
« Reply #59 on: September 18, 2011, 12:35:20 pm »
Quote
The pointers are a good way to make clear that the arguments are referenced after the call and no temporaries are passed, but you should be careful that you don't mix two design policies in SFML. Until now, pointers in SFML interfaces imply the possibility of being NULL.

That's another reason why I need pointers: NULL means no texture/shader.

Quote
Would the high-level objects also provide set/get functions for the transform itself?

It would be the most flexible solution, but SetTransform would conflict with other functions. What happens if you call SetPosition and then SetTransform?

Quote
In principle, the interface is unnecessarily big with SetPosition() etc.

Really? I think that being able to set/get the transformation components individually is what makes it simple. Would you suggest to remove or simplify this interface?

Quote
Another option are free functions, even if you don't seem to like them too much in SFML
[...]
The big advantage is, you can write this function as a template and it works with all positionable entities. Plus, it can be overloaded for other classes, even ones not part of SFML. Member functions either need a common base class like sf::Drawable, or produce a huge code duplication.

But it doesn't work ;)
The interface based on Position/Rotation/Scale is not equivalent to manipulating a sf::Transform directly. sf::Transform accumulates all the transformations that you apply to it, while Position/Rotation/Scale are stored separately, and combined always in the same order. This is less flexible but more convenient.
Also, storing components separately allows to write getters for them. With a sf::Transform alone, you can't get them back (in fact you could get something but it wouldn't always be the same components that you initially set).

Quote
So I would appreciate if you left the users some time to test the new API after you have a first working draft, instead of releasing SFML 2 immediately

Of course! I'm aware that the new API will need to be tested, and probably modified before the final release.
There will always be a release candidate before the final 2.0 release.
Laurent Gomila - SFML developer