-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquareRenderer.java
91 lines (70 loc) · 2.65 KB
/
SquareRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package cg.bouncysquare;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL11;
import android.opengl.GLSurfaceView;
import java.lang.Math;
import android.content.Context;
public class SquareRenderer implements GLSurfaceView.Renderer {
private Square mSquare1;
private Square mSquare2;
private Context mContext;
private float mTransY;
private float mAngle;
public SquareRenderer(Context context)
{
float squareColorsYMCA[] =
{
1.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f
};
float squareColorsRGBA[] =
{
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f
};
mContext = context;
mSquare1 = new Square(squareColorsYMCA);
}
public void onDrawFrame(GL10 gl)
{
gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL11.GL_MODELVIEW);
gl.glEnableClientState(GL11.GL_VERTEX_ARRAY);
gl.glColor4f(1.0f,1.0f,1.0f,1.0f);
gl.glLoadIdentity();
gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -3.0f);
mSquare1.draw(gl);
gl.glLoadIdentity();
gl.glTranslatef((float)(Math.sin(mTransY)/2.0f),0.0f, -2.9f);
gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
mSquare1.draw(gl);
mTransY += .075f;
}
public void onSurfaceChanged(GL10 gl, int width, int height)
{
gl.glViewport(0, 0, width, height);
float ratio = (float) width / height;
gl.glMatrixMode(GL11.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl.glDisable(GL11.GL_DITHER);
gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,
GL11.GL_FASTEST);
gl.glClearColor(.0f,.5f,.5f,1.0f);
gl.glEnable(GL11.GL_CULL_FACE);
gl.glShadeModel(GL11.GL_SMOOTH);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glDisable(GL11.GL_DEPTH_TEST);
gl.glEnable(GL11.GL_BLEND);
mSquare1.setTextures(gl,mContext,R.drawable.goldengate,R.drawable.splash);
}
}