在Android上进行实时图形编程的最佳语言是什么? [英] What's the best language for real-time graphics programming on Android?

查看:106
本文介绍了在Android上进行实时图形编程的最佳语言是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些谷歌搜索使我相信C ++是用于实时2D图形编程的最佳语言,但是由于Android是基于Java的,因此这仍然是最佳选择吗?还是我们事实上我必须使用NDK来减慢它的速度?我的程序还具有很多科学计算功能,我知道C ++是最好/最快的程序.

Some googling has led me to believe that C++ is the best language for real-time 2D graphics programming, but since the Android is Java-based, is that still the best option? Or us the fact that I have to use NDK going to slow it down or something? My program also has a lot of scientific computing and I know C++ is best/fastest for that...

我以前从未对Android做过任何事情,所以现在我真的很无助.如果我只是以错误的方式进行操作,请给我其他建议...我遇到的其他vocab是OpenGL(我有经验,但是更多用于3D,对吗?)和Canvas(不要)很明白这个)?如果我可以使用类似GPU的功能,那就太好了.

I've never done anything with the Android before so I'm really helpless right now. If I'm just going about it the wrong way, please give me other suggestions... Some other vocab I came across is OpenGL (which I have experience with, but that's more for 3D, right?) and Canvas (don't quite get this)? If I could get access to GPU-like capabilities that would be great.

推荐答案

Android应用程序是用Java编写的,是的-但是Android NDK允许您用C或C ++编写程序的性能关键部分.从Android NDK 网站

Android applications are written Java, yes - however the Android NDK allows you to write performance-critical sections of your program in C or C++. From the Android NDK website,

Android NDK是用于 可以让您构建的Android SDK 您的性能至关重要的部分 本机代码中的应用程序.它提供 标头和库,可让您 建立活动,处理用户 输入,使用硬件传感器,访问 应用程序资源等 用C或C ++进行编程.

The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++.

也就是说,适当地使用NDK很有可能不会降低程序速度.

That said, using the NDK appropriately will most likely not slow your program down.

OpenGL 适用于3D和2D图形-如果您仅对2D感兴趣,则希望使用正交投影-请参见画布 是Java方法用于将光栅图形绘制到屏幕上.它可以让您渲染2D图形,但速度较慢(并且Android Garbage Collector经常中断).

OpenGL works for 3D and 2D graphics - if you're only interested in 2D you will want to look at using an Orthographic Projection - see glOrtho for more information. The Android Canvas, on the other hand, is the Java method for drawing raster graphics to the screen. It will let you render 2D graphics, but at a slower rate (and with frequent interruptions from the Android Garbage Collector).

请记住,在撰写本文时,如果要使用C ++,则没有可用的STL实现.但是,有提供大多数功能的非官方端口. STLPort 是我尝试成功的一种.将代码移至C/C ++的最大原因是由于Android Java Garbage Collector的中断-如果您对代码的处理不够谨慎,它将频繁地中断程序以清理您留下的对象.实际上,这会极大地限制游戏或模拟帧速率.

Keep in mind that if you want to use C++, as of writing, there is no STL implementation available. There are, however unofficial ports that provide most of the functionality. STLPort is one that I have tried with some success. The biggest reason to move code to C/C++ is because of interruptions from the Android Java Garbage Collector - if you're not overly careful with your code, it will interrupt your program frequently to clean up objects you've left lying around. In practice this can limit game or simulation framerates drastically.

所有这些,我强烈建议您研究一下正在涌现的少数几个开源android游戏引擎之一.我尝试过的最好的方法是 libGDX .它处理了所有凌乱的NDK详细信息,并让您可以完全使用Java编写游戏/模拟代码.它以本机代码自动运行游戏引擎中性能较高的部分,从而以Java简化的编码获得最快的性能.最重要的是,您只需编写一次应用程序代码,即可使其在Windows,Linux,OSX和Android上自动运行-与使用Android模拟器相比,这使测试应用程序简单得多.

All that said, I would strongly recommend you look into one of the few open source android game engines that are cropping up. The best one I've tried is libGDX. It takes care of all the messy NDK details and lets you code your game / simulation purely in Java. It automatically runs the performance-heavy parts of the game engine in native code to get the fastest possible performance with the ease of coding in Java. Best of all, you can write your application code once and have it automatically run on Windows, Linux, OSX and Android - which makes testing your applications much, much easier than using the Android Emulator.

如果您真的想亲自研究NDK,或者需要对OpenGL所做的事情有很好的控制,我建议您下载Android SDK和NDK,进行eclipse设置,然后从NDK示例开始.那里有一个OpenGL演示,向您展示如何进行所有设置.另一个好的起点是 SpinningCube 谷歌项目.

If you really want to look into the NDK yourself, or need to have really fine control on what OpenGL is doing, I would recommend you download the Android SDK and NDK, get eclipse set up, and then start with the NDK samples. There is an OpenGL demo there that shows you how to get everything set up. Another good starting point would be the SpinningCube google project.

我不太确定您所说的类似于GPU的功能"是什么意思,但是使用libGDX,您可以在OpenGL ES 2.0下编译顶点和片段着色器-您可以使用它来使用设备的GPU.

I'm not really sure if what you mean by 'GPU-like capabilities', but With libGDX, you can compile vertex and fragment shaders under OpenGL ES 2.0 - you could use this to run embarrassingly parallel code using the device's GPU.

这篇关于在Android上进行实时图形编程的最佳语言是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆