Example usage for com.badlogic.gdx.graphics GL20 GL_RGBA

List of usage examples for com.badlogic.gdx.graphics GL20 GL_RGBA

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 GL_RGBA.

Prototype

int GL_RGBA

To view the source code for com.badlogic.gdx.graphics GL20 GL_RGBA.

Click Source Link

Usage

From source file:ta.firegreen.creation.creator.java

License:Apache License

@Override
public void render() {
    if (fileTexture != null) {
        bindTexture(mesh, fileTexture.getAbsolutePath());
        fileTexture = null;// w  w  w  .  j  av  a 2  s . c  om
    }
    if (fileMTA != null) {
        nouveau = MeshTA.loadMeshTA(fileMTA);
        fileMTA = null;
    }
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    cam.position.set(posX, posY, posZ);
    cam.lookAt(cibleX, cibleY, cibleZ);
    cam.update();
    if (afficheTexture)
        mesh.render(renduTexture, cam.combined);
    else
        mesh.render(rendu, cam.combined);

    if (saveIMGFile != null) {

        final Pixmap p = new Pixmap(Gdx.graphics.getWidth() - 200, Gdx.graphics.getHeight() - 200,
                Pixmap.Format.RGBA8888);
        ByteBuffer bytes = ByteBuffer.allocateDirect(p.getPixels().capacity());
        Gdx.gl20.glReadPixels(100, 100, Gdx.graphics.getWidth() - 200, Gdx.graphics.getHeight() - 200,
                GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, bytes);
        int j = p.getPixels().capacity() - 1;
        for (int i = 0; i < p.getPixels().capacity(); i += 4) {
            p.getPixels().put(j, bytes.get(i + 3));
            j--;
            p.getPixels().put(j, bytes.get(i + 2));
            j--;
            p.getPixels().put(j, bytes.get(i + 1));
            j--;
            p.getPixels().put(j, bytes.get(i));
            j--;
        }

        if (!saveIMGFile.getName().endsWith(".png"))
            if (!saveIMGFile.renameTo(new File(saveIMGFile.getName() + ".png"))) {
                JOptionPane.showMessageDialog(null, "Le fichier n'a pas pu tre sauvegarder", "Erreur",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
        PixmapIO.writePNG(new FileHandle(saveIMGFile), p);
        saveIMGFile = null;
    }

    shape.setProjectionMatrix(cam.projection);
    shape.setTransformMatrix(cam.view);
    shape.begin(ShapeType.Line);
    shape.setColor(Color.GREEN);
    shape.line(new Vector3(-10, 0, 0), new Vector3(10, 0, 0));
    shape.setColor(Color.RED);
    shape.line(new Vector3(0, -10, 0), new Vector3(0, 10, 0));
    shape.setColor(Color.BLUE);
    shape.line(new Vector3(0, 0, -10), new Vector3(0, 0, 10));
    shape.end();
    cam.translate(0.05f, 0.05f, 0.05f);
    cam.update();
    trianglesSelected.render(rendu, cam.combined);
    cam.translate(-0.1f, -0.1f, -0.1f);
    cam.update();
    trianglesSelected.render(rendu, cam.combined);
    try {
        Thread.sleep(35);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}