2

注意:我正在使用 LWJGL。

这是我创建新 FBO 的代码:

/**
 * Creates a new FBO.
 * @param width The width of the FBO to create.
 * @param height The height of the FBO to create.
 * @return an int[] array containing the buffer IDs in the 
 * following order: {frameBufferID, colorBufferID (texture), depthBufferID}.
 */
public static int[] newFBO(int width, int height) {
    int[] out = new int[3];
    out[0] = glGenFramebuffersEXT();
    out[1] = glGenTextures();
    out[2] = glGenRenderbuffersEXT();

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, out[0]);

    glBindTexture(GL_TEXTURE_2D, out[1]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, org.lwjgl.opengl.GL12.GL_TEXTURE_MAX_LEVEL,20);
    glTexParameteri(GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP,GL_TRUE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,GL_RGBA, GL_INT, (java.nio.ByteBuffer) null);
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, out[1], 0);

    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, out[2]);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, width, height);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, out[2]);

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    return out;
}

这是我将 FBO 绘制到屏幕上的方法:

public static void rectOnScreen(int tex) {
    glBindTexture(GL_TEXTURE_2D, tex);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glLoadIdentity();
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0);
    glVertex2f(-1, -1);
    glTexCoord2f(0, 1);
    glVertex2f(-1, 1);
    glTexCoord2f(1, 1);
    glVertex2f(1, 1);
    glTexCoord2f(1, 0);
    glVertex2f(1, -1);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);
}

基本上,我使用 out[2] 作为该函数的参数。

现在,我如何在这里应用多重采样?我真的不喜欢我得到的结果的锯齿状外观。我想在绘制 FBO 时对它进行多个样本。我很乐意将代码写出来,但我想一个教程的链接或其他东西也很好。

4

0 回答 0