|
@@ -10,6 +10,7 @@ import javax.microedition.khronos.opengles.GL10;
|
|
|
import android.content.res.AssetManager;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
+import android.graphics.Color;
|
|
|
|
|
|
import android.opengl.GLES20;
|
|
|
import android.opengl.GLSurfaceView.Renderer;
|
|
@@ -23,6 +24,13 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
public static void setThreatLevel(int level) {
|
|
|
threatLevel = level;
|
|
|
}
|
|
|
+
|
|
|
+ public static void setBackgroundColor(int color) {
|
|
|
+ backgroundColor[0] = (float)Color.red(color) / 255.0f;
|
|
|
+ backgroundColor[1] = (float)Color.green(color) / 255.0f;
|
|
|
+ backgroundColor[2] = (float)Color.blue(color) / 255.0f;
|
|
|
+ }
|
|
|
+ private static float[] backgroundColor = new float[3];
|
|
|
|
|
|
public static AssetManager assets;
|
|
|
|
|
@@ -42,30 +50,6 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
|
|
|
public ThreatIndicatorGLRenderer() {}
|
|
|
|
|
|
- public int loadTexture(String filePath) {
|
|
|
- Bitmap bitmap = null;
|
|
|
- try {
|
|
|
- bitmap = BitmapFactory.decodeStream(assets.open(filePath));
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- int[] names = {0};
|
|
|
- GLES20.glGenTextures(1, names, 0);
|
|
|
- int tex = names[0];
|
|
|
- GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
|
|
|
-
|
|
|
- GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
|
|
|
- GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
|
|
|
- GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
|
|
|
- bitmap.recycle(); // memory is now gpu -> free it
|
|
|
-
|
|
|
- GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
|
|
|
-
|
|
|
- return tex;
|
|
|
- }
|
|
|
-
|
|
|
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
|
|
|
//GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
|
|
@@ -173,6 +157,30 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
GLES20.glViewport(0, 0, width, height);
|
|
|
}
|
|
|
|
|
|
+ public int loadTexture(String filePath) {
|
|
|
+ Bitmap bitmap = null;
|
|
|
+ try {
|
|
|
+ bitmap = BitmapFactory.decodeStream(assets.open(filePath));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int[] names = {0};
|
|
|
+ GLES20.glGenTextures(1, names, 0);
|
|
|
+ int tex = names[0];
|
|
|
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
|
|
|
+
|
|
|
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
|
|
|
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
|
|
|
+ GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
|
|
|
+ bitmap.recycle(); // memory is now gpu -> free it
|
|
|
+
|
|
|
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex);
|
|
|
+
|
|
|
+ return tex;
|
|
|
+ }
|
|
|
+
|
|
|
// see http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
|
|
|
private static String inputStreamToString(InputStream is) {
|
|
|
Scanner scanner = new Scanner(is);
|