Jump to content

[1.12.2] Game FrameBuffer problems


ShortByte

Recommended Posts

Hello guys,

 

I'm currently trying around with rendering the ingame screen into a UI.

For this I use the FrameBuffer of the game and render it over a new FrameBuffer.

So far so good. It also works, only as soon as I want to move it, the whole image distorts.

 

I tried a few things, but everything didn't really work.

 

My current code:

Framebuffer framebuffer = new Framebuffer(mc.displayWidth, mc.displayHeight, true);

Framebuffer framebufferMC = Minecraft.getMinecraft().getFramebuffer();
framebuffer.bindFramebuffer(true);

if(framebufferMC != null) {
  framebufferMC.bindFramebuffer(true);
} else {
  OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, 0);
}
framebuffer.bindFramebufferTexture();

int width = mc.displayWidth / 5 * 4;
int height = mc.displayHeight / 5 * 4;

if (OpenGlHelper.isFramebufferEnabled()) {
  GlStateManager.colorMask(true, true, true, false);
  GlStateManager.disableDepth();
  GlStateManager.depthMask(false);
  GlStateManager.matrixMode(5889);
  GlStateManager.loadIdentity();
  GlStateManager.ortho(0, (double) width, (double) height, 0.0D, 1000.0D, 3000.0D);
  GlStateManager.matrixMode(5888);
  GlStateManager.loadIdentity();
  GlStateManager.translate(0, 0, -2000.0F);
  GlStateManager.viewport(0, 0, width, height);
  GlStateManager.enableTexture2D();
  GlStateManager.disableLighting();
  GlStateManager.disableAlpha();
  GlStateManager.disableBlend();
  GlStateManager.enableColorMaterial();

  GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  framebufferMC.bindFramebufferTexture();

  float f2 = (float) framebufferMC.framebufferWidth / (float) framebufferMC.framebufferTextureWidth;
  float f3 = (float) framebufferMC.framebufferHeight / (float) framebufferMC.framebufferTextureHeight;

  Tessellator tessellator = Tessellator.getInstance();
  BufferBuilder bufferbuilder = tessellator.getBuffer();

  bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
  bufferbuilder
    .pos(0, (double) height, 0.0D)
    .tex(0.0D, 0.0D)
    .color(255, 255, 255, 255)
    .endVertex();
  bufferbuilder
    .pos((double) width, (double) height, 0.0D)
    .tex((double) f2, 0.0D)
    .color(255, 255, 255, 255)
    .endVertex();
  bufferbuilder
    .pos((double) width, 0.0D, 0.0D)
    .tex((double) f2, (double) f3)
    .color(255, 255, 255, 255)
    .endVertex();
  bufferbuilder
    .pos(0, 0.0D, 0.0D)
    .tex(0.0D, (double) f3)
    .color(255, 255, 255, 255)
    .endVertex();

  tessellator.draw();

  framebufferMC.unbindFramebufferTexture();
  GlStateManager.depthMask(true);
  GlStateManager.colorMask(true, true, true, true);
}

 

java_m2zWVy6WL5.png

java_pWE8a3V5az.png

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.