com.grillecube.engine.renderer.gui.ProgramQuad.java Source code

Java tutorial

Introduction

Here is the source code for com.grillecube.engine.renderer.gui.ProgramQuad.java

Source

/**
**   This file is part of the project https://github.com/toss-dev/VoxelEngine
**
**   License is available here: https://raw.githubusercontent.com/toss-dev/VoxelEngine/master/LICENSE.md
**
**   PEREIRA Romain
**                                       4-----7          
**                                      /|    /|
**                                     0-----3 |
**                                     | 5___|_6
**                                     |/    | /
**                                     1-----2
*/

package com.grillecube.engine.renderer.gui;

import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL32;

import com.grillecube.engine.maths.Vector2f;
import com.grillecube.engine.opengl.GLH;
import com.grillecube.engine.opengl.object.GLProgram;
import com.grillecube.engine.resources.R;

public class ProgramQuad extends GLProgram {
    private int _quad_pos;
    private int _quad_size;

    public ProgramQuad() {
        super();
        this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quad.fs"), GL20.GL_FRAGMENT_SHADER));
        this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quad.gs"), GL32.GL_GEOMETRY_SHADER));
        this.addShader(GLH.glhLoadShader(R.getResPath("shaders/gui/quad.vs"), GL20.GL_VERTEX_SHADER));
        this.link();
    }

    @Override
    public void bindAttributes() {
    }

    @Override
    public void linkUniforms() {
        this._quad_pos = super.getUniform("quad_pos");
        this._quad_size = super.getUniform("quad_size");
    }

    private Vector2f _vec2buffer = new Vector2f();

    public void loadRect(float x, float y, float width, float height) {
        super.loadUniformVec(this._quad_pos, _vec2buffer.set(x, y));
        super.loadUniformVec(this._quad_size, _vec2buffer.set(width, height));
    }

}