Need to use opengl in combination with View

♀尐吖头ヾ 提交于 2019-12-14 03:43:21

问题


I am new in android. I need to use opengl in combination with View Class to draw something. How to do this. plz give me any hints or suggestions...


回答1:


You also have the option to combine "normal" android views (Button, ImageView, etc) in a layout with a GlSurfaceView. (i.e. FrameLayout)

By doing so you can combine normal android UI with openGL, you can also make a composite view where the openGL view is just part of the layout.

This is the way ads are usually displayed overlaying 3D aplications.

Be aware that this technique can produce quite weird results in low end devices when dealing with tranasparency.




回答2:


You probably wanta GlSurfaceView. It's a View that allows you to use Opengl to draw to it.

Put it in a layout file for your app

<GLSurfaceView id="@+id/myView" android:layout_width="fill_parent" android:layout_height="fill_parent"/>

Then in your code

((GLSurfaceView)findViewById(R.id.myView)).setRenderer(new GlSurfaceView.Renderer() {
    public void onSurfaceCreated(...)...
    public void onSurfaceChanged(...)...
    public void onDraw(GL10 gl)...
});
((GLSurfaceView)findViewById(R.id.myView)).setRenderMode(RENDERMODE_CONTINUOUSLY);

And then you draw in your onDraw with your gl calls.

This is the super-quick start answer to your question, if you drop the surfaceview in framelayout and know what your drawing it's pretty quick to get a basic setup running.



来源:https://stackoverflow.com/questions/6449824/need-to-use-opengl-in-combination-with-view

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