开发者

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. 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 );

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!

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.

//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. That is, referring to the shader code above, whether I do

gl_FragColor = texPixel;

OR

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

EDIT 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 = textur开发者_开发知识库e2D( 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, ...

Note that GL_TEXTURE0, GL_TEXTURE1 does not have a value of 0,1 etc.

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.


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. Right one is glUniform1i. The deference is f or i on the tail which means float or integer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜