Last active
February 12, 2020 16:41
-
-
Save RomiTT/2ab75d595c9a9c2550b50df8921cd0d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void copy_texture(GLuint srcTex, GLuint destTex, int width, int height) { | |
GLuint fboIds[2]; | |
glGenFramebuffers(2, fboIds); | |
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboIds[0]); | |
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, srcTex, 0); | |
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboIds[1]); | |
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTex, 0); | |
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); | |
//glBlitNamedFramebuffer(fboIds[0], fboIds[1], 0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); | |
glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
glDeleteFramebuffers(2, fboIds); | |
} | |
int width = 800; | |
int heght = 600; | |
glGenTextures(1, &tex1); | |
glBindTexture(GL_TEXTURE_2D, tex1); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
glBindTexture(GL_TEXTURE_2D, 0); | |
glGenTextures(1, &tex2); | |
glBindTexture(GL_TEXTURE_2D, tex2); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
glBindTexture(GL_TEXTURE_2D, 0); | |
copy_texture(tex1, tex2, width, height); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment