Framebuffers - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Framebuffers

References

Setup Framebuffer

References

Create Framebuffer Render Target

GLuint framebufferId = 0;
glGenFramebuffers(1, &framebufferId);  
glBindFramebuffer(GL_FRAMEBUFFER, framebufferId);

Attach Textures To Framebuffer

Continuing from above create a new texture (single channel float initialized to a background value) and attach it to the framebuffer.

GLuint texId;
glGenTextures(1, &texId);

std::vector<GLfloat> buffer(width * height, backgroundValue);
glBindTexture(GL_TEXTUE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, height, 0, format, GL_FLOAT, buffer.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texId, 0);

To attach multiple textures then use the glFramebufferTexture2D attachment parameter GL_COLOR_ATTACHMENTN where N is 0 or higher.

⚠️ **GitHub.com Fallback** ⚠️