简体   繁体   English

iOS上的OpenGL ES2.0中的多纹理Point Sprites?

[英]Multi-textured Point Sprites in OpenGL ES2.0 on iOS?

I am trying to make a multi-textured point sprite for an iphone application using OpenGL ES 2.0. 我正在尝试使用OpenGL ES 2.0为iphone应用程序制作一个多纹理点精灵。 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? 是否存在一些内置限制,当使用GL_POINTS模式进行点精灵时,gl_PointCoord不能用于多个纹理?

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

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. 我确定我正确地传递纹理,因为我可以在TRIANGLE_STRIP模式下进行多纹理处理,但我希望使用点精灵来加快速度。

If it is possible, a link to an example of working code would super helpful. 如果有可能 ,到工作代码示例的链接将超级有益的。 Thanks! 谢谢!

EDIT: 编辑:

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. 当我处于TRIANGLE或TRIANGLE_STRIP模式时,这可以让我进行多纹理化。

//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...

However if I am using POINTS mode then I never see the second texture. 但是,如果我使用POINTS模式,那么我永远不会看到第二个纹理。 That is, referring to the shader code above, whether I do 也就是说,参考上面的着色器代码,我是否这样做

gl_FragColor = texPixel; gl_FragColor = texPixel;

OR 要么

gl_FragColor = blurPixel; gl_FragColor = blurPixel;

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. 我的猜测是你不能对点精灵进行多纹理处理,不知何故有两个活动纹理或两次调用gl_PointCoord会导致问题。 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! 因此,如果某人有一个简单的多纹理示例,在OpenGL ES 2.0中使用点精灵,我会很高兴看到该代码!

EDIT 2: 编辑2:

vertex shader: 顶点着色器:

attribute vec4 position;

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

fragment shader: 片段着色器:

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;
}

There is a typo in your main program. 主程序中有拼写错误。

The right parameter to pass to glActiveTexture is GL_TEXTURE0, GL_TEXTURE1, ... 传递给glActiveTexture的正确参数是GL_TEXTURE0,GL_TEXTURE1,...

Note that GL_TEXTURE0, GL_TEXTURE1 does not have a value of 0,1 etc. 请注意,GL_TEXTURE0,GL_TEXTURE1的值不为0,1等。

Since you are passing an invalid value to glActiveTexture, the function will fail and so the active texture will always be a default (probably 0) all your changes are going to texture at 0 position. 由于您将无效值传递给glActiveTexture,因此该函数将失败,因此活动纹理将始终为默认值(可能为0),所有更改将在0位置进行纹理处理。

source In 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 );

I think may be too late to post this though. 我觉得发布这个可能为时已晚。

There are two problems in your code. 您的代码中存在两个问题。 One is the one that Satyakam has pointed out. 一个是萨蒂亚卡姆指出的那个。 The other problem is that you should NOT use glUniform1f. 另一个问题是你不应该使用glUniform1f。 Right one is glUniform1i. 右边一个是glUniform1i。 The deference is f or i on the tail which means float or integer. 尾部的参数是f或i,表示浮点数或整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM