4
\$\begingroup\$

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: https://stackoverflow.com/questions/2538662/how-does-glclear-improve-performance

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Ellis
    Commented Feb 14, 2011 at 22:59
  • \$\begingroup\$ Hai, Sorry for not being clear...jst check the below post \$\endgroup\$
    – Ayyappa
    Commented Feb 16, 2011 at 18:36
  • \$\begingroup\$ 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. \$\endgroup\$
    – DeadMG
    Commented Feb 16, 2011 at 21:23

2 Answers 2

6
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ hope you forgive me as, i edited with bad formatting ;) \$\endgroup\$
    – Ayyappa
    Commented Feb 16, 2011 at 18:53
  • \$\begingroup\$ Where to put the above code? After each Texture is drawn? Or perhaps at the top or bottom of the main render loop? \$\endgroup\$
    – MrDatabase
    Commented Feb 16, 2011 at 22:58
  • \$\begingroup\$ @MrDatabase- You need to keep that code once you finish drawing to RenderTexture.Check the below Post link. \$\endgroup\$
    – Ayyappa
    Commented Feb 17, 2011 at 6:31
1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .