Skip to content

Instantly share code, notes, and snippets.

@defHLT
Last active August 29, 2015 14:23
Show Gist options
  • Save defHLT/ec7ef05aa3925d994e89 to your computer and use it in GitHub Desktop.
Save defHLT/ec7ef05aa3925d994e89 to your computer and use it in GitHub Desktop.
uniform mat4 u_projViewTrans;
attribute vec4 a_position;
void main()
{
gl_Position = u_projViewTrans * a_position;
}
precision lowp float;
void main()
{
gl_FragColor.rgb = vec3(0.0, 1.0, 0.0);
}
package io.github.mlatu.gravity;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Matrix4;
public class MyGdxGame extends ApplicationAdapter {
Texture texture;
private ShaderProgram shaderProgram;
private Mesh mesh;
TextureRegion textureRegion;
private SpriteBatch batch;
private Sprite sprite;
private OrthographicCamera cam = null;
private OrthographicCamera cam2d = null;
@Override
public void create () {
texture = new Texture(Gdx.files.internal("texture_default.jpg"));
batch = new SpriteBatch();
sprite = new Sprite(texture);
FileHandle f = Gdx.files.internal("f_shader.glsl");
FileHandle v = Gdx.files.internal("v_shader.glsl");
shaderProgram = new ShaderProgram(v, f);
//ShaderProgram.pedantic = false;
mesh = new Mesh(true, 4, 6, VertexAttribute.Position());//, VertexAttribute.TexCoords(0));
mesh.setVertices(new float[]
{-0.5f, -0.5f, 0,
0.5f, -0.5f, 0,
0.5f, 0.5f, 0,
-0.5f, 0.5f, 0, });
mesh.setIndices(new short[]{0, 1, 2, 2, 3, 0});
if(!shaderProgram.isCompiled()) {
String log = shaderProgram.getLog();
Gdx.app.log("Log", log);
}
}
@Override
public void render () {
Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Matrix4 o = new Matrix4();
o.setToOrtho2D(0f, 0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
shaderProgram.begin();
shaderProgram.setUniformMatrix("u_projViewTrans", o);
mesh.render(shaderProgram, GL20.GL_TRIANGLES);
shaderProgram.end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment