src/org/lwjgl/demo/opengl/util/DemoUtils.java
public static int createShader(String resource, int type, String version) throws IOException {
		int shader = glCreateShader(type);

		ByteBuffer source = ioResourceToByteBuffer(resource, 8192);

		if ( version == null ) {
			PointerBuffer strings = BufferUtils.createPointerBuffer(1);
			IntBuffer lengths = BufferUtils.createIntBuffer(1);

			strings.put(0, source);
			lengths.put(0, source.remaining());

			glShaderSource(shader, strings, lengths);
		} else {
			PointerBuffer strings = BufferUtils.createPointerBuffer(2);
			IntBuffer lengths = BufferUtils.createIntBuffer(2);

			ByteBuffer preamble = memUTF8("#version " + version + "\n", false);

			strings.put(0, preamble);
			lengths.put(0, preamble.remaining());

			strings.put(1, source);
			lengths.put(1, source.remaining());

			glShaderSource(shader, strings, lengths);
		}

		glCompileShader(shader);
		int compiled = glGetShaderi(shader, GL_COMPILE_STATUS);
		String shaderLog = glGetShaderInfoLog(shader);
		if (shaderLog != null && shaderLog.trim().length() > 0) {
			System.err.println(shaderLog);
		}
		if (compiled == 0) {
			throw new AssertionError("Could not compile shader");
		}
		return shader;
	}
/**
	 * Create a shader object from the given classpath resource.
	 *
	 * @param resource
	 *            the class path
	 * @param type
	 *            the shader type
	 * @param version
	 *            the GLSL version to prepend to the shader source, or null
	 *
	 * @return the shader object id
	 *
	 * @throws IOException
	 */
Create a shader object from the given classpath resource.
@param resource
the class path
@param type
the shader type
@param version
the GLSL version to prepend to the shader source, or null

@return the shader object id


Create a shader object from the given classpath resource . @param resource the class path @param type the shader type @param version the GLSL version to prepend to the shader source or null @return the shader object id
public static int createShader(String resource, int type, String version) throws IOException {
		int shader = glCreateShader(type);
		ByteBuffer source = ioResourceToByteBuffer(resource, 8192);
		if ( version == null ) {
			PointerBuffer strings = BufferUtils.createPointerBuffer(1);
			IntBuffer lengths = BufferUtils.createIntBuffer(1);
			strings.put(0, source);
			lengths.put(0, source.remaining());
			glShaderSource(shader, strings, lengths);
		} else {
			PointerBuffer strings = BufferUtils.createPointerBuffer(2);
			IntBuffer lengths = BufferUtils.createIntBuffer(2);
			ByteBuffer preamble = memUTF8("#version " + version + "\n", false);
			strings.put(0, preamble);
			lengths.put(0, preamble.remaining());
			strings.put(1, source);
			lengths.put(1, source.remaining());
			glShaderSource(shader, strings, lengths);
		}
		glCompileShader(shader);
		int compiled = glGetShaderi(shader, GL_COMPILE_STATUS);
		String shaderLog = glGetShaderInfoLog(shader);
		if (shaderLog != null && shaderLog.trim().length() > 0) {
			System.err.println(shaderLog);
		}
		if (compiled == 0) {
			throw new AssertionError("Could not compile shader");
		}
		return shader;
	}
public static int createShader ( String resource , int type , String version ) throws IOException { int shader = glCreateShader ( type ) ; ByteBuffer source = ioResourceToByteBuffer ( resource , 8192 ) ; if ( version == null ) { PointerBuffer strings = BufferUtils . createPointerBuffer ( 1 ) ; IntBuffer lengths = BufferUtils . createIntBuffer ( 1 ) ; strings . put ( 0 , source ) ; lengths . put ( 0 , source . remaining ( ) ) ; glShaderSource ( shader , strings , lengths ) ; } else { PointerBuffer strings = BufferUtils . createPointerBuffer ( 2 ) ; IntBuffer lengths = BufferUtils . createIntBuffer ( 2 ) ; ByteBuffer preamble = memUTF8 ( "#version " + version + "\n" , false ) ; strings . put ( 0 , preamble ) ; lengths . put ( 0 , preamble . remaining ( ) ) ; strings . put ( 1 , source ) ; lengths . put ( 1 , source . remaining ( ) ) ; glShaderSource ( shader , strings , lengths ) ; } glCompileShader ( shader ) ; int compiled = glGetShaderi ( shader , GL_COMPILE_STATUS ) ; String shaderLog = glGetShaderInfoLog ( shader ) ; if ( shaderLog != null && shaderLog . trim ( ) . length ( ) > 0 ) { System . err . println ( shaderLog ) ; } if ( compiled == 0 ) { throw new AssertionError ( "Could not compile shader" ) ; } return shader ; }
Create a shader object from the given classpath resource.
Create a shader object from the given classpath resource .