iPhone OpenGL - How to gradient fade out a texture?

白昼怎懂夜的黑 提交于 2019-12-12 18:45:01

问题


I want to customize the reflection from the FlowCover (Cover Flow remake) sample code. Now, the reflection (a texture) is only transparent but I want it to have a gradient so that the texture fades to be completely transparent.

How would you achieve this effect with OpenGL? This is the code that handles the textures.

glPushMatrix();
glBindTexture(GL_TEXTURE_2D,fcr.texture);
glTranslatef(trans, 0, 0);
glScalef(sc,sc,1.0);
glMultMatrixf(m);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);

// reflect
glTranslatef(0,-2,0);
glScalef(1,-1,1);
glColor4f(0.5,0.5,0.5,0.5);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glColor4f(1,1,1,1);

glPopMatrix();

Any hints or key words are welcome.

Thanks a lot.


回答1:


My solution to this problem was to remove openGL reflection and to path image with reflection and gradient to FlowCower. Here is a nice example on creating image reflection.




回答2:


It's a good idea to draw reflection with gradient way. ^_^

I think you can put a light source, and change the normal vector of project view. The lighting source will make some gradient effect.




回答3:


You might want to look into multitexturing. You can combine the base texture with a gradient texture in a way that uses the color of the first and the alpha values of the second. Take a look at the glTexEnvi command.



来源:https://stackoverflow.com/questions/3536763/iphone-opengl-how-to-gradient-fade-out-a-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!