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

Fix y inversion on examples #638

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

Mifom
Copy link
Contributor

@Mifom Mifom commented Aug 26, 2023

When building project with current macroquad version I'd found issue with camera. When a camera is set, the screen got inverted y.
After that I've found #618 and checked other examples. I've found that not only platformer has inverted y, but also tree and arkanoid. This examples use Camera2D just like the platfornmer example. I've checked Camera2D code and found this inversion if not drawn on render target.

Am I right to remove inversion or this issues should be fixed other way?

@not-fl3
Copy link
Owner

not-fl3 commented Aug 27, 2023

Hi, thanks for PR, camera's Y sure is messed up!
Tho I am not quite sure if the proposed fix is really the solution: there are quite a few related problems #171

@Mifom
Copy link
Contributor Author

Mifom commented Aug 27, 2023

Okay, I'll look on related issues

@Mifom
Copy link
Contributor Author

Mifom commented Aug 28, 2023

I've done some research and found 3 issues related to this problem: #171, #578 and #618.

After reading code of the examples that use Camera2D I've found that in the letterbox example there is a flipping y axis with comment that render_target drawn upside down.
Also, the second issue gave me thought about fixing problem. So now all this issues can be fixed using this PR.

Although, I think that drawing into camera has issue on miniquad side when render_target is not set (that's why the if before setting zoom camera is present).

@Mifom
Copy link
Contributor Author

Mifom commented Sep 14, 2023

After looking at code of triangle example in miniquad I've found that in miniquad higher values of y means higher position on screen, whereas in macroquad higher values of y means lower position in screen. So we need to flip y axis to do correct drawing. For the default camera it is done by pixel_perfect_projection_matrix function.

The only problem for now is that if we want to draw on render target it's drawn upside down.

Currently this PR fixes issues #171, #578, #618: default camera is correct, examples drawn correctly. Also, zoom for camera can be set intuitively without rotating y (zoom: vec2(1, 1))

@not-fl3 I suppose this PR should be merged as is, I'll continue to work on render target issue on the miniquad side.

@BenMcAvoy
Copy link

So, I'm aware this was supposed to fix Y inversion but it used to work for me with zero issues. I'm now running the platformer example (copied into my own project with now changes) and it's inverted...

image

In the past when I ran this example (quite a while ago) things were fine. But I've noticed that it's upside down for me now.

@BenMcAvoy
Copy link

NOTE: I'm on Fedora 38, BSPWM, X11, Nvidia drivers.

@Mifom
Copy link
Contributor Author

Mifom commented Sep 17, 2023

In the past when I ran this example (quite a while ago) things were fine. But I've noticed that it's upside down for me now.

@BenMcAvoy Thanks for the running. So as I understood, if you run platformer example on the master branch you'll have correct y rotation, and on the current branch - inverted, right?

Can you also try letterbox example? It's doing both drawing onto render target and on the screen, so would be valuable info

@BenMcAvoy
Copy link

In the master branch, the platformer example is flipped. The letterbox example is not flipped.

image

@Mifom
Copy link
Contributor Author

Mifom commented Sep 17, 2023

In the master branch, the platformer example is flipped. The letterbox example is not flipped.

Well, that's strange that with master and fix_y_inversion branches you have identical results as in new branch I've flipped results.

NOTE: I've noticed that you've said

copied into my own project with now changes

... but there is no changes to platformer example, I've changed macroquad's camera logic.

@BenMcAvoy
Copy link

Ah, sorry. I pulled changes and everything is working great! Platformer example isn't flipped and neither is letterbox on your branch (fix_y_inversion). Seems to work great, well done!

@svenstaro
Copy link
Contributor

Could this get merged? The current flip is quite confusing and this fix seems sound.

@not-fl3
Copy link
Owner

not-fl3 commented Dec 5, 2023

This could be merged, but I am a little confused on how those axises should behave myself and where it is supposed to be up or down.

I want to collect all the questionable cases somewhere (maybe here? https://github.com/not-fl3/quadtest) before merging this.

but I am super slow with that :|

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

Successfully merging this pull request may close these issues.

4 participants