Textured points in OpenGL ES 2.0?

こ雲淡風輕ζ 提交于 2019-12-04 02:43:29
Constantin

You select your texture as active and bind it - like normally. But you must pass your texture unit as uniform to the shader program. So you can use the gl_PointCoord as texture coordinates in your fragment shader.

glUniform1i(MY_TEXTURE_UNIFORM_LOCATION, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, yourTextureId);
glEnable(GL_TEXTURE_2D);
glDrawArrays(GL_POINTS, 0, pointCount);
glDisable(GL_TEXTURE_2D);

And your fragment shader should look like:

uniform sampler2D texture;
void main ( )
{
    gl_FragColor = texture2D(texture, gl_PointCoord);
}

I also had a similar problem - my sprites were just rendering as coloured squares but no texture was appearing.

I needed to add this:

glEnable( GL_POINT_SPRITE );

Texturing must not be enabled by default on all GPUs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!