Last active
July 3, 2018 19:25
-
-
Save implicit-invocation/71e307f3ef11941d3c146ae651b6dd2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dongbat.example.game; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.Mesh; | |
import com.badlogic.gdx.graphics.VertexAttribute; | |
import com.badlogic.gdx.graphics.VertexAttributes.Usage; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | |
import io.anuke.gif.GifRecorder; | |
public class Core extends ApplicationAdapter { | |
private static final int NUM_VERTICES = 100000; | |
private Mesh mesh; | |
private ShaderProgram shader; | |
private float time = 0; | |
private SpriteBatch batch; | |
private GifRecorder gifRecorder; | |
@Override | |
public void create() { | |
mesh = new Mesh(true, NUM_VERTICES, 0, new VertexAttribute(Usage.Generic, 1, "vertexId")); | |
float[] ids = new float[NUM_VERTICES]; | |
for (int i = 0; i < NUM_VERTICES; i++) { | |
ids[i] = i; | |
} | |
mesh.setVertices(ids); | |
shader = new ShaderProgram(Gdx.files.internal("test.vs.glsl"), Gdx.files.internal("test.fs.glsl")); | |
ShaderProgram.pedantic = false; | |
if (shader.getLog().length() != 0) { | |
System.out.println(shader.getLog()); | |
} | |
batch = new SpriteBatch(); | |
gifRecorder = new GifRecorder(batch); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(0, 0, 0, 1); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); | |
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); | |
Gdx.gl.glEnable(0x8642); | |
time += Gdx.graphics.getDeltaTime() * 2; | |
shader.begin(); | |
shader.setUniformf("time", time); | |
shader.setUniformf("vertexCount", NUM_VERTICES); | |
shader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); | |
mesh.render(shader, GL20.GL_TRIANGLES); | |
shader.end(); | |
gifRecorder.update(); | |
} | |
@Override | |
public void dispose() { | |
mesh.dispose(); | |
shader.dispose(); | |
batch.dispose(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef GL_ES | |
#define LOWP lowp | |
precision mediump float; | |
#else | |
#define LOWP | |
#endif | |
varying vec4 v_color; | |
void main() { | |
gl_FragColor = v_color; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute float vertexId; | |
uniform float time; | |
uniform vec2 resolution; | |
uniform float vertexCount; | |
varying vec4 v_color; | |
void main() { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment