Esempio n. 1
0
  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 =
        "precision mediump float;\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());
  }
Esempio n. 2
0
  private void createShader() {
    // this shader tells opengl where to put things
    String vertexShader =
        "attribute vec4 a_position;    \n"
            + "void main()                   \n"
            + "{                             \n"
            + "   gl_Position = a_position;  \n"
            + "}                             \n";

    // this one tells it what goes in between the points (i.e
    // colour/texture)
    String fragmentShader =
        "#ifdef GL_ES                \n"
            + "precision mediump float;    \n"
            + "#endif                      \n"
            + "void main()                 \n"
            + "{                           \n"
            + "  gl_FragColor = vec4(1.0,0.0,0.0,1.0);	\n"
            + "}";

    // make an actual shader from our strings
    meshShader = new ShaderProgram(vertexShader, fragmentShader);

    // check there's no shader compile errors
    if (!meshShader.isCompiled()) throw new IllegalStateException(meshShader.getLog());
  }
Esempio n. 3
0
  protected static ShaderProgram createMeshShader() {

    final String VERT_SHADER =
        "attribute vec2 a_position;\n"
            + "attribute vec4 a_color;\n"
            + "uniform mat4 u_projTrans;\n"
            + "varying vec4 vColor;\n"
            + "void main() {\n"
            + "	vColor = a_color;\n"
            + "	gl_Position =  u_projTrans * vec4(a_position.xy, 0.0, 1.0);\n"
            + "}";

    final String FRAG_SHADER =
        "#ifdef GL_ES\n"
            + "precision mediump float;\n"
            + "#endif\n"
            + "varying vec4 vColor;\n"
            + "void main() {\n"
            + "	gl_FragColor = vColor;\n"
            + "}";

    ShaderProgram.pedantic = false;
    ShaderProgram shader = new ShaderProgram(VERT_SHADER, FRAG_SHADER);
    String log = shader.getLog();
    if (!shader.isCompiled()) throw new GdxRuntimeException(log);
    if (log != null && log.length() != 0) System.out.println("Shader Log: " + log);
    return shader;
  }
  @Override
  public void create() {
    ShaderProgram.pedantic = false;

    String vs = Gdx.files.internal("signed/vertex.glsl").readString();
    String fs = Gdx.files.internal("signed/fragment.glsl").readString();

    shader = new ShaderProgram(vs, fs);

    if (!shader.isCompiled()) {
      throw new IllegalArgumentException(
          "Error compiling distance field shader: " + shader.getLog());
    }

    mesh =
        new Mesh(true, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, "a_position"));
    float[] vertices = {1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0};

    short[] indices = {
      0, 1, 2,
      2, 3, 0
    };
    mesh.setVertices(vertices);
    mesh.setIndices(indices);

    startTime = TimeUtils.millis();
  }
Esempio n. 5
0
 public ShaderProgram createShader() {
   ShaderProgram shader =
       new ShaderProgram(
           Gdx.files.internal("data/distort.vs"), Gdx.files.internal("data/distort.fs"));
   if (shader.isCompiled() == false)
     throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
   return shader;
 }
Esempio n. 6
0
 public static ShaderProgram loadShader(String vertexPath, String fragmentPath) {
   ShaderProgram shader =
       new ShaderProgram(Gdx.files.internal(vertexPath), Gdx.files.internal(fragmentPath));
   if (!shader.isCompiled())
     throw new IllegalArgumentException("Error compiling shader: " + shader.getLog());
   Log.log(
       "Shader loaded successfully (vertex: " + vertexPath + ", fragment: " + fragmentPath + ")");
   return shader;
 }
  @Override
  public ShaderProgram load(
      final AssetManager assetManager,
      final String fileName,
      final FileHandle file,
      final AssetLoaderParameters<ShaderProgram> parameter) {
    final ShaderProgram shader =
        new ShaderProgram(
            resolve(fileName + VERTEX_SHADER_SUFFIX), resolve(fileName + FRAGMENT_SHADER_SUFFIX));
    if (shader.isCompiled() == false) {

      Gdx.app.log("ShaderAssetLoader", "Shader compiled failed. Error: " + shader.getLog());
      throw new RuntimeException("Shader compile failed: " + shader.getLog());
    }

    Gdx.app.log("ShaderAssetLoader", "Shader compiled successfully");
    return shader;
  }
Esempio n. 8
0
 public void setElement(SceneElement e) {
   super.setElement(e);
   RuntimeDrawable<?> r = (RuntimeDrawable<?>) assetHandler.getRuntimeAsset(transition.getMask());
   texture = r.getTextureHandle();
   offset = new Vector3();
   if (maskShader == null) {
     maskShader =
         new ShaderProgram(
             assetHandler.getTextFile("@binary/shaders/mask.vert"),
             assetHandler.getTextFile("@binary/shaders/mask.frag"));
     if (maskShader.getLog().length() != 0) logger.warn(maskShader.getLog());
     nextSceneBuffer = new FrameBuffer(Format.RGBA8888, 800, 600, false);
   }
   maskShader.begin();
   maskShader.setUniformi("mask_texture", 1);
   maskShader.setAttributef("a_sizes", 800, 600, r.getWidth(), r.getHeight());
   maskShader.end();
 }
  public ShaderProgram getShaderProgram() {
    ShaderProgram temp = new ShaderProgram(this.vertexShader, this.fragmentShader);

    if (temp.isCompiled() == false) {
      Gdx.app.log("ShaderError", temp.getLog());
      System.exit(0);
    }

    return temp;
  }
Esempio n. 10
0
  private void initializeShaders() {
    String vertexShader = "shaders/blur.vert";
    String fragmentShader = "shaders/blur.frag";

    ShaderProgram.pedantic = false;

    blurShader =
        new ShaderProgram(Gdx.files.internal(vertexShader), Gdx.files.internal(fragmentShader));
    if (!blurShader.isCompiled()) {
      System.err.println(blurShader.getLog());
      System.exit(0);
    }
    if (blurShader.getLog().length() != 0) System.out.println(blurShader.getLog());

    blurShader.begin();
    blurShader.setUniformf("dir", 0f, 0f);
    blurShader.setUniformf("resolution", FBO_SIZE);
    blurShader.setUniformf("radius", blurAmount);
    blurShader.end();
  }
Esempio n. 11
0
  /**
   * Returns a new instance of the default shader used by SpriteBatch for GL2 when no shader is
   * specified.
   */
  public static ShaderProgram createDefaultShader() {
    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" //
            + "#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" //
            + "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("couldn't compile shader: " + shader.getLog());
    return shader;
  }
Esempio n. 12
0
  public static void load() {
    fontDistanceFieldShader =
        new ShaderProgram(
            Gdx.files.internal("assets/font/font.vert"),
            Gdx.files.internal("assets/font/font.frag"));
    if (!fontDistanceFieldShader.isCompiled()) {
      Gdx.app.error("fontShader", "compilation failed:\n" + fontDistanceFieldShader.getLog());
    }

    Texture fontTexture = new Texture(Gdx.files.internal("assets/font/consolas.png"), true);
    fontTexture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);

    consolasFont =
        new BitmapFont(
            Gdx.files.internal("assets/font/consolas.fnt"), new TextureRegion(fontTexture), false);

    Gdx.app.log("Assets", "Finished loading assets");
  }
Esempio n. 13
0
  @Override
  public void create() {
    // Load UI
    gameHud = new GameHud(this, world);

    ShaderProgram.pedantic = false;
    program =
        new ShaderProgram(
            Gdx.files.internal("shaders/sepia.vsh"), Gdx.files.internal("shaders/sepia.fsh"));

    if (!program.isCompiled()) {
      System.out.println(program.getLog());
    }

    camera = new OrthoCamera();
    Timer.startGameTime();
    resize(Settings.getWidth(), Settings.getHeight());
  }
Esempio n. 14
0
  private void init() {
    batch = new SpriteBatch();
    camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH, Constants.VIEWPORT_HEIGHT);
    camera.position.set(0, 0, 0);
    camera.update();

    cameraGUI = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT);
    cameraGUI.position.set(0, 0, 0);
    cameraGUI.setToOrtho(true);
    cameraGUI.update();

    b2debugRenderer = new Box2DDebugRenderer();

    shaderMonochrome =
        new ShaderProgram(
            Gdx.files.internal(Constants.shaderMonochromeVertex),
            Gdx.files.internal(Constants.shaderMonochromeFragment));
    if (!shaderMonochrome.isCompiled()) {
      String msg = "Could not compile shader program: " + shaderMonochrome.getLog();
      throw new GdxRuntimeException(msg);
    }
  }