好的,先简单介绍一下背景...我有一个完全运作良好的游戏,使用画布进行绘制,现在正在尝试学习并将绘图转换为OpenGL ES 1.0。(保持兼容性。)
我一直在尝试的是,找出一种方法将GLSurfaceView和Renderer合并到程序中,以便我可以逐步切换绘图。(有许多精灵需要经常更新,所以我不希望花费一个月来发布下一个更新。)
有人建议我在当前SurfaceView上使用GLSurfaceView,我正在努力实现,但遇到了一些问题。
我基本上是使用LunarLander示例,尝试添加一个简单的OpenGL渲染器,用于在方块上绘制纹理并呈现它。目标是在画布上方绘制方块。
以下是Activity中相关的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lunar_layout);
LinearLayout detailListView = (LinearLayout) findViewById(R.id.dets); // Find the layout where you want to add button
Button button = new Button(this);
button.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
detailListView.addView(button);//add view to add
mGLSV = new BasicGLSurfaceView(this);
mGLSV.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
detailListView.addView(mGLSV);
//clipped
文件的内容如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.lunarlander.LunarView
android:id="@+id/lunar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="@+id/dets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:layout_marginTop="50dp"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a14ecf8f2d9ef49"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
</LinearLayout>
<RelativeLayout
android:id="@+id/relLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:text="@string/lunar_layout_text_text"
android:textColor="#88ffffff"
android:textSize="24sp"
android:visibility="visible" />
</RelativeLayout>
</FrameLayout>
很简单,我想使用LinearLayout在Surface View上添加一些东西。请注意,我还添加了一个按钮,只是为了检查这个概念是否可行。 结果是画布和按钮正确显示,但没有GLSurfaceView的迹象。我做错了什么?