mfidler
September 1, 2013, 4:52pm
1
Is it somehow possible to invert colors of rectangle while using SDL_Renderer?
By inversion I mean R = ~R, G = ~G, B = ~G, or eventually any other operation that turns white to black, black to white and applied twice returns to original values…
I was hoping then SDL_RenderFillRect with correct SDL_SetRenderDrawBlendMode would work similar to other rendering frameworks, e.g. Cairo provides CAIRO_OPERATOR_DIFFERENCE usable for this, but it does not seem to be the case…
mfidler
September 1, 2013, 4:54pm
2
mfidler wrote:
R = ~R, G = ~G, B = ~G
OPS, typo, should have been B = ~B obviously…
It should work, if you subtract each color value from 1.0.
For example,
R = 1.0 - R; G = 1.0 - G; B = 1.0 - B;
Regards,
Klemen Ko?irOn Sun, Sep 1, 2013 at 6:54 PM, mfidler <mirek.fidler at gmail.com > wrote:
**
mfidler wrote:
R = ~R, G = ~G, B = ~G
OPS, typo, should have been B = ~B obviously…
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Probably you meant 255, not 1.0On Sep 1, 2013, at 7:56 PM, Klemen Ko?ir wrote:
It should work, if you subtract each color value from 1.0.
For example,
R = 1.0 - R; G = 1.0 - G; B = 1.0 - B;
Regards,
Klemen Ko?ir
On Sun, Sep 1, 2013 at 6:54 PM, mfidler <mirek.fidler at gmail.com > wrote:
mfidler wrote:
R = ~R, G = ~G, B = ~G
OPS, typo, should have been B = ~B obviously…
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Yeah, I got it confused with shaders. :POn Sun, Sep 1, 2013 at 7:23 PM, wrote:
Probably you meant 255, not 1.0
On Sep 1, 2013, at 7:56 PM, Klemen Ko?ir <@Klemen_Kosir> wrote:
It should work, if you subtract each color value from 1.0.
For example,
R = 1.0 - R; G = 1.0 - G; B = 1.0 - B;
Regards,
Klemen Ko?ir
On Sun, Sep 1, 2013 at 6:54 PM, mfidler <mirek.fidler at gmail.com > wrote:
**
mfidler wrote:
R = ~R, G = ~G, B = ~G
OPS, typo, should have been B = ~B obviously…
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
mfidler
September 2, 2013, 4:45am
6
Klemen Ko??ir wrote:
It should work, if you subtract each color value from 1.0.
For example,
R = 1.0 - R; G = 1.0 - G; B = 1.0 - B;
Sure, but how to do it with SDL_Renderer, I mean accelerated, without reading pixel values, inverting them in sotfware, then writing back?
Mirek
2013/9/2 mfidler <mirek.fidler at gmail.com >
Sure, but how to do it with SDL_Renderer, I mean accelerated, without
reading pixel values, inverting them in sotfware, then writing back?
Mirek
You’d need to use shaders for that, although I don’t think that’s possible
from the SDL render API.
If you want a solid rectangle [no texture], then you use this:
void invert_colors(SDL_Renderer* renderer)
{
Uint8 r, g, b, a;
SDL_GetRendererDrawColor(renderer,&r, &g, &b, &a);
SDL_SetRenderDrawColor(renderer, 255 - r, 255 - g, 255 - b, a);
}
The code above should do it. Note that we do not invert alpha.On Sep 2, 2013, at 7:45 AM, “mfidler” <mirek.fidler at gmail.com > wrote:
Klemen Ko?ir wrote:
It should work, if you subtract each color value from 1.0.
For example,
R = 1.0 - R; G = 1.0 - G; B = 1.0 - B;
Sure, but how to do it with SDL_Renderer, I mean accelerated, without reading pixel values, inverting them in sotfware, then writing back?
Mirek
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
That would only invert the color of the rectangle, not the color of
the pixels underneath it.
2013/9/2, neoaggelos at gmail.com :> If you want a solid rectangle [no texture], then you use this:
void invert_colors(SDL_Renderer* renderer)
{
Uint8 r, g, b, a;
SDL_GetRendererDrawColor(renderer,&r, &g, &b, &a);
SDL_SetRenderDrawColor(renderer, 255 - r, 255 - g, 255 - b, a);
}
The code above should do it. Note that we do not invert alpha.
On Sep 2, 2013, at 7:45 AM, “mfidler” <mirek.fidler at gmail.com > wrote:
Klemen Ko?ir wrote:
It should work, if you subtract each color value from 1.0.
For example,
R = 1.0 - R; G = 1.0 - G; B = 1.0 - B;
Sure, but how to do it with SDL_Renderer, I mean accelerated, without
reading pixel values, inverting them in sotfware, then writing back?
Mirek
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org