Jump to content

  • Log In with Google      Sign In   
  • Create Account


OpenGL/FBO/Cg blend error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 lephyrius   Members   -  Reputation: 265

Like
0Likes
Like

Posted 26 May 2010 - 05:15 AM

OpenGL blend error! As you can see there is a black border around the letters. I want it to blend to transparent. I think the alpha in the shader works otherwise ALPHA_TEST doesn't work. This is how I render the FBO:
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);
	glDepthFunc(GL_LEQUAL);	
	glAlphaFunc(GL_GEQUAL,0.01f);
	glShadeModel(GL_SMOOTH);
	glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
	glBlendEquation ( GL_FUNC_ADD ) ;

	cgGLEnableProfile(cgVertexProfile);
	cgGLEnableProfile(cgFragmentProfile);

// Render as normal.

Here is how I setup the FBO:
	sceneTexture = new Texture();
	glBindTexture(GL_TEXTURE_2D,sceneTexture->getTextureId());
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  width, height, 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_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glGenRenderbuffers(1, &depthBuffer);
	glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sceneTexture->getTextureId(), 0);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, bloomTexture->getTextureId(), 0);
	GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
	glDrawBuffers(2, buffers);



Sponsor:

#2 lephyrius   Members   -  Reputation: 265

Like
0Likes
Like

Posted 26 May 2010 - 07:21 PM

I found out that I rendered the triangle and the text in the wrong order. When I drew the the triangle first and then the transparent text it worked as I wanted. But why? Is there some other way to prevent it other than sorting all the objects so that I render the opaque objects first and then the translucent?

I thought that the Z-buffer sorted everything out but I was wrong.


#3 Fetze   Members   -  Reputation: 709

Like
0Likes
Like

Posted 26 May 2010 - 07:52 PM

The Z-Buffer fails horribly when rendering any transparent objects. You need to first draw all non-translucent objects, then turn off writing to the z-buffer (but not the z test!) and draw all transparent objects sorted from back to front.

If you're 2d only I'd recommend not to use the z buffer at all since you will most likely have transparency in 90% of your textured graphics.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS