Example usage for org.lwjgl.opengl GL20 glLinkProgram

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

Introduction

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

Prototype

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

Source Link

Document

Links a program object.

Usage

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public boolean linkProgram(int program) {
    GL20.glLinkProgram(program);
    return GL20.glGetProgram(program, GL20.GL_LINK_STATUS) == GL11.GL_TRUE;
}

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

License:GNU General Public License

/**
 * Attach's the shader to the program, and links the program
 * @throws Exception // w  w  w  .ja  v a2s  . c  o m
 */
public void attachAndLinkShader(int program, int shaderID) throws Exception {
    if (has_opengl2) {
        GL20.glAttachShader(program, shaderID);
        GL20.glLinkProgram(program);
    } else if (has_arb) {
        ARBShaderObjects.glAttachObjectARB(program, shaderID);
        ARBShaderObjects.glLinkProgramARB(program);
    }
    if (!linkedSuccessfully(program)) {
        StringBuilder errorMessage = new StringBuilder();
        errorMessage.append("Linking Error\n");
        errorMessage.append(getProgramInfoLog(program));
        errorMessage.append("\n\n");
        throw new Exception(errorMessage.toString());
    }
}

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

License:Open Source License

private void SetupShaders(String shaderPath, String fragPath) {
    // Load the vertex shader and fragment shader
    vsId = ShaderHandler.loadShader(shaderPath);
    fsId = ShaderHandler.loadFrag(fragPath);

    // Create a new shader program that links both shaders
    pId = GL20.glCreateProgram();/*from ww w . ja v  a  2s.c  o m*/
    GL20.glAttachShader(pId, vsId);
    GL20.glAttachShader(pId, fsId);

    // Position information will be attribute 0
    GL20.glBindAttribLocation(pId, 0, "in_Position");
    // Color information will be attribute 1
    GL20.glBindAttribLocation(pId, 1, "in_Color");
    // Textute information will be attribute 2
    GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");

    GL20.glLinkProgram(pId);
    GL20.glValidateProgram(pId);

    // Get matrices uniform locations
    projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix");
    viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
    modelMatrixLocation = GL20.glGetUniformLocation(pId, "modelMatrix");

    decayLocation = GL20.glGetUniformLocation(pId, "decay");

    Game.exitOnGLError("setupShaders");
}

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

License:Open Source License

@Override
public void link() {
    ensureCreated("Program must be created to link.");
    // Link the program
    GL20.glLinkProgram(id);
    // Check program link success
    if (GL20.glGetProgrami(id, GL_LINK_STATUS) == GL_FALSE) {
        final int logLength = GL20.glGetProgrami(id, GL_INFO_LOG_LENGTH);
        throw new IllegalStateException(
                "Program could not be linked\n" + GL20.glGetProgramInfoLog(id, logLength));
    }//from  w  w  w . ja  v  a 2  s . c  o  m
    // Check for errors
    RenderUtil.checkGLError();

    // Validate the program
    GL20.glValidateProgram(id);
    // Check program validation success
    if (GL20.glGetProgrami(id, GL_VALIDATE_STATUS) == GL_FALSE) {
        final int logLength = GL20.glGetProgrami(id, GL_INFO_LOG_LENGTH);
        System.err.println("Program validation failed:\n" + GL20.glGetProgramInfoLog(id, logLength));
    }
    // Check for errors
    RenderUtil.checkGLError();

    /*
     * Load the program uniforms
     */
    // Get the maximum uniform name length
    final int maxNameLength = GL20.glGetProgrami(id, GL_ACTIVE_UNIFORM_MAX_LENGTH);
    // Create a buffer to store the name of the uniform
    final ByteBuffer nameBuffer = BufferUtils.createByteBuffer(maxNameLength);
    // Create a buffer to store the length of the uniform name
    final IntBuffer lengthBuffer = BufferUtils.createIntBuffer(1);
    // Create a buffer to store the uniform size
    final IntBuffer sizeBuffer = BufferUtils.createIntBuffer(1);
    // Create a buffer to stroe the uniform type
    final IntBuffer typeBuffer = BufferUtils.createIntBuffer(1);
    // Create a byte array to store the name in
    final byte[] nameBytes = new byte[maxNameLength];
    int textureUnit = 0;

    final int uniformCount = GL20.glGetProgrami(id, GL_ACTIVE_UNIFORMS);
    for (int i = 0; i < uniformCount; ++i) {
        // Retrieve the attributes of the uniform (length, size, type and name)
        GL20.glGetActiveUniform(id, i, lengthBuffer, sizeBuffer, typeBuffer, nameBuffer);

        // Get the length of the uniform name
        final int length = lengthBuffer.get();

        // Get the name from the buffer and put it in the byte[]
        nameBuffer.get(nameBytes, 0, length);

        final String name = new String(nameBytes, 0, length);

        // Convert the name buffer to a String
        this.uniforms.put(name, GL20.glGetUniformLocation(id, name));

        // Check if the uniform is a texture/sampler
        switch (typeBuffer.get()) {
        case GL_SAMPLER_2D:
        case GL_SAMPLER_CUBE:
            this.textures.put(textureUnit++, name);
            break;
        default:
            break;
        }

        // Clear the buffers
        lengthBuffer.clear();
        sizeBuffer.clear();
        typeBuffer.clear();
        nameBuffer.clear();
    }
    // Check for errors
    RenderUtil.checkGLError();
}

From source file:net.betabears.the2dlibrary.graphics.shader.ShaderProgram.java

@Override
public void init() {
    if (isLoaded && !isInited) {
        s0.createShader();/*from w  w w. j  a  va 2 s. c om*/
        s1.createShader();

        id = GL20.glCreateProgram();
        GL20.glAttachShader(id, s0.getID());
        GL20.glAttachShader(id, s1.getID());
        GL20.glLinkProgram(id);
        GL20.glValidateProgram(id);

        int i;
        while ((i = GL11.glGetError()) != 0) {
            LOGGER.log(Level.WARNING, "Error happened during creation of ShaderProgram. GL error code: {0}", i);
        }
        isInited = true;
    } else {
        LOGGER.log(Level.WARNING, "load() wasn't called before init() or init() has been called already.");
    }
}

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

License:Apache License

private int linkProgram() {
    int program = GL20.glCreateProgram();
    if (program == 0)
        return -1;

    GL20.glAttachShader(program, vertexShaderHandle);
    GL20.glAttachShader(program, fragmentShaderHandle);
    GL20.glLinkProgram(program);

    //      ByteBuffer tmp = ByteBuffer.allocateDirect(4);
    //      tmp.order(ByteOrder.nativeOrder());
    //      IntBuffer intbuf = tmp.asIntBuffer();

    GL20.glGetProgram(program, GL20.GL_LINK_STATUS, intbuf);
    int linked = intbuf.get(0);
    if (linked == 0) {
        return -1;
    }//from   ww  w . ja  v a  2s  .  co  m

    return program;
}

From source file:net.smert.frameworkgl.opengl.helpers.ShaderHelper.java

License:Apache License

public void link(int programID) {
    GL20.glLinkProgram(programID);
}

From source file:opengl.test.object.object.java

protected final void link() {
    GL20.glLinkProgram(programID);
    if (GL20.glGetProgrami(programID, GL20.GL_LINK_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the link program");
    }//  www.ja  va2 s  .  c  o m
}

From source file:opengl.test.object.tree.testobject.leaf.java

private void link() {
    GL20.glLinkProgram(programID);
    if (GL20.glGetProgrami(programID, GL20.GL_LINK_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the link program");
    }/*from  w w w  .  j  ava 2  s . com*/
}

From source file:org.bonsaimind.badgersvoyage.tools.planetstudio.Studio.java

License:Open Source License

public Studio(String title, int width, int height) throws LWJGLException {
    PixelFormat pixelFormat = new PixelFormat();
    ContextAttribs contextAttribs = new ContextAttribs(3, 2);
    contextAttribs.withForwardCompatible(true);
    contextAttribs.withProfileCore(true);

    Display.setDisplayMode(new DisplayMode(width, height));
    Display.setTitle(title);//w w w  .j av  a 2 s  .  co m
    Display.create(pixelFormat, contextAttribs);

    ErrorChecker.exitOnOpenGlError("Display creation.");

    programId = GL20.glCreateProgram();
    ErrorChecker.exitOnOpenGlError("Program creation.");

    int shaderId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
    //      GL20.glShaderSource(shaderId, "void main {\n"
    //            + "   gl_Normal = gl_NormalMatrix * gl_Normal; //Note that you can perform operations on matrices and vectors as if they were\n"
    //            + "                                                //primitive types. This is useful for simple, readable code like this.\n"
    //            + "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; //The order in which you times matrices and vertices is IMPORTANT.\n"
    //            + "    gl_FrontColor = gl_Color;   //These lines just pass on the colour value to the fragment shader.\n"
    //            + "    gl_BackColor = gl_Color;\n"
    //            + "}");
    GL20.glShaderSource(shaderId, "void main(void){gl_Position = ftransform();}");
    //      GL20.glShaderSource(shaderId, "#version 140\n"
    //            + "\n"
    //            + "uniform Transformation {\n"
    //            + "    mat4 projectionMatrix;\n"
    //            + "    mat4 viewMatrix;\n"
    //            + "    mat4 modelMatrix;\n"
    //            + "};\n"
    //            + "in vec4 in_Position;\n"
    //            + "\n"
    //            + "in vec3 vertex;\n"
    //            + "\n"
    //            + "void main() {\n"
    //            + "    gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;\n"
    //            + "}");
    //      GL20.glShaderSource(shaderId, "#version 150 core\n"
    //            + "\n"
    //            + "uniform mat4 projectionMatrix;\n"
    //            + "uniform mat4 viewMatrix;\n"
    //            + "uniform mat4 modelMatrix;\n"
    //            + "\n"
    //            + "in vec4 in_Position;\n"
    //            + "in vec4 in_Color;\n"
    //            + "in vec2 in_TextureCoord;\n"
    //            + "\n"
    //            + "out vec4 pass_Color;\n"
    //            + "out vec2 pass_TextureCoord;\n"
    //            + "\n"
    //            + "void main(void) {\n"
    //            + "   gl_Position = in_Position;\n"
    //            + "   gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;\n"
    //            + "\n"
    //            + "   pass_Color = in_Color;\n"
    //            + "   pass_TextureCoord = in_TextureCoord;\n"
    //            + "}");
    GL20.glCompileShader(shaderId);
    GL20.glAttachShader(programId, shaderId);

    //      int shaderId2 = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
    //      GL20.glShaderSource(shaderId2, "#version 150 core\n"
    //            + "\n"
    //            + "uniform sampler2D texture_diffuse;\n"
    //            + "\n"
    //            + "in vec4 pass_Color;\n"
    //            + "in vec2 pass_TextureCoord;\n"
    //            + "\n"
    //            + "out vec4 out_Color;\n"
    //            + "\n"
    //            + "void main(void) {\n"
    //            + "   out_Color = pass_Color;\n"
    //            + "   // Override out_Color with our texture pixel\n"
    //            + "   out_Color = vec4(0.5, 0.5, 0.5, 1); //texture2D(texture_diffuse, pass_TextureCoord);\n"
    //            + "}");
    //      GL20.glCompileShader(shaderId2);
    //      GL20.glAttachShader(programId, shaderId2);

    GL20.glLinkProgram(programId);

    ErrorChecker.exitOnOpenGlError("Program linking.");

    System.err.println(GL20.glGetProgramInfoLog(programId, 255));
    System.err.println();

    GL20.glValidateProgram(programId);
    ErrorChecker.exitOnOpenGlError("Program validation.");

    camera = new Camera(width / (float) height, new Vector3f(0, 0, 2.5f), 100f, 60f, 0.1f, programId);
    ErrorChecker.exitOnOpenGlError("Camera creation.");

    sphere = new Sphere(60, 0.5f);
    sphere.create(programId);
    ErrorChecker.exitOnOpenGlError("Sphere creation.");
}