Draw the GuiVideoRenderer on a separate framebuffer that has the actual size of the window instead of MC's framebuffer which may have a different size
This commit is contained in:
@@ -20,6 +20,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.audio.SoundCategory;
|
import net.minecraft.client.audio.SoundCategory;
|
||||||
import net.minecraft.client.gui.ScaledResolution;
|
import net.minecraft.client.gui.ScaledResolution;
|
||||||
import net.minecraft.client.renderer.OpenGlHelper;
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
|
import net.minecraft.client.shader.Framebuffer;
|
||||||
import net.minecraft.util.Timer;
|
import net.minecraft.util.Timer;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.opengl.Display;
|
import org.lwjgl.opengl.Display;
|
||||||
@@ -62,6 +63,9 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
private boolean paused;
|
private boolean paused;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
|
private Framebuffer guiFramebuffer;
|
||||||
|
private int displayWidth, displayHeight;
|
||||||
|
|
||||||
public VideoRenderer(RenderSettings settings, ReplayHandler replayHandler, Timeline timeline) throws IOException {
|
public VideoRenderer(RenderSettings settings, ReplayHandler replayHandler, Timeline timeline) throws IOException {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.replayHandler = replayHandler;
|
this.replayHandler = replayHandler;
|
||||||
@@ -130,6 +134,13 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float updateForNextFrame() {
|
public float updateForNextFrame() {
|
||||||
|
// because the jGui lib uses Minecraft's displayWidth and displayHeight values, update these temporarily
|
||||||
|
int displayWidthBefore = mc.displayWidth;
|
||||||
|
int displayHeightBefore = mc.displayHeight;
|
||||||
|
|
||||||
|
mc.displayWidth = displayWidth;
|
||||||
|
mc.displayHeight = displayHeight;
|
||||||
|
|
||||||
if (!settings.isHighPerformance() || framesDone % fps == 0) {
|
if (!settings.isHighPerformance() || framesDone % fps == 0) {
|
||||||
drawGui();
|
drawGui();
|
||||||
}
|
}
|
||||||
@@ -142,6 +153,10 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// change Minecraft's display size back
|
||||||
|
mc.displayWidth = displayWidthBefore;
|
||||||
|
mc.displayHeight = displayHeightBefore;
|
||||||
|
|
||||||
framesDone++;
|
framesDone++;
|
||||||
return mc.timer.renderPartialTicks;
|
return mc.timer.renderPartialTicks;
|
||||||
}
|
}
|
||||||
@@ -192,10 +207,15 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
|
|
||||||
totalFrames = (int) (duration*fps/1000);
|
totalFrames = (int) (duration*fps/1000);
|
||||||
|
|
||||||
ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
updateDisplaySize();
|
||||||
|
|
||||||
|
ScaledResolution scaled = new ScaledResolution(mc, displayWidth, displayHeight);
|
||||||
gui.toMinecraft().setWorldAndResolution(mc, scaled.getScaledWidth(), scaled.getScaledHeight());
|
gui.toMinecraft().setWorldAndResolution(mc, scaled.getScaledWidth(), scaled.getScaledHeight());
|
||||||
|
|
||||||
chunkLoadingRenderGlobal = new ChunkLoadingRenderGlobal(mc.renderGlobal);
|
chunkLoadingRenderGlobal = new ChunkLoadingRenderGlobal(mc.renderGlobal);
|
||||||
|
|
||||||
|
// Set up our own framebuffer to render the GUI to
|
||||||
|
guiFramebuffer = new Framebuffer(displayWidth, displayHeight, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finish() {
|
private void finish() {
|
||||||
@@ -219,6 +239,9 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
ReplayMod.soundHandler.playRenderSuccessSound();
|
ReplayMod.soundHandler.playRenderSuccessSound();
|
||||||
|
|
||||||
new GuiRenderingDone(ReplayModRender.instance, videoWriter.getVideoFile(), totalFrames, settings).display();
|
new GuiRenderingDone(ReplayModRender.instance, videoWriter.getVideoFile(), totalFrames, settings).display();
|
||||||
|
|
||||||
|
// Finally, resize the Minecraft framebuffer to the actual width/height of the window
|
||||||
|
mc.resize(displayWidth, displayHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tick() {
|
private void tick() {
|
||||||
@@ -238,12 +261,22 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
|
|
||||||
public void drawGui() {
|
public void drawGui() {
|
||||||
do {
|
do {
|
||||||
|
// Resize the GUI framebuffer if the display size changed
|
||||||
|
if (!settings.isHighPerformance() && displaySizeChanged()) {
|
||||||
|
updateDisplaySize();
|
||||||
|
guiFramebuffer.createBindFramebuffer(mc.displayWidth, mc.displayHeight);
|
||||||
|
}
|
||||||
|
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
enableTexture2D();
|
enableTexture2D();
|
||||||
mc.getFramebuffer().bindFramebuffer(true);
|
guiFramebuffer.bindFramebuffer(true);
|
||||||
|
|
||||||
mc.entityRenderer.setupOverlayRendering();
|
mc.entityRenderer.setupOverlayRendering();
|
||||||
|
|
||||||
|
ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
gui.toMinecraft().setWorldAndResolution(mc, scaled.getScaledWidth(), scaled.getScaledHeight());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
gui.toMinecraft().handleInput();
|
gui.toMinecraft().handleInput();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -252,18 +285,17 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
|
||||||
int mouseX = Mouse.getX() * scaled.getScaledWidth() / mc.displayWidth;
|
int mouseX = Mouse.getX() * scaled.getScaledWidth() / mc.displayWidth;
|
||||||
int mouseY = scaled.getScaledHeight() - Mouse.getY() * scaled.getScaledHeight() / mc.displayHeight - 1;
|
int mouseY = scaled.getScaledHeight() - Mouse.getY() * scaled.getScaledHeight() / mc.displayHeight - 1;
|
||||||
|
|
||||||
gui.toMinecraft().drawScreen(mouseX, mouseY, 0);
|
gui.toMinecraft().drawScreen(mouseX, mouseY, 0);
|
||||||
|
|
||||||
mc.getFramebuffer().unbindFramebuffer();
|
guiFramebuffer.unbindFramebuffer();
|
||||||
popMatrix();
|
popMatrix();
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
mc.getFramebuffer().framebufferRender(mc.displayWidth, mc.displayHeight);
|
guiFramebuffer.framebufferRender(displayWidth, displayHeight);
|
||||||
popMatrix();
|
popMatrix();
|
||||||
|
|
||||||
|
|
||||||
// if not in high performance mode, update the gui size if screen size changed
|
// if not in high performance mode, update the gui size if screen size changed
|
||||||
// otherwise just swap the progress gui to screen
|
// otherwise just swap the progress gui to screen
|
||||||
if (settings.isHighPerformance()) {
|
if (settings.isHighPerformance()) {
|
||||||
@@ -285,6 +317,15 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
} while (paused);
|
} while (paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean displaySizeChanged() {
|
||||||
|
return displayWidth != Display.getWidth() || displayHeight != Display.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDisplaySize() {
|
||||||
|
displayWidth = Display.getWidth();
|
||||||
|
displayHeight = Display.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
public int getFramesDone() {
|
public int getFramesDone() {
|
||||||
return framesDone;
|
return framesDone;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user