1

我希望你能告诉我这里有什么问题:

我从 Android SDK 上的 OpenGLES 开始,我已经完成了第一课并下载了示例代码,但是当我尝试在模拟器或我的 Galaxy Ace 中运行它时,它甚至没有启动,它说应用程序意外停止。我不知道为什么,到目前为止,这是我非常小的代码:

package com.jdpantojavalle.gles20_framework;

import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

public class GLES20_Framework extends Activity {

private GLSurfaceView mGLView;

/**
 * CODE FOR LAUNCHING A SIMPLE OPENGLES 2.0 APP
 */

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // Create a GLSurfaceView instance and set it as the content view for this activity
    mGLView = new mGLSurfaceView(this);
    setContentView(mGLView);
}

/*
 * ORIGINAL SOURCE CODE FOR USING A SIMPLE LAYOUT
 * 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gles20__framework);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_gles20__framework, menu);
    return true;
}
*/

}

class mGLSurfaceView extends GLSurfaceView {

public mGLSurfaceView(Context context)
{
    super(context);

    // Set the renderer for drawing on the GLSurfaceView
    setRenderer(new mGLRenderer());

    // Create an OpenGLES 2.0 context
    setEGLContextClientVersion(2);

    // Render the view only when there is a change in the drawing data
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}

package com.jdpantojavalle.gles20_framework;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;

public class mGLRenderer implements GLSurfaceView.Renderer {

@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config)
{
    // Set the background frame color
    GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
}

@Override
public void onDrawFrame(GL10 unused)
{
    // Redraw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}

@Override
public void onSurfaceChanged(GL10 unused, int width, int height)
{
    // Reset the GL viewport
    GLES20.glViewport(0, 0, width, height);
}

}

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jdpantojavalle.gles20_framework"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />

<uses-feature
    android:glEsVersion="0x00020000" android:required="true"
/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.jdpantojavalle.gles20_framework.GLES20_Framework"
        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>

我不知道应用程序停止的原因是什么。我认为这可能是因为我的设备上有 ChainFire3D 但在模拟器中?谢谢你的时间,我希望你能帮助我:)

4

0 回答 0