我来自FlashBuilder,Flex,Flash开发领域,我正在努力研究如何通过LibGDX进入Android开发。
我已经完成了环境设置,学习了一些基础知识,但现在我正在研究如何渲染一个带有纹理的平面的尴尬时间。
我发现的大多数演示都是OpenGL ES2.0,但是我需要在两者上运行我的应用程序,所以我尝试在创建纹理平面时寻找OpenGL ES1.1教程但最终徘徊了几个小时。如果有人有任何建议吗?代码示例?教程?请告诉我。太棒了。
这是我到目前为止所获得的代码,但没有显示任何内容(libgdx演示图像被注释掉,所以我可以看到它是否呈现任何东西,但它没有):
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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}