如何对FBOS进行多重采样

时间:2013-06-09 02:27:24

标签: opengl textures lwjgl fbo multisampling

注意:我正在使用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);
}

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

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

0 个答案:

没有答案