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

Doesn't work on Mac #30

Closed
CjPhoenix opened this issue Mar 22, 2022 · 44 comments
Closed

Doesn't work on Mac #30

CjPhoenix opened this issue Mar 22, 2022 · 44 comments

Comments

@CjPhoenix
Copy link

My gui works fine on a Windows laptop, but I tested it on my MacBook and suddenly the modules inside the categories wouldn't render (They seem to be displaced by twice the distance they should be).

@lukflug
Copy link
Owner

lukflug commented Mar 22, 2022

I do not own a mac, so I can't reproduce that issue and solve it.
Could you send a few screenshots of the issue?

@CjPhoenix
Copy link
Author

This screen recording should show enough; if you want me to try anything, just let me know.

@lukflug
Copy link
Owner

lukflug commented Mar 23, 2022

Does this only happen on 1.18.2. Could you try running it on 1.17.1?
In any case, the root cause of the problem probably lies in the class GLInterface.
Namely the methods scissor and guiToScreen.
So when instantiating that class, it should work by overriding scissor and guiToScreen in some way.

Could you print out MinecraftClient.getInstance().getWindow().getWidth(), MinecraftClient.getInstance().getWindow().getScaledWidth() (and the corresponding methods for height)?

@CjPhoenix
Copy link
Author

CjPhoenix commented Mar 23, 2022

Output on 1.18.2:

Window width: 854
Window scaled width: 427
Window height: 480
Window scaled height: 240

Output on 1.17.1:

Window width: 854
Window scaled width: 427
Window height: 480
Window scaled height: 240

I didn't include a new visual for 1.17.1, because it produces the same issue.

@lukflug
Copy link
Owner

lukflug commented Mar 23, 2022

Does the (non-scaled) width/height approximately correspond to the actual Minecraft window size in pixels?
And is your GUI size set to 2?
Could you try out other GUI sizes?

@CjPhoenix
Copy link
Author

The scale lines up, and I've tried all the different GUI scales, (they all render the same error).

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

So when instantiating the Interface here add following method to the anonymous class:

@Override
protected void scissor (Rectangle r) {
    width = MinecraftClient.getInstance().getWindow().getWidth();
    height = MinecraftClient.getInstance().getWindow().getWidth();
    GL11.glScissor(0,0,100,100);
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
}

And then open a category and move it around until something appears (it doesn't have to necessarily be inside the category outline). Please report the location and size of the rectangle in which it appears.

Then vary the arguments of glScissor (the first two are x and y position, the last two are width and height):

GL11.glScissor(100,100,100,100);
GL11.glScissor(0,0,width/2,height/2);
GL11.glScissor(width/2,height/2,width/2,height/2);
GL11.glScissor(0,0,width,height);

I hope this information will help me get to the bottom of this issue.

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

Also, thank you very much for your patience and cooperation so far!

@CjPhoenix
Copy link
Author

Of course! However, I'm not quite sure how to add the method you asked, because I can't edit the library (It's included as an external library). Is there a different way I should include the code?

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

There's no need to edit the library. When instantiating an instance of GuiInterface, you can override the method. Here is the place where it is done in the example mod:
image

@CjPhoenix
Copy link
Author

I found a solution that fixed the background, but on the closing of the category it crashes the game, so I'm gonna keep trying.

@CjPhoenix
Copy link
Author

Update: using this method "works," but causes an issue where if a module's settings are open, they will continue to render outside of the category's frame while the module is opened.

@Override
protected void scissor (Rectangle r) {
	if (r==null) {
		GL11.glScissor(0,0,0,0);
		GL11.glEnable(GL11.GL_SCISSOR_TEST);
		return;
	}
	width = MinecraftClient.getInstance().getWindow().getScaledWidth();
	height = MinecraftClient.getInstance().getWindow().getScaledHeight();
	double scaleFactor = MinecraftClient.getInstance().getWindow().getScaleFactor();
	GL11.glScissor((int) (r.x * scaleFactor), (int) -(r.y * scaleFactor), (int) (r.width * scaleFactor), (int) (height * scaleFactor));
	GL11.glEnable(GL11.GL_SCISSOR_TEST);
}

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

Yeah, the scissor method is responsible for selecting the right rectangle for it not to do that.
The problem is that the function transforming from GUI coordinates to screen pixels is wrong, so it either display too much or too little.
Does that cut anything or are all modules visible?
The solution to this entire issue is figuring out how the values that one plugs into glScissor map to the screen.

@CjPhoenix
Copy link
Author

Sorry, I don't really understand what you're asking for. Could you rephrase that?

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

The glScissor takes x, y, width, height values in pixels. However those pixels do not correspond to the values in the rectangle r passed as an argument for this method. The point of that method it to tell OpenGL to only draw pixels inside the category frame and ignore all pixels outside, so nothing is rendered outside the frame.
For whatever reason it seems to work differently on Macs.
What I'm trying to figure out, is how it behaves.

I was asking whether your solution cuts any part of the category out, or if it just renders all of the modules outside. I suspect it is not doing anything, because the y-value is negative.
This is why I was earlier asking for you to try out all those variants, I need to figure out what coordinates I need to pass to glScissor to obtain each corner.
image

@CjPhoenix
Copy link
Author

It doesn't appear to cut any part of the category out.

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

Ok, so what happens if you make the y-value positive? I presume it regresses to what you had originally.
So what happens if you scissor a square of 100x100 at 0,0 (i.e. GL11.glScissor(0,0,100,100))?
In what corner of the screen would the content of the category become visible and how large is that square?

@CjPhoenix
Copy link
Author

  1. When the y-value was positive, it flipped the background such that if I placed the category at the top of the screen, the background would be at the bottom (and vice versa). I believe I know why (which you will see in my next answer).
  2. When I scissor a square of 100x100 at (0,0), it places the square in the bottom-left corner and the size varies depending on the gui scale, but it's small/medium sized.

What I can't figure out is that the fourth argument in GL11.glscissor() has to be the window height, not r.height or else the modules' settings will not render (Doesn't make an issue bc I have a solution, but it might help in your problem solving).

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

ok, assuming it's bottom left and scales with GUI scale, this will hopefully work:

GL11.glScissor(r.x,MinecraftClient.getInstance().getWindow().getHeight()-r.y,r.width,r.height);

@CjPhoenix
Copy link
Author

Nope:
Screen Shot 2022-03-24 at 3 34 21 PM

@CjPhoenix
Copy link
Author

Also, unrelated issue: How do I drag a module back onto the screen when the top of it isn't on the screen?

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

Dragging it back on to screen is typically done by a "fixgui" command, implemented by the client, which resets the position of panels.

@lukflug
Copy link
Owner

lukflug commented Mar 24, 2022

oh, wait, I think I did a mistake, try:

GL11.glScissor(r.x,MinecraftClient.getInstance().getWindow().getHeight()-r.y-r.height,r.width,r.height);

@CjPhoenix
Copy link
Author

Still nope :/

@CjPhoenix
Copy link
Author

I can give you another image but it looks pretty much the same

@lukflug
Copy link
Owner

lukflug commented Mar 25, 2022

I have noticed some parts of Minecraft do it through RenderSystem, maybe all this was a conflict with Minecraft's own bookkeeping:

@override
protected void scissor (Rectangle r) {
	if (r==null) {
		RenderSystem.enableScissor(0,0,0,0);
		return;
	}
	Point a=guiToScreen(r.getLocation()),b=guiToScreen(new Point(r.x+r.width,r.y+r.height));
	if (!clipX) {
		a.x=0;
		b.x=MinecraftClient.getInstance().getWindow().getWidth();
	}
	RenderSystem.enableScissor(Math.min(a.x,b.x),Math.min(a.y,b.y),Math.abs(b.x-a.x),Math.abs(b.y-a.y));
}

@Override
public void restore() {
	if (!clipRect.isEmpty()) {
		clipRect.pop();
		if (clipRect.isEmpty()) RenderSystem.disableScissor();
		else scissor(clipRect.peek());
	}
}

@CjPhoenix
Copy link
Author

clipRect is showing up as an undeclared variable in your second method, so I can't test it...

@CjPhoenix
Copy link
Author

CjPhoenix commented Mar 25, 2022

So... I found clipRect's declaration and redeclared it locally.

However...
XD I don't even know what happened, but when I opened the category it made the screen start flashing and nothing was in the right place. Tbh my earlier solution seems pretty good; all I would need to add is a way for children to clip to the frame of their parents.

@lukflug
Copy link
Owner

lukflug commented Mar 25, 2022

all I would need to add is a way for children to clip to the frame of their parents

this is what I'm trying to figure out, the part that was broken is the part that does this clipping
your solution effectively disables it

@lukflug
Copy link
Owner

lukflug commented Mar 25, 2022

clipRect is showing up as an undeclared variable in your second method, so I can't test it...

Sorry, I forgot to take that into account:

private final Stack<Rectangle> clipRect=new Stack<Rectangle>();

@Override
protected void scissor (Rectangle r) {
	if (r==null) {
		GL11.glScissor(0,0,0,0);
		GL11.glEnable(GL11.GL_SCISSOR_TEST);
		return;
	}
	Point a=guiToScreen(r.getLocation()),b=guiToScreen(new Point(r.x+r.width,r.y+r.height));
	if (!clipX) {
		a.x=0;
		b.x=MinecraftClient.getInstance().getWindow().getWidth();
	}
	GL11.glScissor(Math.min(a.x,b.x),Math.min(a.y,b.y),Math.abs(b.x-a.x),Math.abs(b.y-a.y));
	GL11.glEnable(GL11.GL_SCISSOR_TEST);
}

@Override
public void window (Rectangle r) {
	if (clipRect.isEmpty()) {
		scissor(r);
		clipRect.push(r);
	} else {
		Rectangle top=clipRect.peek();
		if (top==null) {
			scissor(null);
			clipRect.push(null);
		} else {
			int x1,y1,x2,y2;
			x1=Math.max(r.x,top.x);
			y1=Math.max(r.y,top.y);
			x2=Math.min(r.x+r.width,top.x+top.width);
			y2=Math.min(r.y+r.height,top.y+top.height);
			if (x2>x1 && y2>y1) {
				Rectangle rect=new Rectangle(x1,y1,x2-x1,y2-y1);
				scissor(rect);
				clipRect.push(rect);
			} else {
				scissor(null);
				clipRect.push(null);
			}
		}
	}
}

@Override
public void restore() {
	if (!clipRect.isEmpty()) {
		clipRect.pop();
		if (clipRect.isEmpty()) GL11.glDisable(GL11.GL_SCISSOR_TEST);
		else scissor(clipRect.peek());
	}
}

@CjPhoenix
Copy link
Author

That produces both issues:

  1. The first problem I had with rendering the background in the correct position
  2. The second problem of the modules spilling out too far vertically

@CjPhoenix
Copy link
Author

Can you check if the modules render outside of the category's frame too far on windows? I can't get to my (windows) laptop rn bc I'm at school, but I want to see if this is an issue outside of macos.

@lukflug
Copy link
Owner

lukflug commented Mar 25, 2022

Ok, I've tested it on Windows, and noticed I pasted the wrong code:

private final Stack<Rectangle> clipRect=new Stack<Rectangle>();

@Override
protected void scissor (Rectangle r) {
	if (r==null) {
		RenderSystem.enableScissor(0,0,0,0);
		return;
	}
	Point a=guiToScreen(r.getLocation()),b=guiToScreen(new Point(r.x+r.width,r.y+r.height));
	if (!clipX) {
		a.x=0;
		b.x=MinecraftClient.getInstance().getWindow().getWidth();
	}
	RenderSystem.enableScissor(Math.min(a.x,b.x),Math.min(a.y,b.y),Math.abs(b.x-a.x),Math.abs(b.y-a.y));
}

@Override
public void window (Rectangle r) {
	if (clipRect.isEmpty()) {
		scissor(r);
		clipRect.push(r);
	} else {
		Rectangle top=clipRect.peek();
		if (top==null) {
			scissor(null);
			clipRect.push(null);
		} else {
			int x1,y1,x2,y2;
			x1=Math.max(r.x,top.x);
			y1=Math.max(r.y,top.y);
			x2=Math.min(r.x+r.width,top.x+top.width);
			y2=Math.min(r.y+r.height,top.y+top.height);
			if (x2>x1 && y2>y1) {
				Rectangle rect=new Rectangle(x1,y1,x2-x1,y2-y1);
				scissor(rect);
				clipRect.push(rect);
			} else {
				scissor(null);
				clipRect.push(null);
			}
		}
	}
}

@Override
public void restore() {
	if (!clipRect.isEmpty()) {
		clipRect.pop();
		if (clipRect.isEmpty()) RenderSystem.disableScissor();
		else scissor(clipRect.peek());
	}
}

The previous one didn't use RenderSystem and was essentially the same as the original.

@CjPhoenix
Copy link
Author

This screwed up the screen even more... It caused Minecraft to only render a little square on the screen and everything else was just a strobe; I managed to exit the world through guess and check of the button's locations and only that little square would show part of the menu (the rest was still the word going crazy).

@lukflug
Copy link
Owner

lukflug commented Mar 25, 2022

I'll try it on Linux tomorrow and see if the issue appears there as well.
Otherwise I can't do much about it until I get hold of a Mac or something.

@lukflug
Copy link
Owner

lukflug commented Mar 26, 2022

I tested it on Linux and unfortunately it worked fine.
I asked a couple of fellow utility mod devs for assistance.
Unfortunately, I don't know what else to do.
Well, there's one last idea of just overriding screenToGui and using getFramebufferWidth and getFramebufferHeight instead of getWidth and getHeight:

@Override
public Point screenToGui (Point p) {
	int resX=getWindowSize().width;
	int resY=getWindowSize().height;
	return new Point(p.x*resX/MinecraftClient.getInstance().getWindow().getFramebufferWidth(),resY-p.y*resY/MinecraftClient.getInstance().getWindow().getFramebufferHeight()-1);
}

@master7720
Copy link

My gui works fine on a Windows laptop, but I tested it on my MacBook and suddenly the modules inside the categories wouldn't render (They seem to be displaced by twice the distance they should be).

heres a fix dont use macOS

@Z3R0-cmd
Copy link

Z3R0-cmd commented Apr 5, 2022

My gui works fine on a Windows laptop, but I tested it on my MacBook and suddenly the modules inside the categories wouldn't render (They seem to be displaced by twice the distance they should be).

heres a fix dont use macOS

vouch, it worked

@CjPhoenix
Copy link
Author

heres a fix dont use macOS

vouch, it worked

First off, I already found a solution I didn’t care to share with people like you. Second, this thread is for people who care enough to contribute helpful comments and suggestions to assist in solving an issue; if all you have to provide is a sarcastic comment that doesn’t lead to the solution, please refrain from submitting any ideas on this issue. Thanks!

@lukflug
Copy link
Owner

lukflug commented Apr 6, 2022

Could you please share your solution, so that I might be able to push a fix to the library or assist other people who might have this issue in the future?

@CjPhoenix
Copy link
Author

Sorry, I didn't see this

I'm using the solution I posted earlier, and then I have the panels pop out on the sides instead of in the main area. It works the same way on Mac and Windows, and the scissor function override I made earlier functions correctly on Mac and Windows.

@master7720
Copy link

heres a fix dont use macOS

vouch, it worked

First off, I already found a solution I didn’t care to share with people like you. Second, this thread is for people who care enough to contribute helpful comments and suggestions to assist in solving an issue; if all you have to provide is a sarcastic comment that doesn’t lead to the solution, please refrain from submitting any ideas on this issue. Thanks!

It is a helpful commit dont use macOS

@srgantmoomoo
Copy link

heres a fix dont use macOS

vouch, it worked

First off, I already found a solution I didn’t care to share with people like you. Second, this thread is for people who care enough to contribute helpful comments and suggestions to assist in solving an issue; if all you have to provide is a sarcastic comment that doesn’t lead to the solution, please refrain from submitting any ideas on this issue. Thanks!

It is a helpful commit dont use macOS

about as helpful as sending supplies to the Ukraine.

@master7720
Copy link

heres a fix dont use macOS

vouch, it worked

First off, I already found a solution I didn’t care to share with people like you. Second, this thread is for people who care enough to contribute helpful comments and suggestions to assist in solving an issue; if all you have to provide is a sarcastic comment that doesn’t lead to the solution, please refrain from submitting any ideas on this issue. Thanks!

It is a helpful commit dont use macOS

about as helpful as sending supplies to the Ukraine.

I mean come on dude macOS is TRASH use linux or windows

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

5 participants