Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofCairoRenderer stops working after setting ofScale(0, 0); #6715

Closed
dimitre opened this issue Mar 23, 2021 · 5 comments
Closed

ofCairoRenderer stops working after setting ofScale(0, 0); #6715

dimitre opened this issue Mar 23, 2021 · 5 comments
Milestone

Comments

@dimitre
Copy link
Member

dimitre commented Mar 23, 2021

I've noticed ofCairoRenderer stops working after setting ofScale(0, 0)
Maybe there is some destructive scale happening there. easy to reproduce.
Thanks

@arturoc
Copy link
Member

arturoc commented Mar 25, 2021

I imagine what you mean is that it doesn't work afterwards even changing back the scale? It might be introducing some NaNs and never recover from it

@dimitre
Copy link
Member Author

dimitre commented Mar 25, 2021

@arturoc yes this is what I mean.

@ofTheo ofTheo added this to the 0.12.0 milestone Apr 6, 2021
@ofTheo ofTheo mentioned this issue Apr 6, 2021
77 tasks
@dimitre
Copy link
Member Author

dimitre commented May 21, 2022

EDIT: found some more details.
Cairo preserves the matrix (translate, scale) across frames, so if you actually call something like:

	ofScale(0.5, 0.5);
	ofDrawCircle(100,100,100);

it accumulates, shrinking the size. The same happens with ofTranslate
one way of solving it would be reseting matrix before each draw, something like

		cairo_matrix_t matrix;
		cairo_matrix_init_scale(&matrix,xAmnt,yAmnt);
		cairo_set_matrix(cr,&matrix);

and the same for translation.

but this is almost like another issue.
The original issue pointed here is related to Cairo itself,
not very beautiful but if we want to contour this issue we can do something like :

void ofCairoRenderer::scale(float xAmnt, float yAmnt, float zAmnt ){
		if (xAmnt == 0 || yAmnt == 0) return;

ideas?

@dimitre
Copy link
Member Author

dimitre commented May 22, 2022

one possible solution is adding some lines to setupGraphicsDefaults, so it resets the matrix in new frames.
But only if we start using cairo with the second optional parameter = true

ofSetCurrentRenderer(cairo, true);
//----------------------------------------------------------
void ofCairoRenderer::setupGraphicDefaults(){
	setStyle(ofStyle());
	path.setMode(ofPath::COMMANDS);
	path.setUseShapeColor(false);
	clear();
	
// new lines
	cairo_matrix_t matrix;
	cairo_matrix_init_scale(&matrix, 1.0, 1.0);
	cairo_matrix_init_translate(&matrix, 0.0, 0.0);
	cairo_set_matrix(cr,&matrix);
};

@dimitre
Copy link
Member Author

dimitre commented May 28, 2022

Closed by #6991

@dimitre dimitre closed this as completed May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants