Example usage for org.lwjgl.opengl GL20 glAttachShader

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

Introduction

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

Prototype

public static void glAttachShader(@NativeType("GLuint") int program, @NativeType("GLuint") int shader) 

Source Link

Document

Attaches a shader object to a program object.

Usage

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

private void fragmentShader(String file) {
    this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
    GL20.glShaderSource(this.fragmentID, leaf.sourceLoader(file));
    GL20.glCompileShader(this.fragmentID);
    if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the compile fragmentShader");
    }//from   ww  w. j a  v  a2 s.co m
    GL20.glAttachShader(this.programID, this.fragmentID);

}

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

private void vertexShader(String file) {
    this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
    GL20.glShaderSource(this.vertexID, traicay.sourceLoader(file));
    GL20.glCompileShader(this.vertexID);
    if (GL20.glGetShaderi(this.vertexID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the compile vertexShader");
    }//  w w  w  . j av  a  2 s .c o m
    GL20.glAttachShader(this.programID, this.vertexID);
}

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

private void fragmentShader(String file) {
    this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
    GL20.glShaderSource(this.fragmentID, traicay.sourceLoader(file));
    GL20.glCompileShader(this.fragmentID);
    if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the compile fragmentShader");
    }/*from  w  w  w.  ja  va 2  s .c o m*/
    GL20.glAttachShader(this.programID, this.fragmentID);

}

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

private void vertexShader(String file) {
    this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
    GL20.glShaderSource(this.vertexID, trunk.sourceLoader(file));
    GL20.glCompileShader(this.vertexID);
    if (GL20.glGetShaderi(this.vertexID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the compile vertexShader");
    }/*from  w w w.  j  a  v a2  s. c  o m*/
    GL20.glAttachShader(this.programID, this.vertexID);
}

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

private void fragmentShader(String file) {
    this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
    GL20.glShaderSource(this.fragmentID, trunk.sourceLoader(file));
    GL20.glCompileShader(this.fragmentID);
    if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        throw new RuntimeException("Khong the compile fragmentShader");
    }/*  ww  w .ja va2  s.  c om*/
    GL20.glAttachShader(this.programID, this.fragmentID);

}

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);/*from  ww  w.j a  v  a2 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.");
}

From source file:org.jogamp.glg2d.impl.shader.AbstractShaderPipeline.java

License:Apache License

protected void attachShaders() {
    if (vertexShaderFileName != null) {
        vertexShaderId = compileShader(GL20.GL_VERTEX_SHADER, getClass(), vertexShaderFileName);
        GL20.glAttachShader(programId, vertexShaderId);
    }//from w  w w  .  j  ava  2s .com

    if (geometryShaderFileName != null) {
        geometryShaderId = compileShader(GL32.GL_GEOMETRY_SHADER, getClass(), geometryShaderFileName);
        GL20.glAttachShader(programId, geometryShaderId);
    }

    if (fragmentShaderFileName != null) {
        fragmentShaderId = compileShader(GL20.GL_FRAGMENT_SHADER, getClass(), fragmentShaderFileName);
        GL20.glAttachShader(programId, fragmentShaderId);
    }
}

From source file:org.oscim.gdx.LwjglGL20.java

License:Apache License

public void attachShader(int program, int shader) {
    GL20.glAttachShader(program, shader);
}

From source file:org.spout.engine.renderer.shader.ClientShader.java

License:Open Source License

private void doCompileShader(String vsource, String fsource) {
    if (((Client) Spout.getEngine()).getRenderMode() == RenderMode.GL11) {
        return;//from  w  w  w  . ja v a2 s . co  m
    }

    //Create a new Shader object on the GPU
    program = GL20.glCreateProgram();

    int vShader = ShaderHelper.compileShader(vsource, GL20.GL_VERTEX_SHADER);
    GL20.glAttachShader(program, vShader);

    int fShader = ShaderHelper.compileShader(fsource, GL20.GL_FRAGMENT_SHADER);
    GL20.glAttachShader(program, fShader);

    GL20.glLinkProgram(program);

    int status = GL20.glGetProgram(program, GL20.GL_LINK_STATUS);
    if (status != GL11.GL_TRUE) {
        String error = GL20.glGetProgramInfoLog(program, 255);
        throw new ShaderCompileException("Link Error: " + error);
    }
    if (validateShader) {
        GL20.glValidateProgram(this.program);
        if (GL20.glGetProgram(program, GL20.GL_VALIDATE_STATUS) != GL11.GL_TRUE) {
            String info = GL20.glGetProgramInfoLog(program, 255);
            System.out.println("Validate Log: \n" + info);
        }

        System.out.println("Attached Shaders: " + GL20.glGetProgram(program, GL20.GL_ATTACHED_SHADERS));
        int activeAttributes = GL20.glGetProgram(program, GL20.GL_ACTIVE_ATTRIBUTES);
        System.out.println("Active Attributes: " + activeAttributes);
        int maxAttributeLength = GL20.glGetProgram(program, GL20.GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);
        for (int i = 0; i < activeAttributes; i++) {
            System.out.println("\t" + GL20.glGetActiveAttrib(program, i, maxAttributeLength));
        }

        int activeUniforms = GL20.glGetProgram(program, GL20.GL_ACTIVE_UNIFORMS);
        System.out.println("Active Uniforms: " + activeUniforms);
        int maxUniformLength = GL20.glGetProgram(program, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH);
        for (int i = 0; i < activeUniforms; i++) {
            System.out.println("\t" + GL20.glGetActiveUniform(program, i, maxUniformLength));
        }
    }
    System.out.println("Compiled Shader with id: " + program);
}

From source file:org.terasology.rendering.assets.GLSLShaderProgramInstance.java

License:Apache License

private void compileShaderProgram(int featureHash) {
    compileShader(GL20.GL_FRAGMENT_SHADER, featureHash);
    compileShader(GL20.GL_VERTEX_SHADER, featureHash);

    int shaderProgram = GL20.glCreateProgram();
    shaderPrograms.put(featureHash, shaderProgram);

    GL20.glAttachShader(shaderProgram, fragmentPrograms.get(featureHash));
    GL20.glAttachShader(shaderProgram, vertexPrograms.get(featureHash));
    GL20.glLinkProgram(shaderProgram);/*from ww  w .ja  v  a  2s . c o  m*/
    GL20.glValidateProgram(shaderProgram);
}