FBO lwjgl bigger than Screen Size - What I'm d

2019-06-05 08:31发布

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.

First part of code is the way I create FBO, I do the rendering between activate, and deactivate. Later I use texture.

What am I doing wrong?

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 settings:

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);
}

标签: size lwjgl fbo
1条回答
▲ chillily
2楼-- · 2019-06-05 09:12

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);
}
查看更多
登录 后发表回答