net.team2xh.environment.widgets.graphs.Graph.java Source code

Java tutorial

Introduction

Here is the source code for net.team2xh.environment.widgets.graphs.Graph.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.team2xh.environment.widgets.graphs;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;

/**
 *
 * @author Tenchi
 */
public abstract class Graph extends Widget {

    private ShapeRenderer renderer;
    private String vertexShader, fragmentShader;
    private ShaderProgram shader;

    public Graph() {
        renderer = new ShapeRenderer();
        //        ShaderProgram.pedantic = false;
        //        vertexShader = Gdx.files.internal("shaders/vertex/spherize.glsl").readString();
        //        fragmentShader = Gdx.files.internal("shaders/fragment/greyscale.glsl").readString();
        //        shader = new ShaderProgram(vertexShader, fragmentShader);
        //        System.out.println(shader.isCompiled() ? "Shader compiled" : shader.getLog());

        //        ImmediateModeRenderer20 imr = (ImmediateModeRenderer20) renderer.getRenderer();
        //        imr.setShader(shader);
    }

    public abstract void update(float delta);

    public abstract void render(ShapeRenderer renderer, Batch batch);

    @Override
    public void act(float delta) {
        update(delta);
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        super.draw(batch, parentAlpha);

        batch.end();
        //        shader.begin();
        //        shader.setUniformMatrix("u_projTrans", renderer.getProjectionMatrix());
        //        shader.setUniformf("u_widgetPosition", new Vector2(getX(), getY()));
        //        shader.setUniformf("u_resolution", new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
        //        shader.end();
        render(renderer, batch);
        batch.begin();
    }

}