iOS 上 OpenGL ES2.0 中的多纹理点精灵?

发布于 2024-11-03 14:51:48 字数 1753 浏览 1 评论 0原文

我正在尝试使用 OpenGL ES 2.0 为 iPhone 应用程序制作多纹理点精灵。我在网上找不到任何这样的例子,而且它似乎不起作用。当对点精灵使用 GL_POINTS 模式时,是否有一些内置限制使得 gl_PointCoord 不能在多个纹理上使用?

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

我确信我正确地传递了纹理,因为我可以在 TRIANGLE_STRIP 模式下很好地进行多重纹理,但我希望使用点精灵来加快速度。

如果可能的话,工作代码示例的链接将非常有帮助。谢谢!

编辑:

这是我将纹理传递给着色器的方式。这让我可以在 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...

但是,如果我使用 POINTS 模式,那么我永远不会看到第二个纹理。也就是说,参考上面的shader代码,我是否

gl_FragColor = texPixel;

或者

gl_FragColor = 模糊像素;

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

编辑2:

顶点着色器:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女的英雄梦 2024-11-10 14:51:48

您的主程序中有一个拼写错误。

传递给 glActiveTexture 的正确参数是 GL_TEXTURE0、GL_TEXTURE1...

请注意,GL_TEXTURE0、GL_TEXTURE1 没有 0,1 等值。

由于您向 glActiveTexture 传递了无效值,因此该函数将失败,因此活动纹理始终是默认值(可能是 0),所有更改都将在 0 位置处进行纹理化。

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.

枯叶蝶 2024-11-10 14:51:48

来源< /a>
就我而言,存在点混合

可能的问题在于不存在的参数

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

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 );
花桑 2024-11-10 14:51:48

我想发布这个可能已经太晚了。

您的代码中有两个问题。萨蒂亚卡姆指出的就是其中之一。另一个问题是你不应该使用 glUniform1f。右边的是 glUniform1i。尾部的 f 或 i 表示浮点数或整数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文