tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

openVG: how to quickly clear an area to Background color?

Sun Oct 30, 2016 1:11 pm

hello again,
about openVG: how to quickly clear an area to Background color? (e.g., if a text line has to be erased smilar to "ClearEndOfLine", or a graph, a picture, or a shape has to be erased in an area )
Is there a quicker way other than painting a rectangle over the related area which is actually very slow in execution speed?
- Tim

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 9:06 am

is there a way to erase a region correctly (as fast as possible) ?
- Tim

User avatar
Paeryn
Posts: 2055
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 10:29 am

You could use vgClear which sets a rectanglular area of the screen to the clear_colour.

Code: Select all

vgClear(x, y, w, h);
She who travels light — forgot something.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 10:59 am

thank you!
how to set the clear_color? Is it automatically the last background color which has been set?
or is there also a additional vgClear(x, y, w, h, clear_color );
- Tim

User avatar
Paeryn
Posts: 2055
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 11:29 am

It's whatever was last set as the clear colour by

Code: Select all

vgSetfv(VG_CLEAR_COLOR, 4, colour);
Where colour is a 4 element array of VGfloat defining the colour in RGBA.
If you are still using the shapes library then the clear colour is set to white whenever Start() is called. Calling Background() or BackgroundRGB() sets it to whatever colour you pass them.
She who travels light — forgot something.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 12:07 pm

sorry, my English is not so good to understand the details unequivocally.

I usually start with sth like this (taken from your github example, modified)

Code: Select all

#define GRAY25       64,  64, 64
#define YELLOW      255, 255, 0
#define SKYBLUE     135, 206, 235

//...

    initWindowSize(20, 20, 600, 360);
    init(&width, &height);                  // Graphics initialization

    Start(width, height);                   // Start the picture
    Background(GRAY25);                    // Black background
    Fill(SKYBLUE, 1);                   // Big blue marble
    Circle(width / 2, 0, width);            // The "world"

    Fill(YELLOW, 1);                 // yellow text
    TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10); 
//...
having done that, I want to erase the area (0, height/2, width, 50+height/2)
by
vgClear( 0, height/2, width, 50+height/2);

will it be then automatically be erased by Color GRAY25 because it was used for
Background(GRAY25)
most recently immediately before?
- Tim

User avatar
Paeryn
Posts: 2055
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 12:54 pm

tito-t wrote:sorry, my English is not so good to understand the details unequivocally.

I usually start with sth like this (taken from your github example, modified)

Code: Select all

#define GRAY25       64,  64, 64
#define YELLOW      255, 255, 0
#define SKYBLUE     135, 206, 235

//...

    initWindowSize(20, 20, 600, 360);
    init(&width, &height);                  // Graphics initialization

    Start(width, height);                   // Start the picture
    Background(GRAY25);                    // Black background
    Fill(SKYBLUE, 1);                   // Big blue marble
    Circle(width / 2, 0, width);            // The "world"

    Fill(YELLOW, 1);                 // yellow text
    TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10); 
//...
having done that, I want to erase the area (0, height/2, width, 50+height/2)
by
vgClear( 0, height/2, width, 50+height/2);

will it be then automatically be erased by Color GRAY25 because it was used for
Background(GRAY25)
most recently immediately before?
Yes, the last used command of Start, Background or BackgroundRGB sets the clear colour. Start always sets it to white and Background or BackgroundRGB sets it to the given colour.
Last edited by Paeryn on Wed Nov 02, 2016 3:04 pm, edited 1 time in total.
She who travels light — forgot something.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 2:48 pm

perfect, thank you!
- Tim

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 6:46 pm

just a minor humble suggestion, stumbling over Background() and BackgroundRGB():
as Background(r,g,b) has 3 parameters , i.e. r,g,b
and
BackgroundRGB(r,g,b,a) has 4 parameters i.e. r,g,b,a :o

wouldn't it be a good idea to rename BackgroundRGB() to BackgroundRGBA() ? :)
- Tim

User avatar
Paeryn
Posts: 2055
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openVG: how to quickly clear an area to Background colo

Wed Nov 02, 2016 10:04 pm

That's the way ajstarks has it. I'm not sure if he meant it that way or whether he missed the A off the end. I could add BackgroundRGBA to to my version and deprecate BackgroundRGB when I get around to updating it. In fact, yes I will, I'll stick an issue on my fork so I don't forget.
She who travels light — forgot something.


tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Thu Nov 03, 2016 6:49 pm

or make an overloaded function
Background (r,g,b, ...)

:mrgreen:
- Tim

User avatar
Paeryn
Posts: 2055
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openVG: how to quickly clear an area to Background colo

Thu Nov 03, 2016 7:00 pm

tito-t wrote:or make an overloaded function
Background (r,g,b, ...)

:mrgreen:
You can't have overloaded functions in C, that's a function that takes a variable number of arguments. But that's no good, how would the function know whether there is a fourth argument without passing a fifth to say so. And the compiler can't make sure you don't pass an unsuitable variable type to a vararg. Much easier to just have separate functions.
She who travels light — forgot something.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: openVG: how to quickly clear an area to Background colo

Thu Nov 03, 2016 8:03 pm

ok, I assumed it would be C++ ;)

But I don't want to argue, it was just an idea 8-)
- Tim

User avatar
Paeryn
Posts: 2055
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: openVG: how to quickly clear an area to Background colo

Thu Nov 03, 2016 8:22 pm

tito-t wrote:ok, I assumed it would be C++ ;)

But I don't want to argue, it was just an idea 8-)
It's a C library, that way you can use it from C or C++ (and a whole load of other languages that can interface with C libraries).

If I were to do it in C++ I'd have the alpha argument take a default value, that way you wouldn't even need to overload the function.

I didn't think you were arguing. Ideas are fine, sometimes other people see things in ways you never thought. :geek:
She who travels light — forgot something.

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 1 guest