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

Author Topic: Set my own blendfunc on a sprite object  (Read 5613 times)

0 Members and 1 Guest are viewing this topic.

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« on: September 19, 2009, 05:47:45 am »
Is it possible to render a loaded sf::sprite object with my own openGL blendfunc without it defaulting to one of the predefined blend options provided in sf::blend automatically?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Set my own blendfunc on a sprite object
« Reply #1 on: September 19, 2009, 11:05:11 am »
No. What kind of blending mode do you need?
Laurent Gomila - SFML developer

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« Reply #2 on: September 19, 2009, 08:17:22 pm »
Well, theres a few things I was trying out in another project and wanted to see how they would look in the sfml project I'm working on, problem is i'm stuck with the pre-defined blend functions.

Is it possible to have a function to disable the use of the default blending options and allow us to define our own before we call draw on it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Set my own blendfunc on a sprite object
« Reply #3 on: September 19, 2009, 11:09:23 pm »
No.
Laurent Gomila - SFML developer

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« Reply #4 on: September 19, 2009, 11:33:20 pm »
Well that wraps things up than!

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« Reply #5 on: September 20, 2009, 07:44:11 pm »
Oh and the blendfunc i wanted to set was

glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);

Edit:

I just overloaded sprite's render and setup the blendfunc there, im sure im probably taking some penalty for state switching with that but im too lazy to go a more optimal route =p

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Set my own blendfunc on a sprite object
« Reply #6 on: September 21, 2009, 09:03:25 am »
Quote
glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);

Ok so that's a multiply, but why are you adding dest_color * src_alpha to it?
Is it something like using a white texture with variable alpha, to amplify the current color (that's the only usage I found when searching for this combination of modes)?

Quote
I just overloaded sprite's render and setup the blendfunc there, im sure im probably taking some penalty for state switching with that but im too lazy to go a more optimal route =p

Ok, but keep in mind that it may not work anymore in a future release of SFML ;)
Laurent Gomila - SFML developer

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« Reply #7 on: September 21, 2009, 08:56:18 pm »
Quote from: "Laurent"
Quote
glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);

Ok so that's a multiply, but why are you adding dest_color * src_alpha to it?
Is it something like using a white texture with variable alpha, to amplify the current color (that's the only usage I found when searching for this combination of modes)?


Yeah thats exactly what I used it for, I took a gradiant textture and overlayed it with that blend mode to make a lighting effect.

(seen here in latest test bed app)
http://img142.imageshack.us/img142/3466/2dshadows.png

Quote

Ok, but keep in mind that it may not work anymore in a future release of SFML ;)


Well, I'm fine with that if theres some way to support custom alphafunc/blendfunc calls on loaded sprite objects. Whats the reason to not allow this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Set my own blendfunc on a sprite object
« Reply #8 on: September 21, 2009, 09:00:40 pm »
Quote
Well, I'm fine with that if theres some way to support custom alphafunc/blendfunc calls on loaded sprite objects

Actually, the next revision in the sfml2 branch will no longer allow that.

Quote
Whats the reason to not allow this?

Because you're probably the only one who needs it, and that "Alpha", "Multiply" and "Add" are more convenient for all other users ;)
Laurent Gomila - SFML developer

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« Reply #9 on: September 21, 2009, 09:06:02 pm »
wouldn't it be as simple as adding an additional enum to the blend mode options?

I don't see the reason to punish the user into using only pre-defined methods, especially if you want to produce fancier effects.

I just want to make it clear, sfml is an amazing tool to use. This has been probably the only issue I've run into so far. But what I don't understand is why you would remove the only solution I have ( in the scope of using your libraries ) to my problem and than tell me tough luck? Seems kind of a cold thing to do to someone whos been helping push the use of your library.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Set my own blendfunc on a sprite object
« Reply #10 on: September 21, 2009, 11:29:39 pm »
Quote
wouldn't it be as simple as adding an additional enum to the blend mode options?

Unfortunately, no.
Many features could be "as simple as adding a line of code". But a good library is not only a sequence of lines of code. It also has a design, a philosophy, a consistency.
When you ask me to add this simple line of code, I have to think about the relevance of the new feature, how it would integrate into the API, would it be simple to use, wouldn't it break anything, is it easy to understand by beginners, ... I have to consider everyone's point of view, not just yours or mine.

And this feature doesn't meet all the requirements:
- You're the first one to require this kind of effect, I've never heard about it before; and I can't add a new feature for one user
- It's not just a new blending mode, it is an effect that requires a special texture to work; setting it on a regular sprite would make no sense at all.
-> In short, I think it's too specific.

Quote
I don't see the reason to punish the user into using only pre-defined methods, especially if you want to produce fancier effects.

So far the only one to be punished is you ;)
I know that this is frustrating from your point of view, but trust me, it's really hard to maintain a "simple and fast" library. I have to make choices to keep the API clean and usable for everyone, that include rejecting many requests. If you look at the "feature requests" forum you'll find many fights actually :lol:
But that's what makes SFML as good as it is now.

Quote
But what I don't understand is why you would remove the only solution I have ( in the scope of using your libraries ) to my problem and than tell me tough luck? Seems kind of a cold thing to do to someone whos been helping push the use of your library.

Hey, don't take it personally. I'm not cold with you, I'm just answering your request ;)

I hope that you understand my point of view.
Laurent Gomila - SFML developer

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Set my own blendfunc on a sprite object
« Reply #11 on: September 21, 2009, 11:51:12 pm »
I understand where you're coming from, I know you got plenty more experience than I do when it comes to this whole thing in general.

I just want to be able to have a flexible use of what you offer beyond the simple interface of it. You can appeal to beginners and allow other functionality ( like overriding the render function of sf::sprite ) to be there if needed to go beyond the simple face of the program. I don't think thats breaking your design at all since a beginner wouldn't do that.

Shouldn't it be able to appeal to both newcomers on the surface but still have flexibility to those wanting to do more with it under the surface?

Once again I love what you have done so far, it has made the transition of game programming much easier for the people I work with. But it hurts to see that I now see a wall of what I can do with it rather than expand.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Set my own blendfunc on a sprite object
« Reply #12 on: September 22, 2009, 09:06:08 am »
Quote
Shouldn't it be able to appeal to both newcomers on the surface but still have flexibility to those wanting to do more with it under the surface?

Don't forget that you can use OpenGL to get 100% of the rendering power. So I'm not really limiting what you can do, I'm just not providing an easy interface for everything.

Quote
Yeah thats exactly what I used it for, I took a gradiant textture and overlayed it with that blend mode to make a lighting effect.

I was thinking more about your technique; have you tried using multiplicative blending rather than an additive one? On your screenshot we can see some bad effects of your technique: at full intensity the colors don't look right, they look too saturated.
Laurent Gomila - SFML developer

 

anything