[英]Copy part of texture to another texture OpenGL 4.6 C++
如果我必須紋理 ID
SrcID
和DestID
如何將 srcID 的一部分復制到 DestId
給定要復制的部分的歸一化坐標,src 和 dest 的寬度和高度
normailsed 我的意思是它們在 0 和 1 之間
您可以為此使用 glCopyImageSubData。
glCopyImageSubData(SrcID, GL_TEXTURE_2D, 0, 0, 0, 0,
DestID, GL_TEXTURE_2D, 0, 0, 0, 0,
width, height, 1);
您可以將紋理附加到幀緩沖區,然后使用glBlitFramebuffer
。 我無法測試下面的代碼,但它應該是正確的。 您只需要以像素為單位指定坐標,但很容易通過將歸一化坐標乘以紋理尺寸來計算。
GLuint FboID;
glGenFramebuffers(1, &FboID);
glBindFramebuffer(GL_FRAMEBUFFER, FboID);
// Attach the textures to atttachment slots
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, SrcID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, DestID, 0);
// Prepare to read from first attachment (src texture)
// and draw into second attachment (dst texture)
glReadBuffer(GL_COLOR_ATTACHMENT0);
GLenum[] DstBuffer = { GL_COLOR_ATTACHMENT1 };
glDrawBuffers(1, &DstBuffer);
// Fill those pixel coordinates from your normalized coordinates
// (e.g. srcX0 = 0.2f * srcWidth)
GLint srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1;
glBlitFramebuffer(
srcX0, srcY0,
srcX1, srcY1,
dstX0, dstY0,
dstX1, dstY1
GL_COLOR_BUFFER_BIT,
GL_LINEAR);
glBindFramebuffer(GL_FRAMEBUFFER, 0); // disable FBO
// optionally delete FBO, if you won't need it anymore
// glDeleteFramebuffers(1, &FboID);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.