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.

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();
}
share|improve this question
    
Update: As a work around, I had to split my texture images into separate files (loaded individually). This adds a bit of loading time, but it's ok with a few images (worried about when I have 100 textures though...). A caveat I didn't foresee is that OpenGL ES (<2.0) requires that images be power of 2, and point sprites must be square! –  nbolton Mar 12 '11 at 1:48
add comment

1 Answer

With OpenGL ES 1.x, i gess there is no solution. With OpenGL ES 2.x, you can use gl_PointCoord in fragment shader to select a part of your texture.

A typical PointSprite Fragment shader:

#ifdef GL_ES
precision highp float;
#endif 
uniform sampler2D tex0;

void main() 
{
    gl_FragColor = texture2D(tex0, gl_PointCoord);
}

So, you can modify it for 16 square textures in one texture:

    gl_FragColor = texture2D(tex0, gl_PointCoord*0.25+displacement);

One last word, if you are developing for mobile devices, keep you fragment very short and don't use branch.

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.