Example usage for org.lwjgl.opengl GL20 glCreateShader

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

Introduction

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

Prototype

@NativeType("GLuint")
public static int glCreateShader(@NativeType("GLenum") int type) 

Source Link

Document

Creates a shader object.

Usage

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

protected final void fragmentShader(String file) {
    this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
    GL20.glShaderSource(this.fragmentID, object.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");
    }// w w w .  j  av a2  s.  c  o  m
    GL20.glAttachShader(this.programID, this.fragmentID);

}

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

private void vertexShader(String file) {
    this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
    GL20.glShaderSource(this.vertexID, leaf.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  a 2s. c  o m*/
    GL20.glAttachShader(this.programID, this.vertexID);
}

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  w w w .  j  a v a2  s.  c  om
    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  a va  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 ww  w.j  av a  2s  .c  om*/
    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 va 2  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.j a  v  a 2s .c o m
    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  w w  w .j  a  v  a2  s .  c om
    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 int compileShader(int type, ByteBuffer src) throws ShaderException {
    int id = GL20.glCreateShader(type);

    GL20.glShaderSource(id, src);//w  w  w  . jav a2s.  co  m
    int err = GL11.glGetError();
    if (err != GL11.GL_NO_ERROR) {
        throw new ShaderException("Shader source failed, GL Error: 0x" + Integer.toHexString(err));
    }

    GL20.glCompileShader(id);
    err = GL11.glGetError();
    if (err != GL11.GL_NO_ERROR) {
        throw new ShaderException("Compile failed, GL Error: 0x" + Integer.toHexString(err));
    }

    return id;
}

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

License:Open Source License

public static int compileShader(String source, int type) {

    int shader = GL20.glCreateShader(type);
    GL20.glShaderSource(shader, source);
    GL20.glCompileShader(shader);// ww w  .  ja va  2 s .c  o m
    int status = GL20.glGetShader(shader, GL20.GL_COMPILE_STATUS);

    if (status != GL11.GL_TRUE) {
        String error = GL20.glGetShaderInfoLog(shader, 255);
        throw new ShaderCompileException("Compile Error in "
                + ((type == GL20.GL_FRAGMENT_SHADER) ? "Fragment Shader" : "VertexShader") + ": " + error);
    }
    return shader;
}