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