【发布时间】:2011-12-14 02:28:16
【问题描述】:
我正在学习 Android 上的 OpenGL。我编写了一个应用程序,其中 GlSurfaceView 在布局 XML 中声明(片段...)
<FrameLayout
android:id="@+id/framelay"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.nelsondev.myha3ogl.M3View
android:id="@+id/m3SurfView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
...在其构造函数中设置渲染器:
public M3View(Context context, AttributeSet attrs) {
super(context, attrs);
renderer = new M3Renderer(context);
setRenderer(renderer);
}
当 Activity 收到 onResume/onPause 时,它会正确调用 GlSurfaceView 方法。 但渲染器永远不会启动! onSurfaceCreated() 中的断点和渲染器中的其他方法永远不会被命中,也不会渲染任何内容。我如何弄清楚这里发生了什么?
【问题讨论】:
-
实际上,我刚刚检查过,我认为我对您上一个问题的回答是错误的,实际上,在 GLSurfaceView 首次布局时(即当您调用 @987654323 时)调用 start() @ 或
setContentView(R.layout.graphics)与 GLSurfaceView 作为 framelay / 在文件 graphics.xml 中的子级)而不是在调用setRenderer时 -
你确定构造函数被调用了吗?
-
你能在 GLSurfaceView 上打电话给
requestRender()看看有没有画图吗? -
是的,正在调用渲染器构造函数。
-
您绝对确定您的渲染器正在工作并且应该给出输出?如果您从 onDrawFrame() 方法记录消息会发生什么?