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

Canvas's don't necessarily draw right-side-up. #252

Closed
icefoxen opened this issue Jan 10, 2018 · 3 comments

Comments

@icefoxen
Copy link
Contributor

commented Jan 10, 2018

See https://github.com/ggez/ggez/blob/master/examples/shadows.rs#L375-L383 for an example of such.

This is Yet Another Little Coordinate Goof that needs to be fixed. Once you fix it, make sure that things drawn on canvases such as text and images get drawn right-side-up still!

@icefoxen icefoxen referenced this issue Feb 23, 2018

Closed

To do for 0.4.1 #289

8 of 8 tasks complete
@icefoxen

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2018

They totally don't draw right-side up, sigh. And fixing that means they flip on awkward axes for some stupid reason. I suspect the exciting stuff happens on DrawParams::into_matrix() IIRC, but it's still a PITA.

The following code makes render_to_image draw in the right spot, but breaks shadows even when you remove the existing hack to make things draw upright:

impl Drawable for Canvas {
    fn draw_ex(&self, ctx: &mut Context, param: DrawParam) -> GameResult<()> {
        let mut flipped_param = param;
        flipped_param.scale.y *= -1.0;
        flipped_param.dest.y += self.image.height() as f32 / 2.0;
        self.image.draw_ex(ctx, flipped_param)
    }
    ...
}
@termhn

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2018

Hmm. I think this could be caused by a coordinate transformation happening twice. IIRC: we do the first coordinate transformation when we draw onto the canvas by making it have "top left = 0,0 with pixel coordinates", then we apply that same transformation again when drawing the canvas onto the main render target. Perhaps we should disable the first set of coordinate transformations for canvases. I've only thought about this for a couple minutes and haven't been in the ggez world for a little while but this is what I suspect is the root cause of the issue.

@icefoxen

This comment has been minimized.

Copy link
Contributor Author

commented Mar 11, 2018

Started working on this in commit d6ef5b7

I hate coordinate transforms so so much. augh.

icefoxen added a commit that referenced this issue Mar 14, 2018

FIXED canvas coordinate problem.
Resolves #252

Woohoo!

It was a dumb mistake, of course.

@icefoxen icefoxen closed this Mar 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.