Problem rendering to a texture

Started by
3 comments, last by SelethD 11 years, 5 months ago
I need to take sections of several source textures, and render them onto a destination texture, then each time through the render loop, i just draw the destination texture to my screen.

It is working now... in a way, just one little problem, that I really cant seem to figure out.

Lets imagine that my destination texture is empty (transparent even)
If i blit a solid texture onto destination
then i blit a texture with some transparency onto destination
somehow the transparency is blitted also, so that my destination ends up with 'holes' in if, where the transparency was copied.

is there a way to blit only the color values and not the transparency in the source textures.

here is my code for the blit, dont know if it helps
[source lang="cpp"]void cDuGlobals::GLBlit(int srcx,int srcy,int srcw,int srch,sDuTexture* src,int dstx,int dsty,sDuTexture* dst)
{
GLuint fboName;
glGenFramebuffers(1, &fboName);
// enable this frame buffer as the current frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, fboName);// attach the textures to the frame buffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src->textureID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, dst->textureID, 0);
GLenum fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE)
{
printf("FrameBuffer incomplete: 0x%x\n", fboStatus);
return;
}
glReadBuffer(GL_COLOR_ATTACHMENT0);
GLenum bufferlist[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(1, &bufferlist[1]);
glBlitFramebuffer(srcx,srcy,srcx+srcw,srcy+srch,dstx,dsty,dstx+srcw,dsty+srch,GL_COLOR_BUFFER_BIT,GL_NEAREST);
//glBlitFramebuffer(srcx,srcy,srcx+srcw-1,srcy+srch-1,dstx,dsty,dstx+srcw-1,dsty+srch-1,GL_COLOR_BUFFER_BIT,GL_NEAREST);
glDeleteFramebuffers(1, &fboName);
}
[/source]
Thanks for any help
Advertisement
The reason for the holes are most likely an alpha channel. Try to mask the alpha channel out by
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE);
It is a problem with alpha channels, I'm not so sure I know where to put that glColorMask statement ... I tried various locations in my GLBlit function, but was met with the same results.

Here is visual example of the problem, Im not the best at explaining in words.

9upta1.jpg
Ahh, you want blending. I'm not really familiar with the blitting functions, but I would try to use blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

and don't forget to enable blending, your code should look like:


void cDuGlobals::GLBlit(int srcx,int srcy,int srcw,int srch,sDuTexture* src,int dstx,int dsty,sDuTexture* dst)
{
GLuint fboName;
glGenFramebuffers(1, &fboName);
// enable this frame buffer as the current frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, fboName);// attach the textures to the frame buffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src->textureID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, dst->textureID, 0);
GLenum fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE)
{
printf("FrameBuffer incomplete: 0x%x\n", fboStatus);
return;
}
glReadBuffer(GL_COLOR_ATTACHMENT0);
GLenum bufferlist[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(1, &bufferlist[1]);

// enable alpha blending
glEnable( GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBlitFramebuffer(srcx,srcy,srcx+srcw,srcy+srch,dstx,dsty,dstx+srcw,dsty+srch,GL_COLOR_BUFFER_BIT,GL_NEAREST);
//glBlitFramebuffer(srcx,srcy,srcx+srcw-1,srcy+srch- ,dstx,dsty,dstx+srcw-1,dsty+srch-1,GL_COLOR_BUFFER_BIT,GL_NEAREST);
glDeleteFramebuffers(1, &fboName);
}
Still seems to be doing the same thing.

What is odd, is that normal rendering to the screen, works fine, but then again, im using textured quads to do that.

Its just when copying from a texture to a texture. How can I get it to only copy color value, not alpha.

Thanks for the help Ashaman, Ill try to research this some more.

This topic is closed to new replies.

Advertisement