FBO and blending issue

导读:
  




FBO and blending issue





  











Hi, Im trying to render my scene into a texture using a frame buffer object but the output doesnt seem to be getting blended properly. This is what the texture should look like (rendered without using the FBO): Normal_Rendering

However when I try to render the scene using a FBO this is what I get: FBO_Rendering

This is how I set up my FBO

// Setup our FBO

glGenFramebuffersEXT(1, &framebuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);

// Create the render buffer for depth
glGenRenderbuffersEXT(1, &depthBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, TextureWidth, TextureHeight);

//setup the texture to render to
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, TextureWidth, TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// And attach it to the FBO so we can render to it
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);

// Attach the depth render buffer to the FBO as it's depth attachment
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);


The particles are blended additively so I disable the depth test (which makes wonder if I even need to attach the depth buffer to the FBO).

This is part of the code which draws the stars

glBindTexture(GL_TEXTURE_2D, 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glEnable(GL_POINT_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glDisable(GL_DEPTH_TEST);
drawStars();




If I increase the opacity of each particle to about 0.5 then way more particles are visible in the final image: FBO_with_more_opacity
So I think the problem maybe is that a lot of particles are getting clamped to zero or something. Im realy stuck with this problem so any tips or help would be realy appreciated thanks.







 User Rating: 1000   |  Rate This User Report this Post to a Moderator | Link













Have you remembered to disable blending when you render the final texture?
Or made sure you render the textured quad with no alpha?







 User Rating: 1426   |  Rate This User Report this Post to a Moderator | Link













Wow, disabling blending works! Thanks a lot. But now I have another problem because my actually goal is to render the scene into multiple textures and then to blend these textured quads. So my next question is what settings do I need to blend the textured quads? The code I use at the moment to display one textured quad is:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

glBindTexture(GL_TEXTURE_2D, texture);
glEnable(GL_TEXTURE_2D);
glDrawBuffer(GL_BACK);

glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

glViewport( 0, 0, g_windowWidth, g_windowHeight );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, (float)g_windowWidth, 0, (float)g_windowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glUseProgramObjectARB(0);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();

glTranslatef(0.0f,0.0f,-1.0f);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glDisable(GL_BLEND);

glBegin(GL_QUADS);
// Back Face
//glNormal3f( 0.0f, 0.0f,-1.0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0, (float)g_windowHeight, 0.5);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0, 0.0, 0.5);
glTexCoord2f(0.0f, 1.0f); glVertex3f( (float)g_windowWidth, 0.0, 0.5);
glTexCoord2f(0.0f, 0.0f); glVertex3f( (float)g_windowWidth, (float)g_windowHeight, 0.5);
glEnd();

glDisable(GL_TEXTURE_2D);
glutSwapBuffers ( );


and Im using glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

Again many thanks.






 User Rating: 1000   |  Rate This User 


本文转自
http://www.gamedev.net/community/forums/topic.asp?topic_id=463719
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值