如何在libGDX中使用全屏四边形创建扫描线?

时间:2016-08-02 23:06:33

标签: java android libgdx opengl-es-2.0

我想在我的游戏画面上画一个四边形,重复扫描线纹理,1像素:1像素比。这是一款2D游戏。这就是我到目前为止所做的:

创建()

quad = new Mesh(true, 4, 6,
                new VertexAttribute(Usage.Position, 3, "a_position"),
                new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
quad.setVertices(new float[] {
                -1.0f, 0.0f, 0, 0.0f, 1.0f,             //bottom left
                1.0f,  0.0f, 0, 1.0f, 1.0f,             //bottom right
                1.0f,  1.0f, 0, 1.0f, 0.0f,             //top right
                -1.0f, 1.0f, 0, 0.0f, 0.0f });          //top left
quad.setIndices(new short[] { 0, 1, 2, 2, 3, 0});

Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D);
Gdx.gl20.glEnable(GL20.GL_BLEND);
Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

texScanlines = new Texture(Gdx.files.internal("Scanlines.png"));
texScanlines.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
imgTextureRegion = new TextureRegion(texScanlines);
imgTextureRegion.setRegion(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

渲染()

Gdx.graphics.getGL20().glClearColor(0, 0, 0, 1);
Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

camera.update();

spriteBatch.setProjectionMatrix(camera.combined);

spriteBatch.begin();
  // draw game stuff...
spriteBatch.end();

imgTextureRegion.getTexture().bind();
quad.render(SpriteBatch.createDefaultShader(), GL20.GL_TRIANGLES);

但是,四边形没有渲染。有没有人有任何指示?

0 个答案:

没有答案