Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extracted fps view into a separate class

This should be temporary. I hope to move the FPS counter to a billboard
sprite
  • Loading branch information...
commit 44c00453725253cd89c1fd31f6a44eec6a5bd37d 1 parent e2c03d9
@bryanl authored
View
2  src/com/osesm/randy/framework/FPSCounter.java
@@ -12,7 +12,7 @@ public FPSCounter(Simulation simulation) {
public void logFrame() {
frames++;
if (System.nanoTime() - startTime >= 1000000000) {
- simulation.setStatus("fps: " + frames);
+ simulation.setStatus("frames per second: " + frames);
frames = 0;
startTime = System.nanoTime();
}
View
17 src/com/osesm/randy/framework/Simulation.java
@@ -3,9 +3,6 @@
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
-import com.osesm.randy.framework.gl.ShaderCompiler;
-import com.osesm.randy.lab.R;
-
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
@@ -13,7 +10,10 @@
import android.util.Log;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
-import android.widget.TextView;
+
+import com.osesm.randy.framework.gl.ShaderCompiler;
+import com.osesm.randy.lab.FPSView;
+import com.osesm.randy.lab.R;
public abstract class Simulation extends Activity implements Renderer {
@@ -32,7 +32,7 @@
long startTime = System.nanoTime();
private ShaderCompiler shaderCompiler;
- private TextView statusBar;
+ private FPSView statusBar;
public void debug(String message) {
Log.d(TAG, message);
@@ -44,7 +44,6 @@ public void run() {
statusBar.setText(message);
}
});
-
}
@Override
@@ -64,9 +63,9 @@ public void onCreate(Bundle savedInstanceState) {
private void addStatusBar(RelativeLayout view) {
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- statusBar = new TextView(this);
- statusBar.setText("frames per second: 999");
-
+
+ statusBar = new FPSView(this);
+
relativeParams.addRule(RelativeLayout.ALIGN_BOTTOM, glView.getId());
view.addView(statusBar, relativeParams);
}
View
16 src/com/osesm/randy/lab/FPSView.java
@@ -0,0 +1,16 @@
+package com.osesm.randy.lab;
+
+import android.content.Context;
+import android.widget.TextView;
+
+public class FPSView extends TextView {
+
+ public FPSView(Context context) {
+ super(context);
+
+ setText("Status bar initialized...");
+ setTextColor(0xFFF06D2F);
+ setTextSize(25.0f);
+ }
+
+}
View
22 src/com/osesm/randy/lab/SimulationTest.java
@@ -29,7 +29,7 @@ public Scene getStartScene() {
public SimulationScene(Simulation simulation) {
super(simulation);
-
+
fpscounter = new FPSCounter(simulation);
}
@@ -45,15 +45,15 @@ public void present(float deltaTime) {
long time = SystemClock.uptimeMillis() % 4000L;
float angle = 0.090f * ((int) time);
- camera.rotate(0.375f);
-
+ // camera.rotate(angle);
+
for (Shape shape : shapes) {
shape.setAngle(shape.getId() % 2 == 0 ? angle : -angle);
shape.setProjectionMatrix(camera.getViewProjectionMatrix());
shape.update();
shape.draw();
}
-
+
fpscounter.logFrame();
}
@@ -77,8 +77,8 @@ public void dispose() {
@Override
public void changed(int width, int height) {
- GLES20.glViewport(0, 0, width, height);
- camera = new Camera(width, height);
+ GLES20.glViewport(0, 0, width, height);
+ camera = new Camera(width, height);
}
private void initShapes() {
@@ -86,15 +86,15 @@ private void initShapes() {
float triangle1Coords[] = { -0.5f, -0.25f, 0.5f, 0f, 0f, 0.5f, -0.25f, 0.5f, 1f, 0f, 0.0f, 0.559016994f, 0.5f, 0.5f, 1f };
float triangle2Coords[] = { -0.7f, -0.25f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.3f, -0.25f, 0.25f, 0.0f, 0.0f, 1.0f, 1.0f, -0.2f, 0.559016994f, 0.2f, 1.0f, 0.0f, 0.0f, 1.0f };
-
+
Texture texture = new Texture(simulation, R.raw.basic_texture);
shapes = new ArrayList<Shape>();
Mesh mesh;
-// mesh = ObjLoader.load(simulation, "sphere.obj");
-// shapes.add(new Shape(mesh));
-//
+ // mesh = ObjLoader.load(simulation, "sphere.obj");
+ // shapes.add(new Shape(mesh));
+ //
mesh = new Mesh(simulation, 15, 6, false, true, false);
mesh.setVertices(triangle1Coords, 0, triangle1Coords.length);
mesh.setIndices(triangleIndices, 0, triangleIndices.length);
@@ -109,7 +109,7 @@ private void initShapes() {
mesh = ObjLoader.load(simulation, "sphere.obj");
mesh.setTexture(texture);
shapes.add(new Shape(mesh));
-
+
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.