1 定义帧缓冲变量名
//1.定义帧缓冲变量名
unsigned int gBuffer;
2 创建帧缓冲
2.创建帧缓冲
glGenFramebuffers(1, &gBuffer);
3 将帧缓冲绑定到GL_FRAMEBUFFER
//3.将帧缓冲绑定到GL_FRAMEBUFFER
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
4 将要存储的东西存储到帧缓冲中
//4.将gPosition纹理变量存储到刚创建的帧缓冲gbuffer中
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gPosition, 0);
5 整体代码如下:
//1.定义帧缓冲变量名
unsigned int gBuffer;
2.创建帧缓冲
glGenFramebuffers(1, &gBuffer);
//3.将帧缓冲绑定到GL_FRAMEBUFFER
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
unsigned int gPosition, gNormal, gAlbedo, gPortalMap;//要存储的变量
glGenTextures(1, &gPosition);//生成1个纹理
glBindTexture(GL_TEXTURE_2D, gPosition);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, WINDOW_WIDTH, WINDOW_HEIGHT, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//4.将gPosition纹理变量存储到刚创建的帧缓冲gbuffer中
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gPosition, 0);