gpt4 book ai didi

android - 在 Android OpenGL 类(class)上工作无法弄清楚我做错了什么

转载 作者:行者123 更新时间:2023-11-29 00:31:57 25 4
gpt4 key购买 nike

我正在努力完成这节课
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>

我一直在尝试google解决这个问题,但是我的google功夫太弱了。

最佳答案

您的主要 Activity 是什么?你忘记了吗?

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 中导入错误。

关于android - 在 Android OpenGL 类(class)上工作无法弄清楚我做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14993350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com