FBO lwjgl大于屏幕尺寸-我在做什么错? [英] FBO lwjgl bigger than Screen Size - What I'm doing wrong?
问题描述
我再次需要您的帮助.我想使用大于屏幕尺寸的帧缓冲对象.当我按以下方式进行操作时,FBO的尺寸1024 x 1024从分辨率1024 x 768的顶部开始被截断.我自己找不到解决方案-这就是我要问的原因.
I need your help again. I wanna use Frame Buffer Object bigger than the Screen size. When I do it as below FBO size 1024 x 1024 is cut off from the top in resolution 1024 x 768. I couldn't find the solution on my own - that's why I'm asking.
代码的第一部分是创建FBO的方法,即在激活和停用之间进行渲染.后来我使用纹理.
First part of code is the way I create FBO, I do the rendering between activate, and deactivate. Later I use texture.
我在做什么错了?
清除帧缓冲区对象以进行重用的最快方法是什么?
What is the fastest way to clear Frame Buffer Object for reuse?
public FrameBufferObject(int width, int height) {
this.width = width;
this.height = height;
texture = glGenTextures();
frameBufferObject = GL30.glGenFramebuffers();
activate();
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_BYTE, BufferUtils.createByteBuffer(4 * width * height));
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
deactivate();
}
public void activate() {
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferObject);
}
public void deactivate();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}
OpenGL设置:
private static void initializeOpenGL() {
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_MULTISAMPLE);
glEnable(GL_BLEND);
glEnable(GL_SCISSOR_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glClearColor(0, 0, 0, 0);
}
推荐答案
在绑定后和开始渲染之前,需要使用FBO尺寸调用glViewport()
.请注意,视口尺寸是全局状态,而不是每个帧缓冲区状态,因此,当您再次渲染到默认帧缓冲区时,还必须将它们重新设置.
You need to call glViewport()
with the FBO dimensions after binding it, and before starting to render. Note that the viewport dimensions are global state, not per-framebuffer state, so you also have to set them back when you render to the default framebuffer again.
使用您在问题中使用的数字(您显然不希望在实际代码中使用硬编码的数字):
With the numbers you use in the question (you obviously wouldn't want to use hardcoded numbers in real code):
public void activate() {
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferObject);
glViewport(0, 0, 1024, 1024);
}
public void deactivate();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
glViewport(0, 0, 1024, 768);
}
这篇关于FBO lwjgl大于屏幕尺寸-我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!