2

I come from the FlashBuilder, Flex, Flash development area and am trying to work out how to get into Android Development via LibGDX.

I have got my environment setup, learned some of the basics, but am now having an awkward time working out how to render a plane with a texture on it.

Most of the demos I find are OpenGL ES2.0, but I need my application to run on both, so I've tried looking for OpenGL ES1.1 tutorials on creating a texture plane but end up wandering for hours. So if anyone has any suggestions? Code examples? Tutorials? Please let me know. Would be awesome.

Here's the code I've got so far but shows nothing (the libgdx demo image is commented out so I can see if it renders anything but it doesn't):

public class MyGdxGame implements ApplicationListener {
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
private OrthographicCamera camera;
private SpriteBatch batch;
private Texture texture;
private Sprite sprite;

private ShaderProgram sp;
private Mesh mesh;
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -


// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@Override
public void create() {      
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();

    camera = new OrthographicCamera(1, h/w);
    batch = new SpriteBatch();

    texture = new Texture(Gdx.files.internal("data/libgdx.png"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);

    sprite = new Sprite(region);
    sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
    sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
    sprite.setPosition(-sprite.getWidth()/2, -sprite.getHeight()/2);


    mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3,"a_position"));
    mesh.setVertices(new float[] { 100f, 100f, 0, 
              400f, 100f, 0, 
              250, 400f, 0 });

     mesh.setIndices(new short[] { 0, 1, 2 });
     tex = new Texture(Gdx.files.internal("data/libgdx.png"));
}
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -



private Texture tex;




// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@Override
public void render() {
    // Set bg
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);


    Gdx.gl10.glMatrixMode(GL10.GL_PROJECTION);
    Gdx.gl10.glLoadIdentity();
    Gdx.gl10.glMatrixMode(GL10.GL_MODELVIEW);
    Gdx.gl10.glLoadIdentity();
    mesh.render(GL10.GL_TRIANGLES, 0, 3);

    batch.begin();
    //sprite.draw(batch);
    //mesh.render(sp, GL10.GL_TRIANGLES);
    batch.draw(tex, 10, 10);
    batch.end();

    // Results in white window output only...
}
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -





// From a previous tutorial attempt didn't show anything
public Mesh createFullScreenQuad() {

      float[] verts = new float[20];
      int i = 0;

      verts[i++] = -1; // x1
      verts[i++] = -1; // y1
      verts[i++] = 0;
      verts[i++] = 0f; // u1
      verts[i++] = 0f; // v1

      verts[i++] = 1f; // x2
      verts[i++] = -1; // y2
      verts[i++] = 0;
      verts[i++] = 1f; // u2
      verts[i++] = 0f; // v2

      verts[i++] = 1f; // x3
      verts[i++] = 1f; // y2
      verts[i++] = 0;
      verts[i++] = 1f; // u3
      verts[i++] = 1f; // v3

      verts[i++] = -1; // x4
      verts[i++] = 1f; // y4
      verts[i++] = 0;
      verts[i++] = 0f; // u4
      verts[i++] = 1f; // v4

      Mesh mesh = new Mesh( true, 4, 0,  // static mesh with 4 vertices and no indices
        new VertexAttribute( Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE ),
        new VertexAttribute( Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE+"0" ) );

      mesh.setVertices( verts );
      return mesh;
    }














// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@Override
public void resize(int width, int height) {
}
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -



// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@Override
public void pause() {
}
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -



// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@Override
public void resume() {
}
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -



// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@Override
public void dispose() {
    batch.dispose();
    texture.dispose();
}
// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

}

Darcey
  • 1,949
  • 1
  • 13
  • 22
  • For anyone coming across this old question, it is probably a bad idea to use OpenGL ES1.1 now (It likely was at the time as well). Android doesn't even include 1.1 on their device support chart: https://developer.android.com/about/dashboards/index.html#OpenGL – twiz Nov 28 '14 at 02:17
  • @twiz "Note that support for one particular version of OpenGL ES also implies support for any lower version (for example, support for version 2.0 also implies support for 1.1)." – xjcl Aug 23 '20 at 20:46

0 Answers0