拷贝纹理的两种方式

  1. 获取纹理再拷贝
unsigned char * data = new unsigned char[normal_texture.width*normal_texture.Hight*4];
glBindTexture(GL_TEXTURE_2D,src_id);
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
glBindTexture(GL_TEXTURE_2D,dest_id);glTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
glBindTexture(GL_TEXTURE_2D,0);
  1. FBO拷贝
GLuint fbo;glGenFramebuffers(1,&fbo);
/// bind the FBO
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
/// attach the source texture to the fbo
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src_id, 0);
/// bind the destination texture
glBindTexture(GL_TEXTURE_2D, dest_id);
/// copy from framebuffer (here, the FBO!) to the bound texture
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width,height);
/// unbind the FBO
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D,0);

你可能感兴趣的:(拷贝纹理的两种方式)