Search in sources :

Example 16 with ShaderProgram

use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.

the class SimpleVertexShader method create.

@Override
public void create() {
    // @off
    String vertexShader = "uniform mat4 u_mvpMatrix;                   \n" + "attribute vec4 a_position;                  \n" + "void main()                                 \n" + "{                                           \n" + "   gl_Position = u_mvpMatrix * a_position;  \n" + "}                            \n";
    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" + "}";
    // @on
    shader = new ShaderProgram(vertexShader, fragmentShader);
    mesh = Shapes.genCube();
    mesh.getVertexAttribute(Usage.Position).alias = "a_position";
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram)

Example 17 with ShaderProgram

use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.

the class GwtTest method create.

@Override
public void create() {
    Preferences pref = Gdx.app.getPreferences("test");
    boolean resultb = pref.getBoolean("test");
    int resulti = pref.getInteger("test");
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
    if (!shader.isCompiled())
        throw new GdxRuntimeException(shader.getLog());
    mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
    texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    String params = Gdx.files.internal("data/gwttestparams.txt").readString();
    numSprites = Integer.parseInt(params);
    batch = new SpriteBatch();
    positions = new ArrayList<Vector2>();
    for (int i = 0; i < numSprites; i++) {
        positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
    }
    sprite = new Sprite(texture);
    sprite.setSize(64, 64);
    sprite.setOrigin(32, 32);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    cache = font.newFontCache();
    cache.setColor(Color.RED);
    cache.setText("This is a Test", 0, 0);
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Mesh(com.badlogic.gdx.graphics.Mesh) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Vector2(com.badlogic.gdx.math.Vector2) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Preferences(com.badlogic.gdx.Preferences) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 18 with ShaderProgram

use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project commons-gdx by gemserk.

the class MeshRenderer method createDefaultShader.

/** 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" + //
    "uniform mat4 u_projectionViewMatrix;\n" + //
    "varying vec4 v_color;\n" + //
    "\n" + //
    "void main()\n" + //
    "{\n" + "   v_color = " + ShaderProgram.COLOR_ATTRIBUTE + //
    ";\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" + //
    "void main()\n" + //
    "{\n" + //
    "  gl_FragColor = v_color;\n" + // + "  gl_FragColor = vec4 ( 0.0, 1.0, 0.0, 1.0 );\n"//
    "}";
    ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
    if (shader.isCompiled() == false)
        throw new IllegalArgumentException("couldn't compile shader: " + shader.getLog());
    return shader;
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram)

Example 19 with ShaderProgram

use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project bdx by GoranM.

the class MaterialShader method compile.

public MaterialShader compile() {
    dispose();
    programData = new ShaderProgram(prefix + vertexShader, prefix + fragmentShader);
    if (!programData.isCompiled())
        throw new RuntimeException("Shader compilation error: " + programData.getLog());
    return this;
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram)

Example 20 with ShaderProgram

use of com.badlogic.gdx.graphics.glutils.ShaderProgram in project libgdx by libgdx.

the class SpriteBatch method createDefaultShader.

/** 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_projTrans;\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoords;\n" + //
    "\n" + //
    "void main()\n" + //
    "{\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" + //
    "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;
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram)

Aggregations

ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)31 Texture (com.badlogic.gdx.graphics.Texture)10 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)9 Mesh (com.badlogic.gdx.graphics.Mesh)8 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)2 Material (com.badlogic.gdx.graphics.g3d.Material)2 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)2 FirstPersonCameraController (com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)2 IndexBufferObject (com.badlogic.gdx.graphics.glutils.IndexBufferObject)2 VertexBufferObject (com.badlogic.gdx.graphics.glutils.VertexBufferObject)2