ThreatIndicatorGLRenderer.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. package de.tudarmstadt.informatik.hostage.ui.fragment.opengl;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.nio.ByteBuffer;
  5. import java.nio.ByteOrder;
  6. import java.nio.FloatBuffer;
  7. import java.util.Scanner;
  8. import javax.microedition.khronos.egl.EGLConfig;
  9. import javax.microedition.khronos.opengles.GL10;
  10. import android.content.Context;
  11. import android.content.res.AssetManager;
  12. import android.graphics.Bitmap;
  13. import android.graphics.BitmapFactory;
  14. import android.graphics.Color;
  15. import android.opengl.GLES20;
  16. import android.opengl.GLSurfaceView.Renderer;
  17. import android.opengl.GLUtils;
  18. import android.opengl.Matrix;
  19. import android.util.Log;
  20. import de.tudarmstadt.informatik.hostage.R;
  21. import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
  22. /**
  23. * @author Fabio Arnold
  24. *
  25. * ThreatIndicatorGLRenderer
  26. * This class is responsible for drawing an animation representing the current threat level.
  27. * Use the method setThreatLevel to set the state (0 to 3).
  28. */
  29. public class ThreatIndicatorGLRenderer implements Renderer {
  30. public enum ThreatLevel {
  31. NOT_MONITORING,
  32. NO_THREAT,
  33. PAST_THREAT,
  34. LIVE_THREAT
  35. }
  36. /**
  37. * Set the threat level which should be indicated
  38. * @param threatLevel
  39. */
  40. public static void setThreatLevel(ThreatLevel threatLevel) {
  41. mNextThreatLevel = threatLevel;
  42. }
  43. public static boolean showSpeechBubble = true;
  44. /**
  45. * Match the background color of the view holding this renderer
  46. * @param color 32 bit integer encoding the color
  47. */
  48. public static void setBackgroundColor(int color) {
  49. mBackgroundColor[0] = (float)Color.red(color) / 255.0f;
  50. mBackgroundColor[1] = (float)Color.green(color) / 255.0f;
  51. mBackgroundColor[2] = (float)Color.blue(color) / 255.0f;
  52. }
  53. private static float[] mBackgroundColor = new float[3];
  54. // OpenGL data
  55. private int mAnimatedProgram;
  56. private int mTexturedProgram;
  57. private float [] mModelview;
  58. private float [] mProjection;
  59. private float [] mMVP;
  60. private AnimatedMesh androidMesh = null;
  61. private AnimatedMesh beeMesh = null;
  62. private int androidTexture;
  63. private int beeTexture;
  64. private int speechBubbleTexture;
  65. private int mQuadVertexBuffer;
  66. private GLFont font = null;
  67. // threat state
  68. private static ThreatLevel mNextThreatLevel = ThreatLevel.NO_THREAT;
  69. private ThreatLevel mCurrentThreatLevel = ThreatLevel.NO_THREAT;
  70. private ThreatLevel mTargetThreatLevel = ThreatLevel.NO_THREAT;
  71. private float mThreatLevelTransition = 1.0f; // 1.0 means transition is complete
  72. private static boolean sPlayGreetingAnimation = true; // greet the first time
  73. private long mStartTimeMillis; // for animation
  74. public ThreatIndicatorGLRenderer() {
  75. mStartTimeMillis = System.currentTimeMillis();
  76. }
  77. /**
  78. * Initialization will be called after GL context is created and is current
  79. */
  80. public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
  81. GLES20.glClearColor(mBackgroundColor[0], mBackgroundColor[1], mBackgroundColor[2], 1.0f);
  82. GLES20.glEnable(GLES20.GL_DEPTH_TEST);
  83. GLES20.glEnable(GLES20.GL_CULL_FACE);
  84. GLES20.glEnable(GLES20.GL_TEXTURE_2D);
  85. AssetManager assets = MainActivity.getInstance().getAssets();
  86. try {
  87. InputStream is = assets.open("meshes/android.amh");
  88. androidMesh = new AnimatedMesh(is);
  89. /* play the greeting animation the first time the gets opened
  90. not each time the threatindicator gets created */
  91. if (sPlayGreetingAnimation) {
  92. androidMesh.startAction("greet", false, false);
  93. sPlayGreetingAnimation = false;
  94. } else if (mCurrentThreatLevel == ThreatLevel.NO_THREAT) { // default state
  95. androidMesh.startAction("happy", true, false); // play NO_THREAT animation
  96. }
  97. } catch (IOException e) {
  98. Log.e("gl", "Couldn't open android mesh");
  99. }
  100. androidTexture = loadTexture("textures/android-tex.png");
  101. try {
  102. InputStream is = assets.open("meshes/bee.amh");
  103. beeMesh = new AnimatedMesh(is);
  104. beeMesh.startAction("bee_armatureAct", true, false);
  105. } catch (IOException e) {
  106. Log.e("gl", "Couldn't open bee mesh");
  107. }
  108. beeTexture = loadTexture("textures/bee-tex.png");
  109. speechBubbleTexture = loadTexture("textures/speech-bubble.png");
  110. int buffers[] = new int[1];
  111. GLES20.glGenBuffers(1, buffers, 0); // buffer names
  112. mQuadVertexBuffer = buffers[0];
  113. font = new GLFont("fonts/komika.png", "fonts/komika.bin");
  114. mModelview = new float[16];
  115. Matrix.setIdentityM(mModelview, 0);
  116. mProjection = new float[16];
  117. mMVP = new float[16];
  118. // default shader
  119. String vertexSource = "attribute vec3 position; void main() {gl_Position = vec4(position, 1.0);}";
  120. String fragmentSource = "void main() {gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);}";
  121. try {
  122. vertexSource = inputStreamToString(assets.open("shaders/skinned.vert"));
  123. } catch (IOException e) {
  124. e.printStackTrace();
  125. }
  126. try {fragmentSource = inputStreamToString(assets.open("shaders/skinned.frag"));
  127. } catch (IOException e) {
  128. e.printStackTrace();
  129. }
  130. mAnimatedProgram = loadProgram(vertexSource, fragmentSource);
  131. mTexturedProgram = loadProgram(
  132. "uniform vec2 resolution;" // vertex
  133. + "attribute vec2 position;"
  134. + "attribute vec2 texCoord;"
  135. + "varying vec2 vertexTexCoord;"
  136. + "void main() {"
  137. + " vertexTexCoord = texCoord;"
  138. + " gl_Position = vec4(2.0 * (position / resolution) - 1.0, 0.0, 1.0);"
  139. + "}",
  140. "precision mediump float;"
  141. + "uniform sampler2D colormap;" // fragment
  142. + "uniform vec4 color;"
  143. + "varying vec2 vertexTexCoord;"
  144. + "void main() {"
  145. + " vec4 texel = texture2D(colormap, vertexTexCoord);"
  146. + " gl_FragColor = color * texel;"
  147. + "}");
  148. }
  149. private void updateAndroidAndBee() {
  150. // threat level state machine
  151. if (mTargetThreatLevel != mCurrentThreatLevel) {
  152. boolean blocked = false; // block until current action is completed
  153. if (mThreatLevelTransition == 0.0f) {
  154. if (androidMesh.isActionDone()) {
  155. switch (mTargetThreatLevel) {
  156. case NOT_MONITORING:
  157. androidMesh.startAction("sleep", false, false);
  158. break;
  159. case NO_THREAT:
  160. androidMesh.startAction("happy", true, false);
  161. break;
  162. case PAST_THREAT:
  163. androidMesh.startAction("fear", true, false);
  164. break;
  165. case LIVE_THREAT:
  166. androidMesh.startAction("panic", true, false);
  167. break;
  168. }
  169. } else blocked = true;
  170. }
  171. if (!blocked) {
  172. mThreatLevelTransition += 0.016f;
  173. if (mThreatLevelTransition >= 1.0f) {
  174. mCurrentThreatLevel = mTargetThreatLevel;
  175. mThreatLevelTransition = 1.0f;
  176. }
  177. }
  178. } else {
  179. if (mNextThreatLevel != mTargetThreatLevel) {
  180. mTargetThreatLevel = mNextThreatLevel;
  181. mThreatLevelTransition = 0.0f;
  182. // HACK!!! reverses the sleep animation to create smooth transition into other states
  183. if (mCurrentThreatLevel == ThreatLevel.NOT_MONITORING)
  184. androidMesh.startAction("sleep", false, true);
  185. }
  186. }
  187. androidMesh.tick(); // animate android
  188. }
  189. private void drawAndroidAndBee(double animTime) {
  190. GLES20.glUseProgram(mAnimatedProgram);
  191. int colorUniformLoc = GLES20.glGetUniformLocation(mAnimatedProgram, "color");
  192. int textureUniformLoc = GLES20.glGetUniformLocation(mAnimatedProgram, "texture");
  193. int mvpUniformLoc = GLES20.glGetUniformLocation(mAnimatedProgram, "mvp");
  194. // animate color
  195. final float[] whiteColor = {1.0f, 1.0f, 1.0f, 1.0f};
  196. final float[] greyColor = {0.5f, 0.5f, 0.5f, 1.0f};
  197. final float[] redColor = {2.0f, 0.4f, 0.2f, 1.0f};
  198. final float[] yellowColor = {1.1f * 255.0f / 166.0f, 1.2f * 255.0f / 200.0f, 0.0f, 1.0f};
  199. float[] currentColor = whiteColor;
  200. float blink = 0.5f + 0.5f * (float)Math.sin(12.0 * animTime);
  201. switch (mCurrentThreatLevel) {
  202. case NOT_MONITORING:
  203. currentColor = greyColor;
  204. break;
  205. case PAST_THREAT:
  206. currentColor = mixColor(blink, whiteColor, yellowColor);
  207. break;
  208. case LIVE_THREAT:
  209. currentColor = mixColor(blink, whiteColor, redColor);
  210. break;
  211. }
  212. if (mTargetThreatLevel != mCurrentThreatLevel) {
  213. float[] targetColor = whiteColor;
  214. switch (mTargetThreatLevel) {
  215. case NOT_MONITORING:
  216. targetColor = greyColor;
  217. break;
  218. case PAST_THREAT:
  219. targetColor = mixColor(blink, whiteColor, yellowColor);
  220. break;
  221. case LIVE_THREAT:
  222. targetColor = mixColor(blink, whiteColor, redColor);
  223. break;
  224. }
  225. currentColor = mixColor(mThreatLevelTransition, currentColor, targetColor);
  226. }
  227. GLES20.glUniform4fv(colorUniformLoc, 1, currentColor, 0);
  228. GLES20.glUniform1i(textureUniformLoc, 0);
  229. // animate camera
  230. Matrix.setIdentityM(mModelview, 0);
  231. if (mCurrentThreatLevel == ThreatLevel.LIVE_THREAT || mTargetThreatLevel == ThreatLevel.LIVE_THREAT) {
  232. float delta = 1.0f;
  233. if (mThreatLevelTransition < 0.4f) { // animate only during the first 40% of the transition
  234. delta = mThreatLevelTransition / 0.4f;
  235. delta = -2.0f * delta * delta * delta + 3.0f * delta * delta; // ease in/out
  236. }
  237. if (mTargetThreatLevel != ThreatLevel.LIVE_THREAT)
  238. delta = 1.0f - delta;
  239. Matrix.translateM(mModelview, 0, 0.0f, -0.6f - 0.2f * delta, -1.6f - 0.4f * delta); // 0.0f, -0.8f, -2.0f
  240. Matrix.rotateM(mModelview, 0, -85.0f + 5.0f * delta, 1.0f, 0.0f, 0.0f); // -80.0f
  241. } else {
  242. Matrix.translateM(mModelview, 0, 0.0f, -0.6f, -1.6f);
  243. Matrix.rotateM(mModelview, 0, -85.0f, 1.0f, 0.0f, 0.0f);
  244. }
  245. Matrix.multiplyMM(mMVP, 0, mProjection, 0, mModelview, 0);
  246. GLES20.glUniformMatrix4fv(mvpUniformLoc, 1, false, mMVP, 0);
  247. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, androidTexture);
  248. androidMesh.draw(mAnimatedProgram);
  249. // restore color
  250. GLES20.glUniform4fv(colorUniformLoc, 1, whiteColor, 0);
  251. if (mCurrentThreatLevel == ThreatLevel.LIVE_THREAT || mTargetThreatLevel == ThreatLevel.LIVE_THREAT) {
  252. // draw a bee rotating around the android
  253. float fadeIn = mThreatLevelTransition;
  254. if (mTargetThreatLevel != ThreatLevel.LIVE_THREAT) fadeIn = 1.0f - fadeIn; // fade out
  255. float beePositionZ = 2.0f * (1.0f - fadeIn) * (1.0f - fadeIn); // animate the bee going in/out
  256. final float beeSize = 0.2f;
  257. Matrix.rotateM(mModelview, 0, (float)((-240.0 * animTime) % 360.0), 0.0f, 0.0f, 1.0f); // rotate around android
  258. Matrix.translateM(mModelview, 0, 0.6f, 0.0f, 0.7f + 0.1f * (float)Math.sin(12.0 * animTime) + beePositionZ); // go up and down
  259. Matrix.rotateM(mModelview, 0, 20.0f * (float)Math.cos(12.0 * animTime), 1.0f, 0.0f, 0.0f); // rock back and forth
  260. Matrix.scaleM(mModelview, 0, beeSize, beeSize, beeSize);
  261. Matrix.multiplyMM(mMVP, 0, mProjection, 0, mModelview, 0);
  262. GLES20.glUniformMatrix4fv(mvpUniformLoc, 1, false, mMVP, 0);
  263. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, beeTexture);
  264. beeMesh.tick();
  265. beeMesh.draw(mAnimatedProgram);
  266. }
  267. }
  268. /**
  269. * Tries to render at 30 Hz (see bottom part)
  270. */
  271. public void onDrawFrame(GL10 arg0) {
  272. Context ctx = MainActivity.getInstance();
  273. long timeMillis = System.currentTimeMillis() - mStartTimeMillis;
  274. double animTime = 0.001 * (double)timeMillis; // in seconds
  275. // OpenGL drawing
  276. GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
  277. updateAndroidAndBee();
  278. drawAndroidAndBee(animTime);
  279. if (showSpeechBubble) {
  280. Log.i("GL", "drawing bubble");
  281. GLES20.glDisable(GLES20.GL_DEPTH_TEST);
  282. GLES20.glEnable(GLES20.GL_BLEND);
  283. GLES20.glDisable(GLES20.GL_CULL_FACE);
  284. GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
  285. GLES20.glUseProgram(mTexturedProgram);
  286. int resolutionUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "resolution");
  287. int textureUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "colormap");
  288. int colorUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "color");
  289. GLES20.glUniform2f(resolutionUniformLoc, 1024.0f, 1024.0f);
  290. GLES20.glUniform1i(textureUniformLoc, 0);
  291. GLES20.glUniform4f(colorUniformLoc, 1.0f, 1.0f, 1.0f, 0.8f);
  292. String message = "???";
  293. switch (mNextThreatLevel) {
  294. case NOT_MONITORING:
  295. message = ctx.getString(R.string.honeypot_not_monitoring);
  296. break;
  297. case NO_THREAT:
  298. message = ctx.getString(R.string.honeypot_no_threat);
  299. break;
  300. case PAST_THREAT:
  301. message = ctx.getString(R.string.honeypot_past_threat);
  302. break;
  303. case LIVE_THREAT:
  304. message = ctx.getString(R.string.honeypot_live_threat);
  305. break;
  306. }
  307. float textWidth = font.getTextWidth(message);
  308. float textHeight = 40.0f;
  309. float bubbleDiameter = 256.0f;
  310. float bubbleWidth = textWidth + bubbleDiameter;
  311. float bubbleHeight = bubbleDiameter;
  312. float y = 0.75f * 1024.0f + 32.0f * (float) Math.sin(2.0 * animTime);
  313. float x = 0.5f * 1024.0f + 16.0f * (float) Math.cos(1.0 * animTime);
  314. drawSpeechBubble(speechBubbleTexture, x - 0.5f * bubbleWidth, y - 0.5f * bubbleHeight,
  315. bubbleWidth, bubbleHeight);
  316. GLES20.glUniform4f(colorUniformLoc, 0.0f, 0.0f, 0.0f, 1.0f);
  317. font.drawText(mTexturedProgram, message, x - 0.5f * textWidth,
  318. y - 0.5f * textHeight);
  319. GLES20.glUseProgram(0);
  320. GLES20.glEnable(GLES20.GL_DEPTH_TEST);
  321. GLES20.glDisable(GLES20.GL_BLEND);
  322. }
  323. long deltaTime = System.currentTimeMillis() - mStartTimeMillis - timeMillis; // time for one frame
  324. if (deltaTime < 33) {
  325. try {
  326. Thread.sleep(33 - deltaTime); // sleep remaining time for 30 Hz
  327. } catch (InterruptedException e) {
  328. e.printStackTrace();
  329. }
  330. }
  331. }
  332. /**
  333. * Informs renderer of changed surface dimensions
  334. */
  335. public void onSurfaceChanged(GL10 arg0, int w, int h) {
  336. int width = w;
  337. int height = h;
  338. float aspectRatio = (float) w / (float) h;
  339. //Matrix.orthoM(mProjection, 0, -aspectRatio, aspectRatio, -1.0f, 1.0f, -1.0f, 1.0f);
  340. float near = 0.1f;
  341. float fov = 2.0f;
  342. Matrix.frustumM(mProjection, 0, near * -aspectRatio, near * aspectRatio, -near, near, fov * near, 100.0f);
  343. GLES20.glViewport(0, 0, width, height);
  344. }
  345. // some helper functions
  346. private void drawSpeechBubble(int texture, float x, float y, float w, float h) {
  347. float bubbleRadius = 128.0f;
  348. int vertexCount = 8;
  349. int vertexSize = (2+2)*4; // size in bytes
  350. FloatBuffer buffer = ByteBuffer.allocateDirect(vertexCount * vertexSize).order(ByteOrder.nativeOrder()).asFloatBuffer();
  351. buffer.put(x); buffer.put(y+h);
  352. buffer.put(0.0f); buffer.put(1.0f);
  353. buffer.put(x); buffer.put(y);
  354. buffer.put(0.0f); buffer.put(0.0f);
  355. buffer.put(x+bubbleRadius); buffer.put(y+h);
  356. buffer.put(0.5f); buffer.put(1.0f);
  357. buffer.put(x+bubbleRadius); buffer.put(y);
  358. buffer.put(0.5f); buffer.put(0.0f);
  359. buffer.put(x+w-bubbleRadius); buffer.put(y+h);
  360. buffer.put(0.5f); buffer.put(1.0f);
  361. buffer.put(x+w-bubbleRadius); buffer.put(y);
  362. buffer.put(0.5f); buffer.put(0.0f);
  363. buffer.put(x+w); buffer.put(y+h);
  364. buffer.put(1.0f); buffer.put(1.0f);
  365. buffer.put(x+w); buffer.put(y);
  366. buffer.put(1.0f); buffer.put(0.0f);
  367. buffer.position(0); // rewind
  368. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
  369. GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mQuadVertexBuffer);
  370. GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexSize * vertexCount, buffer, GLES20.GL_STREAM_DRAW);
  371. int positionIndex = GLES20.glGetAttribLocation(mTexturedProgram, "position");
  372. int texCoordIndex = GLES20.glGetAttribLocation(mTexturedProgram, "texCoord");
  373. GLES20.glEnableVertexAttribArray(positionIndex);
  374. GLES20.glEnableVertexAttribArray(texCoordIndex);
  375. GLES20.glVertexAttribPointer(positionIndex, 2, GLES20.GL_FLOAT, false, vertexSize, 0);
  376. GLES20.glVertexAttribPointer(texCoordIndex, 2, GLES20.GL_FLOAT, false, vertexSize, 8);
  377. GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, vertexCount);
  378. GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
  379. GLES20.glDisableVertexAttribArray(positionIndex);
  380. GLES20.glDisableVertexAttribArray(texCoordIndex);
  381. }
  382. private float[] mixColor(float alpha, float[] color1, float[] color2) {
  383. float[] color3 = new float[4];
  384. color3[0] = (1.0f - alpha) * color1[0] + alpha * color2[0];
  385. color3[1] = (1.0f - alpha) * color1[1] + alpha * color2[1];
  386. color3[2] = (1.0f - alpha) * color1[2] + alpha * color2[2];
  387. color3[3] = (1.0f - alpha) * color1[3] + alpha * color2[3];
  388. return color3;
  389. }
  390. public static int loadTexture(String filePath) {
  391. AssetManager assets = MainActivity.getInstance().getAssets();
  392. Bitmap bitmap;
  393. try {
  394. bitmap = BitmapFactory.decodeStream(assets.open(filePath));
  395. } catch (IOException e) {
  396. e.printStackTrace();
  397. return 0;
  398. }
  399. int[] names = {0};
  400. GLES20.glGenTextures(1, names, 0);
  401. int tex = names[0];
  402. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
  403. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
  404. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
  405. GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
  406. bitmap.recycle(); // memory is now gpu -> free it
  407. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
  408. return tex;
  409. }
  410. // see http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
  411. private static String inputStreamToString(InputStream is) {
  412. Scanner scanner = new Scanner(is);
  413. Scanner s = scanner.useDelimiter("\\A");
  414. String result = s.hasNext() ? s.next() : "";
  415. scanner.close();
  416. return result;
  417. }
  418. private static int loadShader(int type, String source) {
  419. int shader = GLES20.glCreateShader(type);
  420. GLES20.glShaderSource(shader, source);
  421. GLES20.glCompileShader(shader);
  422. Log.i("gl", GLES20.glGetShaderInfoLog(shader));
  423. return shader;
  424. }
  425. private static int loadProgram(String vertexSource, String fragmentSource) {
  426. int program = GLES20.glCreateProgram();
  427. GLES20.glAttachShader(program, loadShader(GLES20.GL_VERTEX_SHADER, vertexSource));
  428. GLES20.glAttachShader(program, loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource));
  429. GLES20.glLinkProgram(program);
  430. return program;
  431. }
  432. }