HarmonyOS 鸿蒙Next 开发 Opengl ES native 应用
HarmonyOS 鸿蒙Next 开发 Opengl ES native 应用
本人鸿蒙新手,在开发native项目中,想使用Opengl ES 实现绘图功能,遇到了点问题,希望各位技术大佬帮忙看下!!
开发环境 deveco 3.1 API6
整体思路:
- native层实现这4个方法
public static native void Init();
public static native void SurfaceChanged(int width, int height);
public static native void DrawFrame();
public static native void Destroy();
- Java层用 SurfaceOps.Callback 调用 native方法
public class Triangle {
private SCallBacks callBacks;
private final Context mContext;
private SurfaceOps surfaceOps;
public Triangle(Context context) {
this.mContext = context;
}
public SurfaceProvider initSliceLayout() {
SurfaceProvider testSurfaceView = new SurfaceProvider(mContext);
if(testSurfaceView.getSurfaceOps().isPresent()){
surfaceOps = testSurfaceView.getSurfaceOps().get();
callBacks = new SCallbacks();
surfaceOps.addCallback(callBacks);
surfaceOps.setKeepScreenOn(true);
}
testSurfaceView.setWidth(1080);
testSurfaceView.setHeight(2000);
testSurfaceView.pinToZTop(true);
return testSurfaceView;
}
public void onDraw(){
}
private static class SCallbacks implements SurfaceOps.Callback {
static {
System.loadLibrary("entry");
}
@Override
public void surfaceCreated(SurfaceOps ops) {
nativeInit();
YimaHiLog.log("create");
}
@Override
public void surfaceChanged(SurfaceOps ops, int format, int width, int height) {
nativeSurfaceChanged(width, height);
YimaHiLog.log("change");
nativeDrawFrame();
YimaHiLog.log("draw");
}
@Override
public void surfaceDestroyed(SurfaceOps ops) {
nativeDestroy();
}
private static native void nativeInit();
private static native void nativeSurfaceChanged(int width, int height);
private static native void nativeDrawFrame();
private static native void nativeDestroy();
}
}
- 在 MainAbilitySlice onStart 添加
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(myLayout);
Triangle triangle = new Triangle(this);
SurfaceProvider provider = triangle.initSliceLayout();
myLayout.addComponent(provider);
}
为啥画不出来呢????
如果各位大佬有类似的demo或文档也可以发给我。
本段代码在安卓端正常画出一条线,在鸿蒙这边不显示。。
更多关于HarmonyOS 鸿蒙Next 开发 Opengl ES native 应用的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3.1,现在最低都是api9了,而且现在都是c++,arkts开发,,api6很多都不看
更多关于HarmonyOS 鸿蒙Next 开发 Opengl ES native 应用的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
姓名: 张三
职业: 软件工程师
简介: 拥有超过10年的软件开发经验,熟悉多种编程语言和技术。
使用的哪个版本的deveco,api几
api6
- **名称**: API 6
- **版本**: 1.2.3
- **描述**: 这是一个用于演示的API示例。
HarmonyOS鸿蒙Next开发OpenGL ES Native应用主要涉及使用ArkUI和NDK进行开发。ArkUI是鸿蒙系统的UI框架,支持声明式编程,开发者可以通过ArkTS或JS进行界面开发。NDK(Native Development Kit)则用于编写C/C++代码,与OpenGL ES结合实现高性能图形渲染。
在鸿蒙Next中,OpenGL ES用于处理2D和3D图形渲染。开发者可以通过NDK编写C/C++代码,调用OpenGL ES API进行图形渲染。鸿蒙系统提供了相应的NDK工具链和API,开发者可以在DevEco Studio中进行配置和开发。
开发流程大致如下:
- 配置NDK环境,确保DevEco Studio中已安装NDK和CMake。
- 创建Native C++项目,编写OpenGL ES渲染代码。
- 在ArkUI中创建界面,通过Native API调用C++代码进行渲染。
- 编译和调试应用,确保图形渲染效果符合预期。
鸿蒙系统对OpenGL ES的支持较为完善,开发者可以利用其进行高性能图形应用开发。