结合 Canvas 和 OpenGL ES 渲染器?
我有一个应用程序,它使用带有扩展 SurfaceView 的类来绘制到画布上,但我正在考虑转向 openGL。我注意到,如果我只是将 SurfaceView 扩展更改为 GLSurfaceView,应用程序仍然运行相同。我还能够使用 openGL ES 在另一个应用程序中开始基本绘图。
我采取了下一步并在 GLSurfaceView 中实例化了渲染器的另一个类,并指示渲染器绘制一个三角形。这一切都编译并运行良好,但它的运行方式与原始应用程序完全相同,没有渲染三角形,但画布的其余部分正确绘制。
我想不出为什么它没有渲染,或者为什么它不会渲染。或者也许它正在渲染,但它只是被画布覆盖?
我知道尝试使用这两种方法似乎很奇怪,因为我的应用程序已经上线,我宁愿按照自己的节奏将渲染切换到 GL,这样我就不需要一个月的时间来获得下一次更新。
那么有人尝试过这样做吗?在画布上运行 Gl 渲染器?
I have an app that uses a Class with an extension SurfaceView to draw to a canvas, but i'm looking at moving over to openGL. I noticed that if I merely change the SurfaceView extension to a GLSurfaceView, the app still runs the same. I've also been able to start basic drawing in another app using openGL ES.
I took it the next step and instantiated another class for the renderer in GLSurfaceView, and I instruct the render to draw a triangle. This all compiles and runs fine, but it runs exactly like the original App, with no triangle rendered, but the rest of the canvas draws properly.
I can't think of why it's not rendering, or why it wouldn't render. Or maybe it is rendering, but it's simply being overridden by the canvas?
I know it seems odd to try to use both methods, Since my app is live, I would rather implement switching the rendering over to GL at my own pace so that it doesn't take me a month to get the next update out.
So Anybody ever tried do do this? Run a Gl renderer OVER a canvas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能同时使用 OpenGL 和 Canvas 在单个 SurfaceView 上进行渲染。但是,您可以在 SurfaceView 之上放置另一个 View 以达到所需的效果。
You cannot use both OpenGL and a Canvas to render on a single SurfaceView. You can however put another View on top of the SurfaceView to achieve the desired effect.
尝试以下操作:
或创建两个视图的相对布局。
Try the following:
or create a relative layout with both views.
这是我在 OpenGL 视图上添加画布时的示例代码,感谢@Audrius Butkevicius!
Here my sample code when adding canvas over the OpenGL view, thanks to @Audrius Butkevicius !