Re: trying to do a blinking text cursor

Jonathan Dearborn <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <CA+DSiHZRVZG_BvDbQxhncgOvGJq8UtvT2LOU8UWx_LMWNekF4w@mail.gmail.com>
To invert existing colors on a render target, you have to read the pixels
first so you can calculate the inverted colors.  This is a very slow
operation and should not be done lightly.

The best way to do it nowadays (i.e. without direct video memory access) is
to use a shader and keep the color calculations on the GPU.  I can't help
any further than that with plain SDL (is anyone using shaders with
SDL_Renderer?), but I can do it all in a couple minutes with SDL_gpu.

Jonny D



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

> Hi,
>
> I'm using SDL2 as it looks like the most cross-platform UI library out
> there.  I don't want a GUI toolkit.
>
> I'm writing a very simple text editor and so far, the most challenging
> thing has been showing a blinking cursor at the text insertion point.
>
> I think I can work how an SDL timer works, but I can't work out how to
> invert the colours of a SDL_Rect at the insertion point.  How would I
> implement a function:
>
>   int ColourInvert(SDL_Window*w, SDL_Renderer*rend, SDL_Rect area);
>
> ?
>
> here's my pseudo-code for my editor (had to trim all the editor stuff out):
>
> SDL_Renderer*re;SDL_Window*w;TTF_Font*font;
> int drawline(char*s){
>   SDL_Surface*su=SDL_RenderText_Shaded(font,s,a,b));
>   SDL_Texture*tx=SDL_CreateTextureFromSurface,(re,su));
>   SDL_RenderCopy(re,tx,0,&rect));
>   SDL_DestroyTexture(tx);
>   SDL_FreeSurface(su);
> }
> main(){
>   SDL_Init(SDL_INIT_EVERYTHING);TTF_Init();
>   w=SDL_CreateWindow(x,a,a,y,z,SDL_WINDOW_SHOWN);
>   re=SDL_CreateRenderer(w,-1,SDL_RENDERER_ACCELERATED);
>   SDL_SetRenderDrawColor(g.v,255,255,255,255);
>   SDL_RenderClear(g.v);
>   SDL_RenderPresent(g.v);
>   //message loop
>   //a keypress changes a line
>   // for each line in lines{drawline(line)}
> }
>
> Thanks for all your work, guys,
>
>
> Jack
>
> _______________________________________________
> 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.