本文介绍了iOS上的OpenGL ES2.0中的多纹理点精灵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenGL ES 2.0为iPhone应用程序制作多纹理的点精灵.我在网络上找不到任何示例,而且似乎没有用.是否存在一些内置的限制,即在将GL_POINTS模式用于点精灵时不能在多个纹理上使用gl_PointCoord?

I am trying to make a multi-textured point sprite for an iphone application using OpenGL ES 2.0. I can't find any examples of this on web, and it doesn't seem to be working. Is there some built-in limitation where gl_PointCoord can't be used on multiple textures when using GL_POINTS mode for point sprites?

uniform sampler2D tex;
uniform sampler2D blur_tex;
vec4 texPixel = texture2D( tex, gl_PointCoord );
vec4 blurPixel = texture2D( blur_tex, gl_PointCoord );

我确定我可以正确传递纹理,因为我可以在TRIANGLE_STRIP模式下进行多种纹理处理,但是我希望使用点精灵来加快处理速度.

I'm sure I am passing in the textures properly, as I can do multi-texturing just fine in TRIANGLE_STRIP mode, but I am hoping to speed things up using point sprites.

如果可能( ),则指向工作代码示例的链接将非常有帮助.谢谢!

If it is possible, a link to an example of working code would super helpful. Thanks!

这就是我将纹理传递给着色器的方式.当我处于TRIANGLE或TRIANGLE_STRIP模式时,这使我可以进行多重纹理处理.

Here's how I'm passing in the textures to my shader. This lets me do multi-texturing when I am in TRIANGLE or TRIANGLE_STRIP mode.

//pass in position and tex_coord attributes...

//normal tex
glActiveTexture(0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex0);
glUniform1i(SAMPLER_0_UNIFORM, 0);

//blur tex
glActiveTexture(1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex1);
glUniform1i(SAMPLER_1_UNIFORM, 1);
//draw arrays...

但是,如果我使用的是POINTS模式,则永远看不到第二个纹理.也就是说,参考上面的着色器代码,是否可以

However if I am using POINTS mode then I never see the second texture. That is, referring to the shader code above, whether I do

我看到了相同的纹理.这似乎很奇怪.我的猜测是,您无法在点精灵上进行多重纹理化,并且以某种方式具有两个活动纹理或两次调用gl_PointCoord会导致问题.但是我希望我错了.因此,如果有人在OpenGL ES 2.0中有使用点精灵进行多重纹理处理的简单示例,那么我很乐意查看该代码!

I see the same texture. Which seems strange. My guess is that you CAN'T do multi-texturing on a point sprite and somehow having two active textures or two calls to gl_PointCoord causes a problem. But I'm hoping I'm wrong. So if someone has a simple example of multi-texturing working with point sprites in OpenGL ES 2.0 I would be happy to look at that code!

顶点着色器:

attribute vec4 position;

void main() {
  gl_PointSize = 15.0;
  gl_Position = position;
}

片段着色器:

precision mediump float;

uniform sampler2D tex;
uniform sampler2D blur_tex;

void main() {
  vec4 texPixel = texture2D( tex, gl_PointCoord );
  vec4 blurPixel = texture2D( blur_tex, gl_PointCoord );

  //these both do the same thing even though I am passing in two different textures?!?!?!?

  //gl_FragColor = texPixel;
  gl_FragColor = blurPixel;
}

推荐答案

在我的情况下,积分混合在一起

sourceIn my case there is a blending for points

可能的问题是参数不存在

The possible problem was in nonexistent parameters

glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

这篇关于iOS上的OpenGL ES2.0中的多纹理点精灵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:21