Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem rendering to a texture

Started by SelethD Nov 14, 2012 at 3:07 AM 3 replies 2.6k views
Original Post
SelethD
SelethD
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
SelethD
SelethD
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
Ashaman73
Ashaman73
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);
}
SelethD
SelethD
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.