Closed CjPhoenix closed 2 years ago
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?
This screen recording should show enough; if you want me to try anything, just let me know.
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)?
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.
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?
The scale lines up, and I've tried all the different GUI scales, (they all render the same error).
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.
Also, thank you very much for your patience and cooperation so far!
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?
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:
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.
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);
}
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.
Sorry, I don't really understand what you're asking for. Could you rephrase that?
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.
It doesn't appear to cut any part of the category out.
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?
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).
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);
Nope:
Also, unrelated issue: How do I drag a module back onto the screen when the top of it isn't on the screen?
Dragging it back on to screen is typically done by a "fixgui" command, implemented by the client, which resets the position of panels.
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);
Still nope :/
I can give you another image but it looks pretty much the same
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());
}
}
clipRect
is showing up as an undeclared variable in your second method, so I can't test it...
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.
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
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());
}
}
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
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.
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.
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).
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.
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);
}
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
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
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!
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?
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.
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
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.
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
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).