Skip to content

Commit

Permalink
gl20 can be switched off
Browse files Browse the repository at this point in the history
  • Loading branch information
godrin committed Sep 28, 2012
1 parent b83d620 commit 1a58ae6
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 75 deletions.
2 changes: 1 addition & 1 deletion defend-android/assets/data/shaders/cloud.vert
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main()
v_Color=a_mycolor;
v_Color.a*=u_opacity;
vec4 a_position=u_position;
float d=(1.0f+sin(u_time+a_distance+a_angle)*0.1f)*a_distance;
float d=(1.0+sin(u_time+a_distance+a_angle)*0.1)*a_distance;
vec4 delta=vec4(sin(a_angle),cos(a_angle),0,0)*d*u_size;
a_position+=delta;
gl_Position=world*a_position;
Expand Down
10 changes: 7 additions & 3 deletions defend-android/assets/data/shaders/round_explosion.vert
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ uniform float u_opacity;

void main()
{
float s;
s=10.0*u_time;
s=sin(s);
v_Color=a_mycolor;
v_Color.a*=u_opacity;
v_Color.g=sin(u_time*10.0f);
v_Color.b=sin(u_time*10.0f);
v_Color.g=s;
v_Color.b=s;
vec4 a_position=u_position;
float d=a_distance*u_time/1.0f; //(1.0f+sin(u_time+a_distance+a_angle)*0.1f)*a_distance;
float d=a_distance*u_time;
d/=1.0;
vec4 delta=vec4(sin(a_angle),cos(a_angle),0,0)*d*u_size;
a_position+=delta;
gl_Position=world*a_position;
Expand Down
2 changes: 1 addition & 1 deletion defend-android/src/com/cdm/defend/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = true;
cfg.useGL20 = false;

//AndroidApplicationConfiguration settings = new AndroidApplicationConfiguration();
//settings.resolutionStrategy = new FillResolutionStrategy();
Expand Down
2 changes: 1 addition & 1 deletion defend-desktop/src/com/cdm/defend/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "defend";
cfg.useGL20 = true;
cfg.useGL20 = false;
cfg.width = 800;
cfg.height = 480;

Expand Down
2 changes: 1 addition & 1 deletion defend/src/com/cdm/defend/DefendGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void mywait(float delta) {
int ms = (int) (delta * 1000);

int wait = (1000 / 60) - ms;
if (wait > 2) {
if (wait > 15) {
Thread.sleep(wait);
}
} catch (InterruptedException e) {
Expand Down
2 changes: 2 additions & 0 deletions defend/src/com/cdm/view/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ public void render(PolySprite sprite, Position pos, float size,

public void render(WorldCallback callback, Position pos, float size,
float angle) {
if(Gdx.gl20==null)
return;
initGlSettings();
// FIXME: new
Matrix4 p = new Matrix4();
Expand Down
105 changes: 54 additions & 51 deletions defend/src/com/cdm/view/elements/shots/RoundExplosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,62 +30,64 @@ public class RoundExplosion extends PositionedDisplayEffect {
public RoundExplosion(Position pPos, Level pLevel) {
level = pLevel;
pos = new Position(pPos.to(Position.LEVEL_REF));
if (mesh == null) {
mesh = new Mesh(true, SEGMENTS * 6, 0, new VertexAttribute(
Usage.Position, 1, "a_distance"), new VertexAttribute(
Usage.ColorPacked, 4, "a_mycolor"), new VertexAttribute(
Usage.Generic, 1, "a_angle"));

float color = Color.toFloatBits(255, 255, 255, 255);
float vs[] = new float[SEGMENTS * 6 * 3];

int j = 0;
float r0 = 1;
float r1 = 1.4f;
for (int i = 0; i < SEGMENTS; i++) {
float a0 = i * 2 * Cloud.M_PI / (SEGMENTS + 2);
float a1 = (i + 1) * 2 * Cloud.M_PI / (SEGMENTS + 2);

vs[j++] = r0;
vs[j++] = color;
vs[j++] = a0;

vs[j++] = r1;
vs[j++] = color;
vs[j++] = a0;

vs[j++] = r0;
vs[j++] = color;
vs[j++] = a1;

vs[j++] = r0;
vs[j++] = color;
vs[j++] = a1;

vs[j++] = r1;
vs[j++] = color;
vs[j++] = a0;

vs[j++] = r1;
vs[j++] = color;
vs[j++] = a1;
if (Gdx.gl20 != null) {
if (mesh == null) {
mesh = new Mesh(true, SEGMENTS * 6, 0, new VertexAttribute(
Usage.Position, 1, "a_distance"), new VertexAttribute(
Usage.ColorPacked, 4, "a_mycolor"),
new VertexAttribute(Usage.Generic, 1, "a_angle"));

}
mesh.setVertices(vs);
float color = Color.toFloatBits(255, 255, 255, 255);
float vs[] = new float[SEGMENTS * 6 * 3];

meshShader = SimpleShader.createShader(Gdx.graphics,
"round_explosion");
int j = 0;
float r0 = 1;
float r1 = 1.4f;
for (int i = 0; i < SEGMENTS; i++) {
float a0 = i * 2 * Cloud.M_PI / (SEGMENTS + 2);
float a1 = (i + 1) * 2 * Cloud.M_PI / (SEGMENTS + 2);

}
vs[j++] = r0;
vs[j++] = color;
vs[j++] = a0;

vs[j++] = r1;
vs[j++] = color;
vs[j++] = a0;

vs[j++] = r0;
vs[j++] = color;
vs[j++] = a1;

vs[j++] = r0;
vs[j++] = color;
vs[j++] = a1;

vs[j++] = r1;
vs[j++] = color;
vs[j++] = a0;

painter = new WorldCallback() {
vs[j++] = r1;
vs[j++] = color;
vs[j++] = a1;

}
mesh.setVertices(vs);

meshShader = SimpleShader.createShader(Gdx.graphics,
"round_explosion");

@Override
public void callback(Matrix4 world) {
drawIt(world, 1);
drawIt(world, 0.5f);
}
};

painter = new WorldCallback() {

@Override
public void callback(Matrix4 world) {
drawIt(world, 1);
drawIt(world, 0.5f);
}
};
}

}

Expand Down Expand Up @@ -118,7 +120,8 @@ public void move(float time) {

@Override
public void draw(IRenderer renderer) {
renderer.render(painter, getPosition(), 1, 0);
if (Gdx.gl20 != null)
renderer.render(painter, getPosition(), 1, 0);

}

Expand Down
38 changes: 21 additions & 17 deletions defend/src/com/cdm/view/enemy/types/Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Cloud {
private float[] px = new float[4];
private float size = 0.0f;
private int sizing = 1;
private float opacity=1.0f;
private float opacity = 1.0f;

public Cloud(float mean, float delta, int segments) {
radii = new ArrayList<Float>(segments);
Expand Down Expand Up @@ -125,23 +125,27 @@ public Cloud(float mean, float delta, int segments) {

mesh.setVertices(vs);

meshShader = SimpleShader.createShader(Gdx.graphics, "cloud");
if (Gdx.gl20 != null)
meshShader = SimpleShader.createShader(Gdx.graphics, "cloud");
}

public void draw(Matrix4 world) {
meshShader.begin();
meshShader.setUniformf("u_time", currentTime);
meshShader.setUniformf("u_size", size);
meshShader.setUniformf("u_opacity", opacity);
px[0] = pos.x;
px[1] = pos.y;
px[2] = 0;
px[3] = 1;
meshShader.setUniformMatrix("world", world);
meshShader.setUniform4fv("u_position", px, 0, 4);

mesh.render(meshShader, GL20.GL_TRIANGLES);
meshShader.end();
if (Gdx.gl20 != null) {

meshShader.begin();
meshShader.setUniformf("u_time", currentTime);
meshShader.setUniformf("u_size", size);
meshShader.setUniformf("u_opacity", opacity);
px[0] = pos.x;
px[1] = pos.y;
px[2] = 0;
px[3] = 1;
meshShader.setUniformMatrix("world", world);
meshShader.setUniform4fv("u_position", px, 0, 4);

mesh.render(meshShader, GL20.GL_TRIANGLES);
meshShader.end();
}
}

public interface ShrinkedCallback {
Expand All @@ -161,9 +165,9 @@ public void move(float t) {
if (sizing != 0) {

size += sizing * t * SKRINK_SPEED;
if(sizing<0) {
if (sizing < 0) {
size += sizing * t * SKRINK_SPEED;
opacity+= sizing * t * SKRINK_SPEED*3;
opacity += sizing * t * SKRINK_SPEED * 3;
}
if (size < 0) {
size = 0;
Expand Down

0 comments on commit 1a58ae6

Please sign in to comment.