1
How do you create a framebuffer?
I'm trying to get a part of the world and display it with a framebuffer.
The current code that I tried uses the default Minecraft Framebuffer class, and the code looks like this
The old code looks like this
Both snippets wield the exact same results, nothing displays at all, but there are no errors. So I'm wondering how I can get it to render.
Thanks in advance!
The current code that I tried uses the default Minecraft Framebuffer class, and the code looks like this
Framebuffer framebuf = new Framebuffer(Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), true);
framebuf.framebufferRender(128, 128);
framebuf.deleteFramebuffer();
The old code looks like this
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
// Init ColorTex
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, colorTexID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), 0, GL_RGBA, GL_INT, (ByteBuffer) null);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexID, 0);
// Init Depth
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderID);
glRenderbufferStorage(GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderID);
// Set FBO pos
glClearColor(0.1f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, 0);
glViewport(0, 0, 640, 480);
glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(x, y, z + 5.0);
glRotated(rotX, 0.0, 1.0, 0.0);
glRotated(rotY, 1.0, 0.0, 0.0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Render FBO
glBindTexture(GL_TEXTURE_2D, colorTexID);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslated(0, 0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
glDeleteFramebuffers(fboID);
glDeleteRenderbuffers(depthRenderID);
glDeleteTextures(colorTexID);
Both snippets wield the exact same results, nothing displays at all, but there are no errors. So I'm wondering how I can get it to render.
Thanks in advance!
Create an account or sign in to comment.