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 bufferglBindFramebuffer(GL_FRAMEBUFFER, fboName);// attach the textures to the frame bufferglFramebufferTexture2D(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
Problem rendering to a texture
Started by SelethD, Nov 13 2012 09:07 PM
4 replies to this topic
Sponsor:
#2 Members - Reputation: 4605
Posted 14 November 2012 - 12:24 AM
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);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE);
Ashaman
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
#3 Members - Reputation: 246
Posted 14 November 2012 - 09:20 AM
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.
Here is visual example of the problem, Im not the best at explaining in words.
#4 Members - Reputation: 4605
Posted 14 November 2012 - 12:24 PM
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:
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);
}
Ashaman
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
#5 Members - Reputation: 246
Posted 14 November 2012 - 02:41 PM
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.
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.






