opengl es:绘制带有渐变渐变的纹理 [英] opengl es: drawing a texture with fading gradient

查看:448
本文介绍了opengl es:绘制带有渐变渐变的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对opengl完全陌生,需要一些帮助来绘制带有渐变的纹理.

I am completely new to opengl and need some help in drawing a texture with gradient applied over it.

现在,我使用以下代码绘制纹理:

Now I am drawing a texture with the following code:

glPushMatrix();
glBindTexture(GL_TEXTURE_2D,fcr.texture);
glTranslatef(trans, 0, 0);
glScalef(sc,sc,1.0);
glColor4f(1.0,1.0,1.0,0.4);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glColor4f(1,1,1,1);

在上面的代码glColor4f(1.0,1.0,1.0,0.4);中,将透明度应用于绘制的图像.现在,我要给图像应用透明的渐变色,而不是纯色的透明色,以模拟淡入淡出的效果.

In the above code glColor4f(1.0,1.0,1.0,0.4); applies transparency to the drawn image. Now instead of a solid transparent color, I would like to apply a transparent gradient to the image so as to simulate the fading out effect.

找到了该线程 iPhone OpenGL-如何渐变淡出是一个纹理?,与我的问题相同,除了我希望将渐变应用于主图像本身而不是反射.但是我无法从给出的答案中找出解决方案.

Found this thread iPhone OpenGL - How to gradient fade out a texture?, which is the same as my question except I want the gradient to be applied to the main image itself instead of reflection. But I couldn't figure out the solution from answers given.

我想我应该使用glTexEnvi,但是那怎么用渐变绘制另一幅图像呢?

I guess I should use glTexEnvi, but then how to draw another image with the gradient?

推荐答案

您可以设置glColorPointer(或glVertexAttribPointer),而不是在绘制四边形之前调用glColor4f,以便四边形的四个顶点中的每个顶点具有不同的alpha值.值吗?

Instead of calling glColor4f before drawing the quad, can you set a glColorPointer (or glVertexAttribPointer), such that each of the four vertices of your quad get a different alpha value?

即RGBA值:

 (x,x,x,1)       (x,x,x,0)
     -----------------
     |               |
     |               |
     |               |
     |               |
     |               |
     |               |
     -----------------
  (x,x,x,1)      (x,x,x,0)

这将为您提供从右到左的alpha渐变.

This would give you an alpha gradient from right to left.

这篇关于opengl es:绘制带有渐变渐变的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆