GlSurfaceView Renderer not being called

こ雲淡風輕ζ 提交于 2019-12-13 05:48:45

问题


I'm learning OpenGL on Android. I've written an app where the GlSurfaceView is declared in the layout XML (fragment...)

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

... and in its constructor the renderer is being set:

    public M3View(Context context, AttributeSet attrs) {
        super(context, attrs);
        renderer = new M3Renderer(context);
        setRenderer(renderer);
   }

When the activity receives onResume/onPause it is properly calling the GlSurfaceView methods. But the renderer is never being started! Breakpoints in onSurfaceCreated() and other methods in the renderer are never being hit and nothing is rendered. How do I figure out what's happening here?


回答1:


(This answer comes from your other question : Trying to start renderer from GLSurfaceView declared in layout)

You didn't specify your LinearLayout orientation, so it is set to horizontal by default. This means your GLSurfaceView is outside of the screen (because you set your button width to fill_parent).

Just add the following attribute to your LinearLayout :

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


来源:https://stackoverflow.com/questions/8498877/glsurfaceview-renderer-not-being-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!