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";
}
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"));
}
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;
}
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;
}
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;
}
Aggregations