Java Code Examples for com.badlogic.gdx.graphics.glutils.ShaderProgram#getLog()

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShaderProgram#getLog() . 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: ShaderUtils.java    From Mundus with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and links shader.
 *
 * @param vertexShader
 *            path to vertex shader
 * @param fragmentShader
 *            path to fragment shader
 *
 * @return compiled shader program
 */
public static ShaderProgram compile(String vertexShader, String fragmentShader) {
    String vert;
    String frag;

    if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        vert = Gdx.files.internal(vertexShader).readString();
        frag = Gdx.files.internal(fragmentShader).readString();
    } else {
        vert = Gdx.files.classpath(vertexShader).readString();
        frag = Gdx.files.classpath(fragmentShader).readString();
    }

    ShaderProgram program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }

    return program;
}
 
Example 2
Source File: VfxGLUtils.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public static ShaderProgram compileShader(FileHandle vertexFile, FileHandle fragmentFile, String defines) {
    if (fragmentFile == null) {
        throw new IllegalArgumentException("Vertex shader file cannot be null.");
    }
    if (vertexFile == null) {
        throw new IllegalArgumentException("Fragment shader file cannot be null.");
    }
    if (defines == null) {
        throw new IllegalArgumentException("Defines cannot be null.");
    }

    StringBuilder sb = new StringBuilder();
    sb.append("Compiling \"").append(vertexFile.name()).append('/').append(fragmentFile.name()).append('\"');
    if (defines.length() > 0) {
        sb.append(" w/ (").append(defines.replace("\n", ", ")).append(")");
    }
    sb.append("...");
    Gdx.app.log(TAG, sb.toString());

    String prependVert = prependVertexCode + defines;
    String prependFrag = prependFragmentCode + defines;
    String srcVert = vertexFile.readString();
    String srcFrag = fragmentFile.readString();

    ShaderProgram shader = new ShaderProgram(prependVert + "\n" + srcVert, prependFrag + "\n" + srcFrag);

    if (!shader.isCompiled()) {
        throw new GdxRuntimeException("Shader compile error: " + vertexFile.name() + "/" + fragmentFile.name() + "\n" + shader.getLog());
    }
    return shader;
}
 
Example 3
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private IBLBuilder() {
	shapes = new ShapeRenderer(20);
	shapes.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);

	sunShader = new ShaderProgram(
			Gdx.files.classpath("net/mgsx/gltf/shaders/ibl-sun.vs.glsl"), 
			Gdx.files.classpath("net/mgsx/gltf/shaders/ibl-sun.fs.glsl"));
	if(!sunShader.isCompiled()) throw new GdxRuntimeException(sunShader.getLog());
	
	sunShapes = new ShapeRenderer(20, sunShader);
	sunShapes.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);
}
 
Example 4
Source File: EditorTerrainShader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public EditorTerrainShader() {
    String vertexShader = "\n#define PICKER\n" + Gdx.files.classpath(VERTEX_SHADER).readString();
    String fragmentShader = "\n#define PICKER\n" + Gdx.files.classpath(FRAGMENT_SHADER).readString();

    program = new ShaderProgram(vertexShader, fragmentShader);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }
}
 
Example 5
Source File: PickerCommons.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private ShaderProgram loadShader (String vertFile, String fragFile) {
	ShaderProgram program = new ShaderProgram(
			Gdx.files.classpath("com/kotcrab/vis/ui/widget/color/internal/" + vertFile),
			Gdx.files.classpath("com/kotcrab/vis/ui/widget/color/internal/" + fragFile));

	if (program.isCompiled() == false) {
		throw new IllegalStateException("ColorPicker shader compilation failed. Shader: " + vertFile + ", " + fragFile + ": " + program.getLog());
	}

	return program;
}
 
Example 6
Source File: Box2dLightCustomShaderTest.java    From box2dlights with Apache License 2.0 4 votes vote down vote up
private ShaderProgram createNormalShader () {
	String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
		+ "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
		+ "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
		+ "uniform mat4 u_projTrans;\n" //
		+ "uniform float u_rot;\n" //
		+ "varying vec4 v_color;\n" //
		+ "varying vec2 v_texCoords;\n" //
		+ "varying mat2 v_rot;\n" //
		+ "\n" //
		+ "void main()\n" //
		+ "{\n" //
		+ "   vec2 rad = vec2(-sin(u_rot), cos(u_rot));\n" //
		+ "   v_rot = mat2(rad.y, -rad.x, rad.x, rad.y);\n" //
		+ "   v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" //
		+ "   v_color.a = v_color.a * (255.0/254.0);\n" //
		+ "   v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" //
		+ "   gl_Position =  u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" //
		+ "}\n";
	String fragmentShader = "#ifdef GL_ES\n" //
		+ "#define LOWP lowp\n" //
		+ "precision mediump float;\n" //
		+ "#else\n" //
		+ "#define LOWP \n" //
		+ "#endif\n" //
		+ "varying LOWP vec4 v_color;\n" //
		+ "varying vec2 v_texCoords;\n" //
		+ "varying mat2 v_rot;\n" //
		+ "uniform sampler2D u_texture;\n" //
		+ "void main()\n"//
		+ "{\n" //
		+ "  vec4 normal = texture2D(u_texture, v_texCoords).rgba;\n" //
		// got to translate normal vector to -1, 1 range
		+ "  vec2 rotated = v_rot * (normal.xy * 2.0 - 1.0);\n" //
		// and back to 0, 1
		+ "  rotated = (rotated.xy / 2.0 + 0.5 );\n" //
		+ "  gl_FragColor = vec4(rotated.xy, normal.z, normal.a);\n" //
		+ "}";

	ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
	if (!shader.isCompiled()) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
	return shader;
}