|
@@ -49,7 +49,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
mNextThreatLevel = threatLevel;
|
|
|
}
|
|
|
|
|
|
- public static boolean showSpeechBubble = false;
|
|
|
+ public static boolean showSpeechBubble = true;
|
|
|
|
|
|
/**
|
|
|
* Match the background color of the view holding this renderer
|
|
@@ -130,7 +130,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
GLES20.glGenBuffers(1, buffers, 0); // buffer names
|
|
|
mQuadVertexBuffer = buffers[0];
|
|
|
|
|
|
- font = new GLFont("fonts/laCartoonerie.png", "fonts/laCartoonerie.bin");
|
|
|
+ font = new GLFont("fonts/komika.png", "fonts/komika.bin");
|
|
|
|
|
|
mModelview = new float[16];
|
|
|
Matrix.setIdentityM(mModelview, 0);
|
|
@@ -162,11 +162,11 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
+ "}",
|
|
|
"precision mediump float;"
|
|
|
+ "uniform sampler2D colormap;" // fragment
|
|
|
- + "uniform vec3 color;"
|
|
|
+ + "uniform vec4 color;"
|
|
|
+ "varying vec2 vertexTexCoord;"
|
|
|
+ "void main() {"
|
|
|
+ " vec4 texel = texture2D(colormap, vertexTexCoord);"
|
|
|
- + " gl_FragColor = vec4(color * texel.rgb, texel.a);"
|
|
|
+ + " gl_FragColor = color * texel;"
|
|
|
+ "}");
|
|
|
}
|
|
|
|
|
@@ -331,7 +331,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
int colorUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "color");
|
|
|
GLES20.glUniform2f(resolutionUniformLoc, 1024.0f, 1024.0f);
|
|
|
GLES20.glUniform1i(textureUniformLoc, 0);
|
|
|
- GLES20.glUniform3f(colorUniformLoc, 1.0f, 1.0f, 1.0f);
|
|
|
+ GLES20.glUniform4f(colorUniformLoc, 1.0f, 1.0f, 1.0f, 0.8f);
|
|
|
String message = "???";
|
|
|
switch (mNextThreatLevel) {
|
|
|
case NOT_MONITORING:
|
|
@@ -349,12 +349,14 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
}
|
|
|
float textWidth = font.getTextWidth(message);
|
|
|
float textHeight = 40.0f;
|
|
|
- float bubbleSize = textWidth + 100.0f;
|
|
|
+ float bubbleDiameter = 256.0f;
|
|
|
+ float bubbleWidth = textWidth + bubbleDiameter;
|
|
|
+ float bubbleHeight = bubbleDiameter;
|
|
|
float y = 0.75f * 1024.0f + 32.0f * (float) Math.sin(2.0 * animTime);
|
|
|
float x = 0.5f * 1024.0f + 16.0f * (float) Math.cos(1.0 * animTime);
|
|
|
- drawTexturedQuad(speechBubbleTexture, x - 0.5f * bubbleSize, y - 0.25f * bubbleSize,
|
|
|
- bubbleSize, 0.5f * bubbleSize);
|
|
|
- GLES20.glUniform3f(colorUniformLoc, 0.0f, 0.0f, 0.0f);
|
|
|
+ drawSpeechBubble(speechBubbleTexture, x - 0.5f * bubbleWidth, y - 0.5f * bubbleHeight,
|
|
|
+ bubbleWidth, bubbleHeight);
|
|
|
+ GLES20.glUniform4f(colorUniformLoc, 0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
font.drawText(mTexturedProgram, message, x - 0.5f * textWidth,
|
|
|
y - 0.5f * textHeight);
|
|
|
GLES20.glUseProgram(0);
|
|
@@ -387,18 +389,31 @@ public class ThreatIndicatorGLRenderer implements Renderer {
|
|
|
}
|
|
|
|
|
|
// some helper functions
|
|
|
- private void drawTexturedQuad(int texture, float x, float y, float w, float h) {
|
|
|
- int vertexCount = 4;
|
|
|
+ private void drawSpeechBubble(int texture, float x, float y, float w, float h) {
|
|
|
+ float bubbleRadius = 128.0f;
|
|
|
+ int vertexCount = 8;
|
|
|
int vertexSize = (2+2)*4; // size in bytes
|
|
|
FloatBuffer buffer = ByteBuffer.allocateDirect(vertexCount * vertexSize).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
|
- buffer.put(x); buffer.put(y);
|
|
|
- buffer.put(0.0f); buffer.put(0.0f);
|
|
|
- buffer.put(x+w); buffer.put(y);
|
|
|
- buffer.put(1.0f); buffer.put(0.0f);
|
|
|
buffer.put(x); buffer.put(y+h);
|
|
|
buffer.put(0.0f); buffer.put(1.0f);
|
|
|
+ buffer.put(x); buffer.put(y);
|
|
|
+ buffer.put(0.0f); buffer.put(0.0f);
|
|
|
+
|
|
|
+ buffer.put(x+bubbleRadius); buffer.put(y+h);
|
|
|
+ buffer.put(0.5f); buffer.put(1.0f);
|
|
|
+ buffer.put(x+bubbleRadius); buffer.put(y);
|
|
|
+ buffer.put(0.5f); buffer.put(0.0f);
|
|
|
+
|
|
|
+ buffer.put(x+w-bubbleRadius); buffer.put(y+h);
|
|
|
+ buffer.put(0.5f); buffer.put(1.0f);
|
|
|
+ buffer.put(x+w-bubbleRadius); buffer.put(y);
|
|
|
+ buffer.put(0.5f); buffer.put(0.0f);
|
|
|
+
|
|
|
buffer.put(x+w); buffer.put(y+h);
|
|
|
buffer.put(1.0f); buffer.put(1.0f);
|
|
|
+ buffer.put(x+w); buffer.put(y);
|
|
|
+ buffer.put(1.0f); buffer.put(0.0f);
|
|
|
+
|
|
|
buffer.position(0); // rewind
|
|
|
|
|
|
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
|