美文网首页
拷贝纹理的两种方式

拷贝纹理的两种方式

作者: gpr | 来源:发表于2016-08-11 20:29 被阅读586次
    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);
    

    相关文章

      网友评论

          本文标题:拷贝纹理的两种方式

          本文链接:https://www.haomeiwen.com/subject/fmessttx.html