结合 Canvas 和 OpenGL ES 渲染器?

发布于 2024-12-20 23:04:02 字数 433 浏览 0 评论 0原文

我有一个应用程序,它使用带有扩展 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

来日方长 2024-12-27 23:04:02

您不能同时使用 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.

半世晨晓 2024-12-27 23:04:02

尝试以下操作:

addContentView(SurfaceView);
addContentView(GLSurfaceView);

或创建两个视图的相对布局。

Try the following:

addContentView(SurfaceView);
addContentView(GLSurfaceView);

or create a relative layout with both views.

酒浓于脸红 2024-12-27 23:04:02

这是我在 OpenGL 视图上添加画布时的示例代码,感谢@Audrius Butkevicius!

mGLView = new MyOpenGLSurfaceView;
// SET OpenGL View
setContentView(myOpenGLView);


mCanvasOverlayView = new View(context)
mOverlayViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
// ADD Canvas view overlay
addContentView(mCanvasOverlayView, mOverlayViewParams );

Here my sample code when adding canvas over the OpenGL view, thanks to @Audrius Butkevicius !

mGLView = new MyOpenGLSurfaceView;
// SET OpenGL View
setContentView(myOpenGLView);


mCanvasOverlayView = new View(context)
mOverlayViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
// ADD Canvas view overlay
addContentView(mCanvasOverlayView, mOverlayViewParams );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文