Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Edit: I'm using the GL enum, which is incorrect since it's not part of OpenGL ES (see my answer). I should have used GL10, GL11 or GL20 instead.

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

Point sprite problem

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.

share|improve this question
add comment

2 Answers

If you are using orthogonal projection, then chances are you called Gdx.gl.glOrtho() at some point. The last two arguments are your near and far distances.

By the way, you should call Gdx.gl.glClearColor() before Gdx.gl.glClear(). It's not dramatic in your code, you will only get the first frame wrong, but be careful about similar errors.

share|improve this answer
add comment
up vote 0 down vote accepted

Figured out the answer, here's how you render textured point sprites, using alpha test and depth test:

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(GL10.GL_DEPTH_TEST);
    Gdx.gl.glEnable(GL10.GL_ALPHA_TEST);
    Gdx.gl.glEnable(GL11.GL_POINT_SPRITE_OES);

    Gdx.gl10.glAlphaFunc(GL10.GL_GREATER, 0);

    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 | GL10.GL_DEPTH_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();
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.