List of usage examples for com.badlogic.gdx.graphics.glutils ShaderProgram ShaderProgram
public ShaderProgram(FileHandle vertexShader, FileHandle fragmentShader)
From source file:airfoil.Main.java
License:Open Source License
@Override public void create() { Gdx.input.setInputProcessor(this); ShaderProgram.pedantic = false;/*ww w .j av a2s .com*/ this.bodyShader = new ShaderProgram(Gdx.files.internal("data/shaders/body.vert.glsl").readString(), Gdx.files.internal("data/shaders/body.frag.glsl").readString()); this.alive = this.bodyShader.isCompiled(); if (!this.alive) { Gdx.app.error(Main.Title, "Error compiling body shader " + this.bodyShader.getLog()); Gdx.app.exit(); } else { this.axesShader = new ShaderProgram(Gdx.files.internal("data/shaders/axes.vert.glsl").readString(), Gdx.files.internal("data/shaders/axes.frag.glsl").readString()); this.alive = this.axesShader.isCompiled(); if (!this.alive) { Gdx.app.error(Main.Title, "Error compiling axes shader " + this.axesShader.getLog()); Gdx.app.exit(); } } }
From source file:color.guard.GameplayScreen.java
License:Open Source License
@Override public void show() { guiRandom = new RNG(new Lathe32RNG(0x1337BEEFFEEDL)); Gdx.gl.glDisable(GL20.GL_BLEND);/*from www. j a va2 s . c om*/ viewport = new PixelPerfectViewport(Scaling.fill, visualWidth, visualHeight); //viewport = new ScreenViewport(); //tempVector3 = new Vector3(); viewport.getCamera().update(); //prevCameraPosition = viewport.getCamera().position.cpy(); nextCameraPosition = viewport.getCamera().position.cpy(); atlas = new TextureAtlas("Iso_Mini.atlas"); palettes = new Texture("palettes.png"); tempSB = new StringBuilder(16); font = new BitmapFont(Gdx.files.internal("NanoOKExtended.fnt"), atlas.findRegion("NanoOKExtended")); //font.getData().setScale(2f); font.setColor(1f / 255f, 1f, 1f, 1f); //displayString = state.world.mapGen.atlas.getAt(0); String s, r; terrains = new TextureAtlas.AtlasRegion[WorldState.terrains.length << 2]; for (int i = 0; i < terrains.length >> 2; i++) { terrains[i * 4] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face0", 0); terrains[i * 4 + 1] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face1", 0); terrains[i * 4 + 2] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face2", 0); terrains[i * 4 + 3] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face3", 0); } ; int pieceCount = PieceKind.kinds.size(), facilityCount = PieceKind.facilities.size(), totalCount = pieceCount + facilityCount << 2; PieceKind p; standing = new Animation[totalCount]; acting0 = new Animation[totalCount]; acting1 = new Animation[totalCount]; dying = new Animation[totalCount]; receiving0 = new Animation[totalCount]; receiving1 = new Animation[totalCount]; for (int i = 0; i < pieceCount; i++) { p = PieceKind.kinds.getAt(i); s = p.visual + "_Large_face"; standing[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0), Animation.PlayMode.LOOP); standing[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1), Animation.PlayMode.LOOP); standing[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2), Animation.PlayMode.LOOP); standing[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3), Animation.PlayMode.LOOP); s = p.visual + "_Large_face"; if ((p.weapons & 2) != 0) { acting0[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_attack_0")); acting0[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_attack_0")); acting0[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_attack_0")); acting0[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_attack_0")); r = p.show[0] + "_face"; receiving0[i << 2] = new Animation<>(0.10f, atlas.createSprites(r + 0 + "_strength_" + p.shownStrengths[0])); receiving0[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(r + 1 + "_strength_" + p.shownStrengths[0])); receiving0[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(r + 2 + "_strength_" + p.shownStrengths[0])); receiving0[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(r + 3 + "_strength_" + p.shownStrengths[0])); } if ((p.weapons & 1) != 0) { acting1[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_attack_1")); acting1[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_attack_1")); acting1[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_attack_1")); acting1[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_attack_1")); r = p.show[1] + "_face"; receiving1[i << 2] = new Animation<>(0.10f, atlas.createSprites(r + 0 + "_strength_" + p.shownStrengths[1])); receiving1[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(r + 1 + "_strength_" + p.shownStrengths[1])); receiving1[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(r + 2 + "_strength_" + p.shownStrengths[1])); receiving1[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(r + 3 + "_strength_" + p.shownStrengths[1])); } dying[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_death")); dying[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_death")); dying[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_death")); dying[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_death")); } for (int i = 0; i < facilityCount; i++) { p = PieceKind.facilities.getAt(i); s = p.visual + "_Large_face"; standing[pieceCount + i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0), Animation.PlayMode.LOOP); standing[pieceCount + i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1), Animation.PlayMode.LOOP); standing[pieceCount + i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2), Animation.PlayMode.LOOP); standing[pieceCount + i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3), Animation.PlayMode.LOOP); s = p.visual + "_Large_face"; dying[pieceCount + i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_death")); dying[pieceCount + i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_death")); dying[pieceCount + i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_death")); dying[pieceCount + i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_death")); } glp = new GLProfiler(Gdx.graphics); glp.enable(); state.world.startBattle(state.world.factions); state.world.battle.resistanceMaps(); final Coord playerPos = state.world.battle.pieces.firstKey(); targetCell = playerPos; playerPiece = state.world.battle.pieces.getAt(0); dijkstra = new DijkstraMap(ArrayTools.fill('.', mapWidth, mapHeight), DijkstraMap.Measurement.MANHATTAN, new StatefulRNG(new Lathe32RNG(123456789, 987654321))); dijkstra.initializeCost(state.world.battle.resistances[playerPiece.pieceKind.mobility]); viewport.getCamera().position.set(32 * (playerPos.y - playerPos.x) + 9f, 16 * (playerPos.y + playerPos.x) + 13f, 0f); viewport.getCamera().update(); //prevCameraPosition = viewport.getCamera().position.cpy(); nextCameraPosition = viewport.getCamera().position.cpy(); //fog = new Noise.Layered3D(SeededNoise.instance, 2, 0.015); /*pieces = new int[mapWidth][mapHeight]; int[] tempOrdering = new int[pieceCount]; for (int x = mapWidth - 1; x >= 0; x--) { CELL_WISE: for (int y = mapHeight - 1; y >= 0; y--) { if(guiRandom.next(4) == 0) { guiRandom.randomOrdering(pieceCount, tempOrdering); for (int i = 0; i < pieceCount; i++) { if(PieceKind.kinds.getAt(tempOrdering[i]).mobilities[map[x][y]] < 6) { pieces[x][y] = tempOrdering[i] << 2 | guiRandom.next(2); continue CELL_WISE; } } } pieces[x][y] = -1; } } */ String vertex = "attribute vec4 a_position;\n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_projTrans;\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "void main()\n" + "{\n" + "v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" + "v_color.a = v_color.a * (255.0/254.0);\n" + //* (256.0/255.0) "v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" + "gl_Position = u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" + "}\n"; String fragment = "#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" + "uniform sampler2D u_texture;\n" + "uniform sampler2D u_texPalette;\n" + "void main()\n" + "{\n" + "vec4 color = texture2D(u_texture, v_texCoords);\n" + "vec2 index = vec2(color.r * 255.0 / 255.5, v_color.r);\n" + "gl_FragColor = vec4(texture2D(u_texPalette, index).rgb, color.a);\n" + "}\n"; // String fragment = // "#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" + // "uniform sampler2D u_texture;\n" + // "uniform sampler2D u_texPalette;\n" + // "// The MIT License\n" + // "// Copyright 2013 Inigo Quilez\n" + // "// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" + // "// Gradient Noise 3D : https://www.shadertoy.com/view/Xsl3Dl\n" + // "//===============================================================================================\n" + // "vec3 hash( vec3 p ) // replace this by something better\n" + // "{\n" + // " p = vec3( dot(p,vec3(127.1,311.7, 74.7)),\n" + // " dot(p,vec3(269.5,183.3,246.1)),\n" + // " dot(p,vec3(113.5,271.9,124.6)));\n" + // " return -1.0 + 2.0*fract(sin(p)*43758.5453123);\n" + // "}\n" + // "float noise(vec3 p)\n" + // "{\n" + // " vec3 i = floor(p);\n" + // " vec3 f = fract(p);\n" + // " vec3 u = f*f*(3.0-2.0*f);\n" + // " return " + // " mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ), \n" + // " dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),\n" + // " mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ), \n" + // " dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),\n" + // " mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ), \n" + // " dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),\n" + // " mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ), \n" + // " dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z)" + // ";\n" + // "}\n" + // "const mat3 m = mat3( 0.00, 0.80, 0.60,\n" + // " -0.80, 0.36, -0.48,\n" + // " -0.60, -0.48, 0.64 );\n"+ // "// End of MIT-licensed code\n"+ // //Jim Hejl and Richard Burgess-Dawson's tone mapping formula // "vec3 tone(vec3 texColor, LOWP float change)\n" + // "{\n" + // "vec3 x = clamp((texColor * 0.666) - 0.004, 0.0, 100.0);\n" + // "return mix(texColor, (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06), change);\n" + // "}\n" + // "void main()\n" + // "{\n" + // "vec4 color = texture2D(u_texture, v_texCoords);\n" + // "vec2 index = vec2(color.r * 255.0 / 255.5, v_color.r);\n" + // "vec3 q = vec3(0.01125 * gl_FragCoord.xy, v_color.g * 2.75);\n" + //// "float f = 0.5000*noise( q ); q = m*q*2.01;\n" + //// "f += 0.3125*noise( q ); q = m*q*2.02;\n" + //// "f += 0.1875*noise( q );\n" + //// "f += 0.0625*noise( q ); q = m*q*2.01;\n" + // "gl_FragColor = vec4(tone(texture2D(u_texPalette, index).rgb, 0.65 - noise(q) * 0.75), color.a);\n" + // "}\n"; indexShader = new ShaderProgram(vertex, fragment); if (!indexShader.isCompiled()) throw new GdxRuntimeException("Error compiling shader: " + indexShader.getLog()); map = ArrayTools.copy(state.world.worldMap); for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { map[x][y] = map[x][y] * 4 + guiRandom.next(2); } } batch = new SpriteBatch(); proc = new InputAdapter() { @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { if (inputMode == INPUT_LOCKED) return false; inputMode = INPUT_LOCKED; nextCameraPosition.set(screenX, screenY, 0); viewport.unproject(nextCameraPosition); //32 * y - 32 * x, 16 * y + 16 * x /* nx = 32 * y - 32 * x ny = 16 * y + 16 * x nx + 2ny = 64y nx - 2ny = -64x */ targetCell = Coord.get( MathUtils.round((nextCameraPosition.x - nextCameraPosition.y * 2f + 32f) / -64f), MathUtils.round((nextCameraPosition.x + nextCameraPosition.y * 2f - 96f) / 64f)); dijkstra.clearGoals(); dijkstra.findPath(playerPiece.pieceKind.stats[PieceKind.MOV], 20, state.world.battle.pieces.keySet(), null, state.world.battle.pieces.firstKey(), targetCell); return true; } @Override public boolean keyDown(int keycode) { if (inputMode == INPUT_LOCKED) return false; switch (keycode) { case Input.Keys.RIGHT: lastArrow = Direction.LEFT; break; case Input.Keys.LEFT: lastArrow = Direction.RIGHT; break; case Input.Keys.UP: lastArrow = Direction.DOWN; break; case Input.Keys.DOWN: lastArrow = Direction.UP; break; //default: lastArrow = Direction.NONE; default: return false; } targetCell = playerPos.translate(lastArrow); dijkstra.clearGoals(); dijkstra.findPath(playerPiece.pieceKind.stats[PieceKind.MOV], 20, state.world.battle.pieces.keySet(), null, state.world.battle.pieces.firstKey(), targetCell); inputMode = INPUT_LOCKED; return true; } }; Gdx.input.setInputProcessor(proc); }
From source file:com.andgate.ikou.Ikou.java
License:Open Source License
private void loadShader() { fontShader = new ShaderProgram(Gdx.files.internal(Constants.FONT_VERT_SHADER), Gdx.files.internal(Constants.FONT_FRAG_SHADER)); if (!fontShader.isCompiled()) { Gdx.app.error(TAG + " fontShader", "compilation failed:\n" + fontShader.getLog()); }/*w w w. j a v a 2s.c o m*/ bloom = new Bloom(); bloom.setClearColor(1.0f, 1.0f, 1.0f, 1.0f); bloom.setTreshold(0.6f); bloom.setBloomIntesity(1.5f); }
From source file:com.anythingmachine.gdxwrapper.SpriteCache.java
License:Apache License
static ShaderProgram createDefaultShader() { if (!true)/*from w w w . ja va2s .c om*/ return null; String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n" // + "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" // + "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" // + "uniform mat4 u_projectionViewMatrix;\n" // + "varying vec4 v_color;\n" // + "varying vec2 v_texCoords;\n" // + "\n" // + "void main()\n" // + "{\n" // + " v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" // + " v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" // + " gl_Position = u_projectionViewMatrix * " + ShaderProgram.POSITION_ATTRIBUTE + ";\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" // + "}"; ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader); if (shader.isCompiled() == false) throw new IllegalArgumentException("Error compiling shader: " + shader.getLog()); return shader; }
From source file:com.badlogic.gdx.tests.dragome.examples.HelloTriangle.java
License:Apache License
@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);//from w ww. jav a 2 s .c o m }
From source file:com.badlogic.gdx.tests.g3d.ShaderLoader.java
License:Apache License
public ShaderProgram load(String vertex, String fragment) { StringBuilder out = new StringBuilder(); load(out, vertex);/*from w w w. j a v a2 s. c o m*/ vertex = out.toString(); includes.clear(); out.setLength(0); load(out, fragment); fragment = out.toString(); includes.clear(); return new ShaderProgram(vertex, fragment); }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.classical.MainShader.java
License:Apache License
public MainShader(final Renderable renderable, final Config config, final String prefix, final String vertexShader, final String fragmentShader) { this(renderable, config, new ShaderProgram(prefix + vertexShader, prefix + fragmentShader)); }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.classical.Pass1Shader.java
License:Apache License
public Pass1Shader(final Renderable renderable, final Config config, final String prefix, final String vertexShader, final String fragmentShader) { this(renderable, config, new ShaderProgram(prefix + vertexShader, prefix + fragmentShader)); }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.classical.Pass2Shader.java
License:Apache License
public Pass2Shader(final Renderable renderable, final Config config, final String prefix, final String vertexShader, final String fragmentShader) { this(renderable, config, new ShaderProgram(prefix + vertexShader, prefix + fragmentShader)); }
From source file:com.badlogic.gdx.tests.gles2.MipMap2D.java
License:Apache License
@Override public void create() { String vertexShader = "uniform float u_offset; \n" + "attribute vec4 a_position; \n" + "attribute vec2 a_texCoord; \n" + "varying vec2 v_texCoord; \n" + "void main() \n" + "{ \n" + " gl_Position = a_position; \n" + " gl_Position.x += u_offset;\n" + " v_texCoord = a_texCoord; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec2 v_texCoord; \n" + "uniform sampler2D s_texture; \n" + "void main() \n" + "{ \n" + " gl_FragColor = texture2D( s_texture, v_texCoord );\n" + "} \n"; shader = new ShaderProgram(vertexShader, fragmentShader); mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 4, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord")); float[] vertices = { -0.5f, 0.5f, 0.0f, 1.5f, // Position 0 0.0f, 0.0f, // TexCoord 0 -0.5f, -0.5f, 0.0f, 0.75f, // Position 1 0.0f, 1.0f, // TexCoord 1 0.5f, -0.5f, 0.0f, 0.75f, // Position 2 1.0f, 1.0f, // TexCoord 2 0.5f, 0.5f, 0.0f, 1.5f, // Position 3 1.0f, 0.0f // TexCoord 3 };/*from www .j a v a 2s . co m*/ short[] indices = { 0, 1, 2, 0, 2, 3 }; mesh.setVertices(vertices); mesh.setIndices(indices); createTexture(); }