davenull
Posts: 1162
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

why initWindowSize, why init, and why Start ?

Sat Apr 16, 2016 8:38 pm

hi,
I still haven't got it:

why do I need a

Code: Select all

void initWindowSize(int x, int y, unsigned int w, unsigned int h)
. without "&",

what for is

Code: Select all

void init(&width, &height)
(and why int hat case with "&"),

and why do I need additionally

Code: Select all

void Start(int width, int height)
(and why in that case again without "&" ?)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
ajstarks
Posts: 129
Joined: Fri Jun 22, 2012 2:14 am

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 12:08 am

Note that init and Start were original functions in my OpenVG wrapper.

init() was designed to initialize the low-level graphics environment, and is only meant to be called once, returning the dimensions of the screen. init is to be paired with finish(), which shuts down the graphics environment, again, designed to called once.

Start() is designed to begin a drawing region, conventionally using the dimensions returned in init. It may be called multiple times in your program, and then used with End() to swap buffers and show the picture.

initWindowSize() was introduced later via Paeryn's fork, which introduced more flexible canvas handling.

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

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 2:34 am

Continuing on what ajstarks said, the reason why init() takes its parameters preceded by & is because that function passes values back into those values diecrlty. None of he other functions you meantioned have a need to set more than the ongle value allowed by a return..
She who travels light — forgot something.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 3:08 am

Paeryn wrote:Continuing on what ajstarks said, the reason why init() takes its parameters preceded by & is because that function passes values back into those values diecrlty. None of he other functions you meantioned have a need to set more than the ongle value allowed by a return..
I would add... study what is meant by 'pass by reference,' and 'pass by value'. Some functions return more than the return value (another way of stating Paeryn's case)... and the way they do that is by taking a 'reference' (a pointer) to a data structure (or to an object) and the function then uses that pointer to memory to pass back data into the data structure or object information beyond what is being 'returned' by the function proper :ugeek: .

Do a google search on 'pass by reference' and 'pass by value' as regarding C | C++
marcus
:ugeek:

davenull
Posts: 1162
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 8:20 am

I know of course the difference between pass by value or by reference, that's not the point.


@ajstarks, paeryn:

but initWindowSize has to be called before init, with constant parameters which have to be defined before anyway:

int width=800, height=600;

initWindowSize(100, 100, width, height);

the same then is passed afterwards to init and start:

init(&width, &height));
Start(width, height);

why makes it sense to call this (width, height) 3 times, one after another,
and why has it to be passed by reference to init() which has already been set so far before and which now is not expected to change (or be changed) anything of width, height after that call anyway?
And in which respect is a drawing region different from the screen region?
it's still expected to remain
int width=800, height=600;
as defined at the top!
Or what do I miss?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

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

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 12:12 pm

davenull wrote:@ajstarks, paeryn:

but initWindowSize has to be called before init, with constant parameters which have to be defined before anyway:

int width=800, height=600;

initWindowSize(100, 100, width, height);

the same then is passed afterwards to init and start:

init(&width, &height));
Start(width, height);

why makes it sense to call this (width, height) 3 times, one after another,
and why has it to be passed by reference to init() which has already been set so far before and which now is not expected to change (or be changed) anything of width, height after that call anyway?
And in which respect is a drawing region different from the screen region?
it's still expected to remain
int width=800, height=600;
as defined at the top!
Or what do I miss?
The original init() function just opened a full screen window and returned it's size by filling in the width and height variables pointed to. When I added the ability to choose the size of the window I could have required the user to pass the requested size in via the same width and height, but that could cause problems for existing programs as if the variables hadn't been initialised (quite likely if the were on the stack and there was no need beforehand to set them to any value) then programs could end up having random sized windows. Plus there was no way of specifing an initial position so instead I added the initWindowSize() function that would set internal variables to show a specified size / position was wanted. init() was changed to look at those internal variables and it will reduce the width / height if the requested size was larger than the size of the display. If initWindowSize() isn't called first then init() works exactly as the original. In both cases the actual size of the window created still needs to be passed back as it can be different to what was requested.

Start() takes a width and height (it doesn't have to be the width and height of the screen) as the area to clear (with the origin always at the bottom-left).

What do you mean about the drawing region vs screen region? OpenVG can draw to the whole region of the created window. It can be restricted to a certain rectangle within the window with ClipRect().
Last edited by Paeryn on Sun Apr 17, 2016 12:17 pm, edited 1 time in total.
She who travels light — forgot something.

davenull
Posts: 1162
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 12:17 pm

init() was changed to look at those internal variables and it will reduce the width / height if the requested size was larger than the size of the display.
thank you, now that part is clear to me!

about start:
Do I understand correctly that the coordinates passed to start are just a subset of the whole openVG screen then?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

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

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 12:22 pm

davenull wrote:
init() was changed to look at those internal variables and it will reduce the width / height if the requested size was larger than the size of the display.
thank you, now that part is clear to me!

about start:
Do I understand correctly that the coordinates passed to start are just a subset of the whole openVG screen then?
The area that Start() clears is a rectangle with it's bottom left corner at the bottom left of the screen and it's top right corner being width,height. So if the screen is 800,600 and you call Start(400,300) then the bottom left quarter of the screen will be cleared, the rest of the screen will retain whatever was already drawn. It doesn't restrict any further drawing to that size, it's purely the size of the area to clear.
She who travels light — forgot something.

davenull
Posts: 1162
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 12:55 pm

So if the screen is 800,600 and you call Start(400,300) then the bottom left quarter of the screen will be cleared,
now that confuses me.
how will be cleared the bottom right quarter instead? or the upper right?

anyway, I actually assumed 4 values to clear a rectangle: x1, y1, x2, y2
... :?

and, BTW:
why is start then called "start"? isn't it more a "clear" ?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

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

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 1:17 pm

davenull wrote:
So if the screen is 800,600 and you call Start(400,300) then the bottom left quarter of the screen will be cleared,
now that confuses me.
how will be cleared the bottom right quarter instead? or the upper right?

anyway, I actually assumed 4 values to clear a rectangle: x1, y1, x2, y2
... :?

and, BTW:
why is start then called "start"? isn't it more a "clear" ?
If you want to clear any other area then you need to clear it another way. WindowClear() clears the whole window AreaClear() clears a rectangle (both using the background colour set via a previous Background() or BackgroundRGB() both of which also clear the whole screen whilst setting the colour).

A rectangle does need 4 values, but Start() forces the bottom left to 0,0 and only lets you provide the top-right.

Start() does extra things like changes the background colour to white, clears the lower-left area, sets the fill and stroke colours to black, sets strokewidth to 0 and restores the current transform matrix to identity (i.e. no scale, translate, shear or rotation). I think it intended to be Start of a new frame, i.e. set various parameters back to a default setting. Unfortunately you can't choose what those defaults are.
She who travels light — forgot something.

davenull
Posts: 1162
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 1:29 pm

ok, so for clearing the area 100,100 to 200,200 would I also need to call
start(? which values?)
plus
AreaCkear(100,100, 200,200) ?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

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

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 2:01 pm

davenull wrote:ok, so for clearing the area 100,100 to 200,200 would I also need to call
start(? which values?)
plus
AreaCkear(100,100, 200,200) ?
You only need to use Start() if you want the other things it does as well. If you only want to clear 100,100 to 200,200 and are happy to either change the other settings yourself or want to leave them alone then just use AreaClear(100,100, 101,101); AreaClear's last two parameters are width,height not absolute coordinates and 100->200 inclusive is 101 pixels. I think calling Start(0,0) would not clear any area and just set the other things (I can't remember off hand how it deals with a zero size rect).
She who travels light — forgot something.

davenull
Posts: 1162
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 2:18 pm

aaaha. Now the darkness clears up.
Thank you very much! :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

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

Re: why initWindowSize, why init, and why Start ?

Sun Apr 17, 2016 2:44 pm

davenull wrote:aaaha. Now the darkness clears up.
Thank you very much! :)
I've just checked, it's an error to pass 0 for either the width or height to Start() or AreaClear().
So at the very minimum Start() has to be Start(1,1) which will clear the bottom-left pixel 0,0.
She who travels light — forgot something.

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 4 guests