【问题标题】:GlSurfaceView Renderer not being called未调用 GlSurfaceView 渲染器
【发布时间】: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() 方法记录消息会发生什么?

标签: android opengl-es


【解决方案1】:

(这个答案来自你的另一个问题:Trying to start renderer from GLSurfaceView declared in layout

您没有指定 LinearLayout 方向,因此默认设置为 horizontal。这意味着您的 GLSurfaceView 位于屏幕之外(因为您将按钮宽度设置为 fill_parent)。

只需将以下属性添加到您的 LinearLayout :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-08
    • 2020-09-02
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    相关资源
    最近更新 更多