我正在关注本教程:http://developer.android.com/training/graphics/opengl/environment.html
并尝试让它在一整天内运行......与此同时,我正在研究其他一些关于OpenGL的教程,但最后我总是遇到应用程序崩溃... 这是我的所有文件: 的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.openglproject1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" />
<supports-gl-texture android:name="GL_OES_compressed_paletted_texture" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.openglproject1.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml中:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.openglproject1.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
MainActivity.java:
package com.example.openglproject1;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
public class MainActivity extends Activity {
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a GLSurfaceView instance and set it
// as the ContentView for this Activity.
mGLView = new MyGLSurfaceView(this);
setContentView(mGLView);
}
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context){
super(context);
// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
setRenderer(new MyGLRenderer());
// Render the view only when there is a change in the drawing data
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}
}
MyGLRenderer.java:
package com.example.openglproject1;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
import android.opengl.GLES20;
public class MyGLRenderer implements GLSurfaceView.Renderer {
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
@Override
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
}
根据developer.android.com,这应该工作并显示灰色屏幕。我能够编译应用程序并在模拟器上启动它但它会立即崩溃...有没有人在这些代码片段中看到任何问题?我已经厌倦了尝试一整天运行1个愚蠢的OpenGL应用程序...... 这是logcat:
06-27 13:58:16.901: D/(1075): HostConnection::get() New Host Connection established 0xb8946c38, tid 1075
06-27 13:58:16.971: W/EGL_emulation(1075): eglSurfaceAttrib not implemented
06-27 13:58:16.981: D/OpenGLRenderer(1075): Enabling debug mode 0
06-27 13:58:17.081: D/(1075): HostConnection::get() New Host Connection established 0xb894f3d0, tid 1088
06-27 13:58:17.141: W/dalvikvm(1075): threadid=11: thread exiting with uncaught exception (group=0xb2a97ba8)
06-27 13:58:17.151: E/AndroidRuntime(1075): FATAL EXCEPTION: GLThread 78
06-27 13:58:17.151: E/AndroidRuntime(1075): Process: com.example.openglproject1, PID: 1075
06-27 13:58:17.151: E/AndroidRuntime(1075): java.lang.IllegalArgumentException: No config chosen
06-27 13:58:17.151: E/AndroidRuntime(1075): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:874)
06-27 13:58:17.151: E/AndroidRuntime(1075): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
06-27 13:58:17.151: E/AndroidRuntime(1075): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
06-27 13:58:17.151: E/AndroidRuntime(1075): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
06-27 13:58:24.351: I/Process(1075): Sending signal. PID: 1075 SIG: 9
06-27 14:22:48.651: D/(1120): HostConnection::get() New Host Connection established 0xb894b288, tid 1120
06-27 14:22:48.691: W/EGL_emulation(1120): eglSurfaceAttrib not implemented
06-27 14:22:48.701: D/OpenGLRenderer(1120): Enabling debug mode 0
06-27 14:22:48.771: D/(1120): HostConnection::get() New Host Connection established 0xb894f420, tid 1133
06-27 14:22:48.821: W/dalvikvm(1120): threadid=11: thread exiting with uncaught exception (group=0xb2a97ba8)
06-27 14:22:48.841: E/AndroidRuntime(1120): FATAL EXCEPTION: GLThread 81
06-27 14:22:48.841: E/AndroidRuntime(1120): Process: com.example.openglproject1, PID: 1120
06-27 14:22:48.841: E/AndroidRuntime(1120): java.lang.IllegalArgumentException: No config chosen
06-27 14:22:48.841: E/AndroidRuntime(1120): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:874)
06-27 14:22:48.841: E/AndroidRuntime(1120): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
06-27 14:22:48.841: E/AndroidRuntime(1120): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
06-27 14:22:48.841: E/AndroidRuntime(1120): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
06-27 14:22:55.231: I/Process(1120): Sending signal. PID: 1120 SIG: 9
06-27 14:23:08.541: D/(1160): HostConnection::get() New Host Connection established 0xb894ba50, tid 1160
06-27 14:23:08.591: W/EGL_emulation(1160): eglSurfaceAttrib not implemented
06-27 14:23:08.601: D/OpenGLRenderer(1160): Enabling debug mode 0
06-27 14:23:08.661: D/(1160): HostConnection::get() New Host Connection established 0xb894f4f0, tid 1173
06-27 14:23:08.691: W/dalvikvm(1160): threadid=11: thread exiting with uncaught exception (group=0xb2a97ba8)
06-27 14:23:08.691: E/AndroidRuntime(1160): FATAL EXCEPTION: GLThread 84
06-27 14:23:08.691: E/AndroidRuntime(1160): Process: com.example.openglproject1, PID: 1160
06-27 14:23:08.691: E/AndroidRuntime(1160): java.lang.IllegalArgumentException: No config chosen
06-27 14:23:08.691: E/AndroidRuntime(1160): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:874)
06-27 14:23:08.691: E/AndroidRuntime(1160): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
06-27 14:23:08.691: E/AndroidRuntime(1160): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
06-27 14:23:08.691: E/AndroidRuntime(1160): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
06-27 14:23:10.811: I/Process(1160): Sending signal. PID: 1160 SIG: 9