How do I draw an OpenGL point sprite using libgdx for Android?
Posted
by
nbolton
on Game Development
See other posts from Game Development
or by nbolton
Published on 2011-03-05T00:12:56Z
Indexed on
2011/03/05
7:32 UTC
Read the original article
Hit count: 821
Here's a few snippets of what I have so far...
void create()
{
renderer = new ImmediateModeRenderer();
tiles = Gdx.graphics.newTexture(
Gdx.files.getFileHandle("res/tiles2.png", FileType.Internal),
TextureFilter.MipMap,
TextureFilter.Linear,
TextureWrap.ClampToEdge,
TextureWrap.ClampToEdge);
}
void render()
{
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glClearColor(0.6f, 0.7f, 0.9f, 1);
}
void renderSprite()
{
int handle = tiles.getTextureObjectHandle();
Gdx.gl.glBindTexture(GL.GL_TEXTURE_2D, handle);
Gdx.gl.glEnable(GL.GL_POINT_SPRITE);
Gdx.gl11.glTexEnvi(GL.GL_POINT_SPRITE, GL.GL_COORD_REPLACE, GL.GL_TRUE);
renderer.begin(GL.GL_POINTS);
renderer.vertex(pos.x, pos.y, pos.z);
renderer.end();
}
create()
is called once when the program starts, and renderSprites()
is called for each sprite (so, pos
is unique to each sprite) where the sprites are arranged in a sort-of 3D cube.
Unfortunately though, this just renders a few white dots...
I suppose that the texture isn't being bound which is why I'm getting white dots. Also, when I draw my sprites on anything other than 0 z-axis, they do not appear -- I read that I need to crease my zfar and znear, but I have no idea how to do this using libgdx (perhaps it's because I'm using ortho projection? What do I use instead?).
I know that the texture is usable, since I was able to render it using a SpriteBatch, but I guess I'm not using it properly with OpenGL.
© Game Development or respective owner