Merge change I8018f091 into eclair

* changes:
  Add very simple input path. Fix end-of-line issues.
This commit is contained in:
Android (Google) Code Review
2009-09-30 09:15:16 -04:00
4 changed files with 75 additions and 63 deletions

View File

@@ -3,13 +3,16 @@
#include <nativehelper/jni.h> #include <nativehelper/jni.h>
#define LOG_TAG "GLJNI gl_code.cpp" #define LOG_TAG "GLJNI gl_code.cpp"
#include <utils/Log.h> #include <utils/Log.h>
#include <GLES/gl.h> #include <GLES/gl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
GLuint texture; GLuint texture;
GLfloat background;
#define FIXED_ONE 0x10000 #define FIXED_ONE 0x10000
@@ -83,10 +86,10 @@ void init_scene(int width, int height)
printGLString("Vendor", GL_VENDOR); printGLString("Vendor", GL_VENDOR);
printGLString("Renderer", GL_RENDERER); printGLString("Renderer", GL_RENDERER);
printGLString("Extensions", GL_EXTENSIONS); printGLString("Extensions", GL_EXTENSIONS);
glDisable(GL_DITHER); glDisable(GL_DITHER);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
float ratio = width / height; float ratio = width / height;
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
@@ -94,8 +97,8 @@ void init_scene(int width, int height)
glLoadIdentity(); glLoadIdentity();
glFrustumf(-ratio, ratio, -1, 1, 1, 10); glFrustumf(-ratio, ratio, -1, 1, 1, 10);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gluLookAt( gluLookAt(
0, 0, 3, // eye 0, 0, 3, // eye
@@ -122,6 +125,7 @@ void create_texture()
on, off, on, off, on, off, on, off, on, off, on, off, on, off, on, off,
off, on, off, on, off, on, off, on, off, on, off, on, off, on, off, on,
}; };
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
@@ -133,9 +137,9 @@ void create_texture()
extern "C" { extern "C" {
JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height); JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height);
JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_changeBackground(JNIEnv * env, jobject obj);
}; };
JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height) JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_init(JNIEnv * env, jobject obj, jint width, jint height)
{ {
init_scene(width, height); init_scene(width, height);
@@ -159,19 +163,21 @@ JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_step(JNIEnv * env, jobjec
}; };
const GLushort quadIndices[] = { 0, 1, 2, 0, 2, 3 }; const GLushort quadIndices[] = { 0, 1, 2, 0, 2, 3 };
glVertexPointer(3, GL_FLOAT, 0, vertices); glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FIXED, 0, texCoords); glTexCoordPointer(2, GL_FIXED, 0, texCoords);
int nelem = sizeof(quadIndices)/sizeof(quadIndices[0]); int nelem = sizeof(quadIndices)/sizeof(quadIndices[0]);
static float grey; static float grey;
grey += 0.01f; grey += 0.01f;
if (grey > 1.0f) { if (grey > 1.0f) {
grey = 0.0f; grey = 0.0f;
} }
glClearColor(grey, grey, grey, 1.0f); glClearColor(background, grey, grey, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, quadIndices); glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, quadIndices);
} }
JNIEXPORT void JNICALL Java_com_android_gljni_GLJNILib_changeBackground(JNIEnv * env, jobject obj)
{
background = 1.0f - background;
}

View File

@@ -18,28 +18,27 @@ package com.android.gljni;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import java.io.File;
public class GLJNIActivity extends Activity { public class GLJNIActivity extends Activity {
GLJNIView mView; GLJNIView mView;
@Override protected void onCreate(Bundle icicle) { @Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
mView = new GLJNIView(getApplication()); mView = new GLJNIView(getApplication());
setContentView(mView); mView.setFocusableInTouchMode(true);
setContentView(mView);
} }
@Override protected void onPause() { @Override
protected void onPause() {
super.onPause(); super.onPause();
mView.onPause(); mView.onPause();
} }
@Override protected void onResume() { @Override
protected void onResume() {
super.onResume(); super.onResume();
mView.onResume(); mView.onResume();
} }

View File

@@ -30,4 +30,5 @@ public class GLJNILib {
*/ */
public static native void init(int width, int height); public static native void init(int width, int height);
public static native void step(); public static native void step();
public static native void changeBackground();
} }

View File

@@ -80,5 +80,11 @@ class GLJNIView extends GLSurfaceView {
// Do nothing. // Do nothing.
} }
} }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
GLJNILib.changeBackground();
return true;
}
} }