Example usage for org.lwjgl.opengl GL20 glUseProgram

List of usage examples for org.lwjgl.opengl GL20 glUseProgram

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glUseProgram.

Prototype

public static void glUseProgram(@NativeType("GLuint") int program) 

Source Link

Document

Installs a program object as part of current rendering state.

Usage

From source file:lessur.util.shader.ShaderManager.java

License:GNU General Public License

/**
 * Reverts to the fixed program/* www .j av a2s.com*/
 */
public void endUse() {
    if (has_opengl2) {
        GL20.glUseProgram(0);
    } else if (has_arb) {
        ARBShaderObjects.glUseProgramObjectARB(0);
    }
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

@Override
public void Render(float interpolation) {

    GL20.glUseProgram(pId);

    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // Bind to the VAO that has all the information about the vertices
    GL30.glBindVertexArray(vaoId);//ww  w .java 2  s.c  o m
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);

    GL20.glUseProgram(0);

    Game.exitOnGLError("renderCycle");
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

@Override
public void Tick() {
    // Update Positions
    Vector3f.add(this.modelAngle, this.modelSpin, this.modelAngle);
    Vector3f.add(this.modelVelcity, this.modelAccel, this.modelVelcity);
    Vector3f.add(this.modelPos, this.modelVelcity, this.modelPos);

    // Reset view and model matrices
    modelMatrix = new Matrix4f();

    // Scale, translate and rotate model
    Matrix4f.scale(modelScale, modelMatrix, modelMatrix);
    Matrix4f.translate(modelPos, modelMatrix, modelMatrix);
    Matrix4f.rotate(Conversions.degreesToRadians(modelAngle.z), new Vector3f(0, 0, 1), modelMatrix,
            modelMatrix);//ww w .  j ava  2  s. c o  m
    Matrix4f.rotate(Conversions.degreesToRadians(modelAngle.y), new Vector3f(0, 1, 0), modelMatrix,
            modelMatrix);
    Matrix4f.rotate(Conversions.degreesToRadians(modelAngle.x), new Vector3f(1, 0, 0), modelMatrix,
            modelMatrix);

    // Upload matrices to the uniform variables
    GL20.glUseProgram(pId);

    Game.projectionMatrix.store(Game.matrix44Buffer);
    Game.matrix44Buffer.flip();
    GL20.glUniformMatrix4(projectionMatrixLocation, false, Game.matrix44Buffer);
    Game.viewMatrix.store(Game.matrix44Buffer);
    Game.matrix44Buffer.flip();
    GL20.glUniformMatrix4(viewMatrixLocation, false, Game.matrix44Buffer);
    modelMatrix.store(Game.matrix44Buffer);
    Game.matrix44Buffer.flip();
    GL20.glUniformMatrix4(modelMatrixLocation, false, Game.matrix44Buffer);

    GL20.glUseProgram(0);
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

public void destroy() {
    // Delete the Program
    GL20.glUseProgram(0);
    GL20.glDeleteProgram(pId);/*from   w w  w.  j av  a2s  .  c  o m*/

    // Select the VAO
    GL30.glBindVertexArray(vaoId);

    // Disable the VBO index from the VAO attributes list
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);

    // Delete the vertex VBO
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboId);

    // Delete the index VBO
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(vboiId);

    // Delete the VAO
    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(vaoId);
}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private synchronized void render() {
    GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL20.glUseProgram(shader.getPID());
    ///* w w  w  .ja  v a 2 s .  co m*/

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL30.glBindVertexArray(vaoId);

    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    long offset = 0;
    int shift = 0;
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    for (Drawable object : objects) {
        Matrix4f finalMVP = new Matrix4f(mvpMat);
        Matrix4f modelMat = new Matrix4f();
        Matrix4f scaler = new Matrix4f();
        scaler.scale(object.scale * allScale);
        modelMat.translate(object.translation);
        modelMat.rotateXYZ(object.rotation.x, object.rotation.y, object.rotation.z);
        finalMVP.mul(modelMat);
        finalMVP.mul(scaler);
        finalMVP.get(0, matBuff);
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap));
        }
        GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);
        GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0);
        if (object.isVisible())
            GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE,
                    offset, shift);

        offset += object.getIndices().length;
        shift += object.getVertex().length;
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
        }
    }
    render2d(offset, shift);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
    //
    GL20.glUseProgram(0);
    glfwSwapBuffers(window);
    glfwPollEvents();

}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java

License:Open Source License

@Override
public void bind() {
    ensureCreated("Program must be created to bind.");
    GL20.glUseProgram(id);
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java

License:Open Source License

@Override
public void unbind() {
    GL20.glUseProgram(0);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java

License:Apache License

/** Makes OpenGL ES 2.0 use this vertex and fragment shader pair. When you are done with this shader you have to call
 * {@link ShaderProgram#end()}. */
public void begin() {
    checkContext();/*w  w w .j  a va  2s  . co  m*/
    GL20.glUseProgram(program);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java

License:Apache License

/** Disables this shader. Must be called when one is done with the shader. Don't mix it with dispose, that will release the
 * shader resources. *//*from w  ww.ja  v a 2  s . co m*/
public void end() {
    GL20.glUseProgram(0);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java

License:Apache License

/** Disposes all resources associated with this shader. Must be called when the shader is no longer used. */
public void dispose() {
    GL20.glUseProgram(0);
    GL20.glDeleteShader(vertexShaderHandle);
    GL20.glDeleteShader(fragmentShaderHandle);
    GL20.glDeleteProgram(program);//from   w w w. j  a va  2s  .co  m
    //      if (shaders.get(Gdx.app) != null) shaders.get(Gdx.app).remove(this);
}