2

私はこのレッスンをやろうとしています
http://developer.android.com/training/graphics/opengl/environment.html
アプリを起動するたびにクラッシュし、Eclipseは何が悪いのか教えてくれません。
これが私のコードです

package com.example.opengl;

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

import android.opengl.GLES20;

public class MyGL20Renderer implements MyGLSurfaceView.Renderer {
    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // Set the background frame color
        GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        // Redraw Background Color
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        GLES20.glViewport(0, 0, width, height);

    }



}

次の授業

package com.example.opengl;

import android.content.Context;
import android.opengl.GLSurfaceView;

public class MyGLSurfaceView extends GLSurfaceView {

    public MyGLSurfaceView(Context context) {
        super(context);
        // Set the Renderer for drawing on the GLSurfaceVIew
        setRenderer(new MyGL20Renderer());
        // Create an OpenGL ES 2.0 context
        setEGLContextClientVersion(2);
        // Render the view only when there is a change in the drawing data
        setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    }

}

最後にmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.opengl"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
<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.example.opengl.MyGLSurfaceView" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

この問題を解決するためにググってみましたが、ググるカンフーが弱すぎます。

4

1 に答える 1

2

主な活動は?これを忘れましたか?

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);

    }
}

私もこの例にこだわっていますが、私のプログラムはその後問題なく起動しますが、次のように宣言されているものではなく、黒い画面しか表示されません。

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

編集:私のエラーが見つかりました。別の onSurfaceChanged メソッドを作成した MyGL20Renderer に間違ったインポートがありました。

于 2013-03-25T10:51:31.460 に答える