Search in sources :

Example 11 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 12 with ShaderProgram

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

the class ParticleShader method init.

@Override
public void init() {
    final ShaderProgram program = this.program;
    this.program = null;
    init(program, renderable);
    renderable = null;
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram)

Example 13 with ShaderProgram

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

the class CameraGroupStrategy method createDefaultShader.

private void 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_color.a = v_color.a * (255.0/254.0);\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" + "}";
    shader = new ShaderProgram(vertexShader, fragmentShader);
    if (shader.isCompiled() == false)
        throw new IllegalArgumentException("couldn't compile shader: " + shader.getLog());
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram)

Example 14 with ShaderProgram

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

the class DecalBatch method render.

/** Renders all decals to the buffer and flushes the buffer to the GL when full/done */
protected void render() {
    groupStrategy.beforeGroups();
    for (SortedIntList.Node<Array<Decal>> group : groupList) {
        groupStrategy.beforeGroup(group.index, group.value);
        ShaderProgram shader = groupStrategy.getGroupShader(group.index);
        render(shader, group.value);
        groupStrategy.afterGroup(group.index);
    }
    groupStrategy.afterGroups();
}
Also used : Array(com.badlogic.gdx.utils.Array) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) SortedIntList(com.badlogic.gdx.utils.SortedIntList)

Example 15 with ShaderProgram

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

the class SpriteCache method createDefaultShader.

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_color.a = v_color.a * (255.0/254.0);\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;
}
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