Java Code Examples for com.jogamp.opengl.GL3#glGetShaderInfoLog()

The following examples show how to use com.jogamp.opengl.GL3#glGetShaderInfoLog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLTools.java    From constellation with Apache License 2.0 5 votes vote down vote up
public static String getShaderLog(final GL3 gl, final int shader) {
    final int[] maxLength = new int[1];
    gl.glGetShaderiv(shader, GL3.GL_INFO_LOG_LENGTH, maxLength, 0);
    if (maxLength[0] == 0) {
        return "";
    }

    final byte[] buf = new byte[maxLength[0]];
    final int[] length = new int[1];
    gl.glGetShaderInfoLog(shader, maxLength[0], length, 0, buf, 0);
    final String log = new String(buf);

    return log.trim();
}
 
Example 2
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 5 votes vote down vote up
/**
 * Initialize the shaders and the shader program
 * 
 * @param gl
 *            The GL context
 */
private void initShaders(final GL3 gl) {
	final int vertexShaderId = createShader(gl, GL3.GL_VERTEX_SHADER, "shaders/simulation.vert");
	final int fragmentShaderID = createShader(gl, GL3.GL_FRAGMENT_SHADER, "shaders/simulation.frag");

	shaderProgramID = gl.glCreateProgram();

	gl.glAttachShader(shaderProgramID, vertexShaderId);
	gl.glAttachShader(shaderProgramID, fragmentShaderID);
	gl.glLinkProgram(shaderProgramID);

	final IntBuffer linkStatus = Buffers.newDirectIntBuffer(1);
	gl.glGetShaderiv(shaderProgramID, GL3.GL_LINK_STATUS, linkStatus);
	if (linkStatus.get(0) == GL.GL_FALSE) {
		final IntBuffer logLength = Buffers.newDirectIntBuffer(1);

		gl.glGetShaderiv(shaderProgramID, GL3.GL_INFO_LOG_LENGTH, logLength);

		final ByteBuffer infoLog = Buffers.newDirectByteBuffer(logLength.get(0));
		gl.glGetShaderInfoLog(shaderProgramID, infoLog.limit(), logLength, infoLog);

		final byte[] infoLogArray = new byte[logLength.get(0)];
		infoLog.get(infoLogArray);

		final String errorString = new String(infoLogArray);
		System.err.println(errorString);
	}
}
 
Example 3
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 5 votes vote down vote up
/**
 * Creates a shader with the given type from the given file
 * 
 * @param gl
 * @param shaderType
 * @param file
 * @return
 */
private int createShader(final GL3 gl, final int shaderType, final String file) {
	final int shaderId = gl.glCreateShader(shaderType);
	try {
		gl.glShaderSource(shaderId, 1, new String[] { readAllLines(file) }, null);
		gl.glCompileShader(shaderId);
		final IntBuffer vertexBufferCompilationStatus = Buffers.newDirectIntBuffer(1);
		gl.glGetShaderiv(shaderId, GL3.GL_COMPILE_STATUS, vertexBufferCompilationStatus);
		if (vertexBufferCompilationStatus.get(0) == GL.GL_FALSE) {
			final IntBuffer logLength = Buffers.newDirectIntBuffer(1);

			gl.glGetShaderiv(shaderId, GL3.GL_INFO_LOG_LENGTH, logLength);

			final ByteBuffer infoLog = Buffers.newDirectByteBuffer(logLength.get(0));
			gl.glGetShaderInfoLog(shaderId, infoLog.limit(), logLength, infoLog);

			final byte[] infoLogArray = new byte[logLength.get(0)];
			infoLog.get(infoLogArray);

			final String errorString = new String(infoLogArray);
			System.err.println(errorString);
		}

		return shaderId;

	} catch (final IOException e) {
		e.printStackTrace();
	}

	return -1;
}