Refine search
private void createShader (Graphics graphics) { String vertexShader = "attribute vec4 a_Position; \n" + "attribute vec4 a_Color;\n" + "attribute vec2 a_texCoords;\n" + "varying vec4 v_Color;" + "varying vec2 v_texCoords; \n" + "void main() \n" + "{ \n" + " v_Color = a_Color;" + " v_texCoords = a_texCoords;\n" + " gl_Position = a_Position; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_Color;\n" + "varying vec2 v_texCoords; \n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_Color * texture2D(u_texture, v_texCoords);\n" + "}"; meshShader = new ShaderProgram(vertexShader, fragmentShader); if (meshShader.isCompiled() == false) throw new IllegalStateException(meshShader.getLog()); }
public void flush () { if (numVertices == 0) return; shader.begin(); shader.setUniformMatrix("u_projModelView", projModelView); for (int i = 0; i < numTexCoords; i++) shader.setUniformi(shaderUniformNames[i], i); mesh.setVertices(vertices, 0, vertexIdx); mesh.render(shader, primitiveType); shader.end(); numSetTexCoords = 0; vertexIdx = 0; numVertices = 0; }
@Override public void beforeGroups () { Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); shader.begin(); shader.setUniformMatrix("u_projectionViewMatrix", camera.combined); shader.setUniformi("u_texture", 0); }
@Override public void create () { camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.position.set(0, 1.5f, 1.5f); camera.lookAt(0, 0, 0); camera.update(); controller = new PerspectiveCamController(camera); mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE)); mesh.setVertices(new float[] {-1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, -1, 0, 0,}); mesh.setIndices(new short[] {0, 1, 2, 3}); shader = new ShaderProgram(Gdx.files.internal("data/shaders/flattex-vert.glsl").readString(), Gdx.files.internal( "data/shaders/flattex-frag.glsl").readString()); if (!shader.isCompiled()) throw new GdxRuntimeException("shader error: " + shader.getLog()); textureHW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true); MipMapGenerator.setUseHardwareMipMap(false); textureSW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true); currTexture = textureHW; createUI(); multiplexer = new InputMultiplexer(); Gdx.input.setInputProcessor(multiplexer); multiplexer.addProcessor(ui); multiplexer.addProcessor(controller); }
public void clicked (InputEvent event, float x, float y) { ShaderProgram prog = new ShaderProgram(Gdx.files.internal("data/shaders/projtex-vert.glsl").readString(), Gdx.files .internal("data/shaders/projtex-frag.glsl").readString()); if (prog.isCompiled() == false) { Gdx.app.log("GLSL ERROR", "Couldn't reload shaders:\n" + prog.getLog()); } else { projTexShader.dispose(); projTexShader = prog; } } });
private void bindAttributes(ShaderProgram shader, int[] locations) { final GL20 gl = Gdx.gl20; gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle); final int numAttributes = attributes.size(); if (locations == null) { for (int i = 0; i < numAttributes; i++) { final VertexAttribute attribute = attributes.get(i); final int location = shader.getAttributeLocation(attribute.alias); if (location < 0) continue; shader.enableVertexAttribute(location); shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset); } } else { for (int i = 0; i < numAttributes; i++) { final VertexAttribute attribute = attributes.get(i); final int location = locations[i]; if (location < 0) continue; shader.enableVertexAttribute(location); shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset); } } }
private void renderMesh (ShaderProgram shader, Matrix4 cam, Matrix4 projector, Matrix4 model, Mesh mesh, Color color) { position.set(this.projector.position); modelNormal.set(model).toNormalMatrix(); shader.setUniformMatrix("u_camera", cam); shader.setUniformMatrix("u_projector", projector); shader.setUniformf("u_projectorPos", position.x, position.y, position.z); shader.setUniformMatrix("u_model", model); shader.setUniformMatrix("u_modelNormal", modelNormal); shader.setUniformf("u_color", color.r, color.g, color.b); shader.setUniformi("u_texture", 0); mesh.render(shader, GL20.GL_TRIANGLES); }
public void render () { Gdx.gl20.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0); texture.bind(); Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE1); texture2.bind(); shader.begin(); shader.setUniformi("s_texture", 0); shader.setUniformi("s_texture2", 1); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); }
@Override public void create () { String vertexShader = "attribute vec4 vPosition; \n" + "void main() \n" + "{ \n" + " gl_Position = vPosition; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "void main() \n" + "{ \n" + " gl_FragColor = vec4 ( 1.0, 1.0, 1.0, 1.0 );\n" + "}"; shader = new ShaderProgram(vertexShader, fragmentShader); mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "vPosition")); float[] vertices = {0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f}; mesh.setVertices(vertices); }
public DepthShader (final Renderable renderable, final Config config, final String prefix, final String vertexShader, final String fragmentShader) { this(renderable, config, new ShaderProgram(prefix + vertexShader, prefix + fragmentShader)); }
private void setupMatrices () { combinedMatrix.set(projectionMatrix).mul(transformMatrix); if (customShader != null) { customShader.setUniformMatrix("u_projTrans", combinedMatrix); customShader.setUniformi("u_texture", 0); } else { shader.setUniformMatrix("u_projTrans", combinedMatrix); shader.setUniformi("u_texture", 0); } }
public final boolean set (final int uniform, final Vector3 value) { if (locations[uniform] < 0) return false; program.setUniformf(locations[uniform], value); return true; }
@Override public void end () { program.end(); }
/** Constructs a new ShaderProgram and immediately compiles it. * * @param vertexShader the vertex shader * @param fragmentShader the fragment shader */ public ShaderProgram (String vertexShader, String fragmentShader) { if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null"); if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null"); if (prependVertexCode != null && prependVertexCode.length() > 0) vertexShader = prependVertexCode + vertexShader; if (prependFragmentCode != null && prependFragmentCode.length() > 0) fragmentShader = prependFragmentCode + fragmentShader; this.vertexShaderSource = vertexShader; this.fragmentShaderSource = fragmentShader; this.matrix = BufferUtils.newFloatBuffer(16); compileShaders(vertexShader, fragmentShader); if (isCompiled()) { fetchAttributes(); fetchUniforms(); addManagedShader(Gdx.app, this); } }
@Override public void begin (Camera camera, RenderContext context) { this.context = context; shaderProgram.begin(); shaderProgram.setUniformMatrix("u_projViewTrans", camera.combined); context.setDepthTest(GL20.GL_LEQUAL); context.setCullFace(GL20.GL_BACK); }
public final boolean set (final int uniform, final int v1, final int v2, final int v3, final int v4) { if (locations[uniform] < 0) return false; program.setUniformi(locations[uniform], v1, v2, v3, v4); return true; }