Re: trying to do a blinking text cursor

Jonathan Dearborn <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <CA+DSiHb-rLAn3cHineqdL31Gat7Xo8LahQSOFeehnGt_BPguBQ@mail.gmail.com>
Well, it would be simple to just draw a cursor without inverting the colors
of the underlying pixels.  If you know the color of the background, you can
do that.  It's a good first step.  Porting to SDL_gpu is easy, but still
takes a few additional changes.  If SDL_Renderer satisfies your needs,
stick with it.

SDL is quite low level and can change the color of pixels only by drawing
over them.  The trouble is reading the color of the underlying pixels.
That is a different matter.

But I realized inverting the color doesn't require a shader, only a
subtractive blend mode.  Still, SDL doesn't have one.


If inverted color is what you really need, you can set the shape blend
equation to subtract the RGB color values (and add alpha values):

GPU_SetShapeBlendEquation(GPU_EQ_SUBTRACT, GPU_EQ_ADD);

Then set the shape blend function to use all of the RGB values and ignore
the source alpha:

GPU_SetShapeBlendFunction(GPU_FUNC_ONE, GPU_FUNC_ONE, GPU_FUNC_ZERO,
GPU_FUNC_ONE);

Lastly, draw a white rectangle to invert the color under it (1.0 - R = R'):

GPU_RectangleFilled(screen, x, y, x + w-1, y + h-1,
GPU_MakeColor(255,255,255,255));


Jonny D


On Sat, Aug 6, 2016 at 11:55 AM, Jack Andrews <[email protected]> wrote:

> > glyph opposite color
>
> Thanks Chris.  That would work, but for the default, I'd like a
> browser-like blinking "I" cursor between pos-1 and pos.
> I kinda thought SDL was low level and so changing pixels in a window
> wouldn't be a big deal.
>
> Best,
> Jack.
>
> On 7 August 2016 at 01:50, Chris Bush <[email protected]> wrote:
>
>> Could you re-render the glyph in the opposite color on top of the cursor?
>>
>> Hope this helps.
>>
>> CB
>>
>>
>> _______________________________________________
>> SDL mailing list
>> [email protected]
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>
>
> _______________________________________________
> SDL mailing list
> [email protected]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.