How do I render only part of a texture to a point sprite in OpenGL ES for Android?
Posted
by
nbolton
on Game Development
See other posts from Game Development
or by nbolton
Published on 2011-03-11T20:19:38Z
Indexed on
2011/03/12
0:19 UTC
Read the original article
Hit count: 301
Using the libgdx framework, I've figured out how to render a texture to a point sprite. The problem is, it renders the entire texture to the point sprite, where I only want a small part of it (since it's an isometric tile image).
Here's a snippet from some demo code I wrote...
create()
{
renderer = new ImmediateModeRenderer();
tiles = Gdx.graphics.newTexture(
Gdx.files.internal("data/tiles2.png"),
TextureFilter.MipMap,
TextureFilter.Linear,
TextureWrap.ClampToEdge,
TextureWrap.ClampToEdge);
Gdx.gl.glClearColor(0.6f, 0.7f, 0.9f, 1);
Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
Gdx.gl.glEnable(GL11.GL_POINT_SPRITE_OES);
Gdx.gl11.glTexEnvi(
GL11.GL_POINT_SPRITE_OES,
GL11.GL_COORD_REPLACE_OES,
GL11.GL_TRUE);
Gdx.gl10.glPointSize(s);
tiles.bind();
}
render()
{
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
renderer.begin(GL10.GL_POINTS);
// render 3 point sprites at various 3d points
renderer.vertex(-.1f, 0, -.1f);
renderer.vertex(0, 0, 0);
renderer.vertex(.1f, 0, .1f);
// ... more vertices here if needed (one for each sprite) ...
renderer.end();
}
© Game Development or respective owner