使用android源代码下的API
来源:互联网 发布:励志句子 知乎 编辑:程序博客网 时间:2024/05/21 11:10
声明: 这个是 看到别人的代码,感觉不错,适合我这样的初学者,就加工了!
1,在android源代码的external目录下建立文件夹,如mkdir sno_opengl
2,在sno_opengl文件夹下,创建源代码,如tst_opengl.cpp和Android.mk其中Android.mk的代码如下:
LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES:= \ tst_opengl.cppLOCAL_SHARED_LIBRARIES := \ libutils\ libui \ libEGL \ libGLESv1_CM \libsurfaceflinger_client LOCAL_MODULE := sno_openglLOCAL_MODULE_TAGS:= optional include $(BUILD_EXECUTABLE)
tst_poengl.cpp的源代码是:
(转自:http://blog.csdn.net/xiexh0921/article/category/1134272)
//android opengl es画三角形-native C实现 //Native C开发opengl,网上这方面的资料很少,研究了几天才弄出来,现在贴出来供交流,转载请注明Hello Xiexh#include <stdio.h>#include <unistd.h>#include <EGL/egl.h>#include <GLES/gl.h>#include <ui/FramebufferNativeWindow.h>#include <ui/EGLUtils.h>#include <ui/DisplayInfo.h> #include <surfaceflinger/SurfaceComposerClient.h> using namespace android; int mWidth;int mHeight;EGLDisplay mDisplay;EGLDisplay mContext;EGLDisplay mSurface;sp<SurfaceControl>mFlingerSurfaceControl;sp<Surface> mFlingerSurface; int initGraphics(){ //create the native surface sp<SurfaceComposerClient>session = new SurfaceComposerClient(); DisplayInfo dinfo; status_t status = session->getDisplayInfo(0, &dinfo); if(status) return-1; sp<SurfaceControl> control = session->createSurface( getpid(), 0, 400, 300, PIXEL_FORMAT_RGB_565); session->openTransaction(); control->setLayer(0x40000000); session->closeTransaction(); sp<Surface> s = control->getSurface(); //initialize opengl and egl const EGLint attribs[] = { EGL_DEPTH_SIZE,0, EGL_NONE }; EGLint w, h, dummy; // EGLintnum Configs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display,0, 0); EGLUtils::selectConfigForNativeWindow(display,attribs, s.get(), &config); surface= eglCreateWindowSurface(display, config, s.get(), NULL); context= eglCreateContext(display, config, NULL, NULL); eglQuerySurface(display,surface, EGL_WIDTH, &w); eglQuerySurface(display,surface, EGL_HEIGHT, &h); if(eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) return NO_INIT; mDisplay = display; mContext = context; mSurface = surface; mWidth = w; mHeight = h; mFlingerSurfaceControl= control; mFlingerSurface= s; glViewport(0,0, mWidth, mHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0,mWidth, 0, mHeight, 0, 1); return EGL_TRUE;} void draw() { //printf("startdrawing...\n"); glColor4f(1,0,0,1); const GLfloat vertices[3][2] = { {100, 100}, {200, 100}, {100,200} }; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertices); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); eglSwapBuffers(mDisplay, mSurface); } int main(int argc, char** argv) { if(!initGraphics()) { printf("Graphicsinitialization failed.\n"); return EXIT_FAILURE; } while(1){ draw(); usleep(100*1000); } //clearstatus eglMakeCurrent(mDisplay,EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(mDisplay,mContext); eglDestroySurface(mDisplay,mSurface); mFlingerSurface.clear(); mFlingerSurfaceControl.clear(); eglTerminate(mDisplay); return 0;}
3,在源代码目录下执行 make sno_opengl
4,可以./adb push 进虚拟机,然后./sno_opengl可以出来。
- 使用android源代码下的API
- 使用crypto api的加密解密源代码
- android studio下使用android的日志api
- Android 剪贴板操作方法在不同版本API下的使用
- Android 剪贴板操作方法在不同版本API下的使用
- Java、android源代码的使用。
- 在WinCE下调用校准触摸屏的API和源代码
- 在WinCE下调用校准触摸屏的API和源代码
- 在WinCE下调用校准触摸屏的API和源代码
- Windows下下载Android源代码的方法
- Windows下下载Android源代码的方法
- Windows下下载Android源代码的方法
- Windows下下载Android源代码的方法
- Windows下下载Android源代码的方法
- 浅谈:Android下的external源代码目录
- Windows下下载Android源代码的方法
- Eclipse 下管理Android的源代码
- ubuntu下下载Android源代码的方法
- VC中使用ListCtrl经验总结(1)
- 关于显示器接口的部分介绍
- 12个最好的开源报表工具
- Qt 中关于undefined reference to `vtable for故障总结
- Qt学习之路(21): event()
- 使用android源代码下的API
- 欧几里得+扩展的欧几里得算法+线性同余方程+中国剩余定理
- Qt学习之路(22): 事件过滤器
- Failed to create Java Virtual Machine
- 2012-7-17 固定屏幕显示模式Android: ScreenOrientation,全屏
- include与jsp:include区别
- 两个窗体之间数值的传送!
- vim 常用命令
- 自定义文件关联