Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question is a follow-up to Texture artifacts on iPad

How does one "clear the alpha of the render texture frameBufferObject"? I've searched around here, StackOverflow and various search engines but no luck. I've tried a few things... for example calling GlClear(GL_COLOR_BUFFER_BIT) at the beginning of my render loop... but it doesn't seem to make a difference. Any help is appreciated since I'm still new to OpenGL.

Cheers!

p.s. I read on SO and in Apple's documentation that GlClear should always be called at the beginning of the renderLoop. Agree? Disagree? Here's where I read this: http://stackoverflow.com/questions/2538662/how-does-glclear-improve-performance

share|improve this question
1  
What is the format of your FBO? RGBA_8888, RGBA_5551, RGB_888 or RGB_565. If you use RGB_565 or RGB_888, alpha component is always equal to 1.0. –  Ellis Feb 14 '11 at 22:59
    
Hai, Sorry for not being clear...jst check the below post –  Ayyappa Feb 16 '11 at 18:36
    
Clearing the framebuffer is an excellent way to improve performance, because the graphics card knows that it can discard or draw from the old memory. Consider double buffering- if you want to save the previous contents of the frame, then you can't draw on to the back buffer and display the front buffer, because the back buffer doesn't have the previous frame's image on it. –  DeadMG Feb 16 '11 at 21:23

2 Answers 2

up vote 2 down vote accepted

Try

glColorMask(FALSE, FALSE, FALSE, TRUE);//This ensures that only alpha will be effected
glClearColor(0, 0, 0, alphaValue);//alphaValue - Value to which you need to clear
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

to clear both the color buffer (with transparent black) and the depth buffer, in case you are using depth testing.

glClear must be called unless you are really sure you are redrawing all the pixels every frame, so parts of previous frames don't show over your new render.

share|improve this answer
    
hope you forgive me as, i edited with bad formatting ;) –  Ayyappa Feb 16 '11 at 18:53
    
Where to put the above code? After each Texture is drawn? Or perhaps at the top or bottom of the main render loop? –  MrDatabase Feb 16 '11 at 22:58
    
@MrDatabase- You need to keep that code once you finish drawing to RenderTexture.Check the below Post link. –  Ayyappa Feb 17 '11 at 6:31

Once have a look at the below link (please check the afterRender method)

http://code.google.com/p/cocos2d-iphone/issues/detail?id=631&q=glClear%28GL_COLOR_BUFFER_BIT&colspec=ID%20Type%20Status%20Priority%20Milestone%20Component%20Owner%20Summary

Here the fix was to clear the RenderTextures's Alpha channel with 1.0 so that it will not have artifact when you draw other nodes on RenderTexture.That clearing should be done once you are done drawing on the renderTexture. Please let me know if you need further clarification.

Btw, for glClear call.... If you are drawing a full screen background, there is no need of calling glClear.The game i worked on recently had a bit of performance gain when i removed glClear call.The link you posted seems interesting.Thanks for the link.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.