Sign in to follow this  
SelethD

Problem rendering to a texture

Recommended Posts

SelethD    456
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

Share this post


Link to post
Share on other sites
SelethD    456
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.

[IMG]http://i48.tinypic.com/9upta1.jpg[/IMG]

Share this post


Link to post
Share on other sites
Ashaman73    13715
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:

[CODE]
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);
}
[/CODE]

Share this post


Link to post
Share on other sites
SelethD    456
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this