Android Dev Intro - Opengl ES and EGL

本文详细介绍了OpenGL ES和EGL的基本概念及使用步骤。OpenGL ES定义了跨平台的图形绘制指令,而EGL则定义了显示、上下文和表面等核心组件。文章通过实例演示了如何初始化显示设备、配置、创建上下文和表面,以及如何进行图形绘制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




Opengl ES define platform independent GL draw graphics instructions
EGL define display, context and surface.
Display (EGLDisplay) is the abstract of display device
Surface (EGLSurface) is the abstract of memory area used to store graphics
Context (EGLContext) is used to save state information of Opengl ES


General Steps.
1. acquire EGLDisplay object
   EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
   
2. init EGLDisplay object
   eglInitialize(display, 0, 0);
   
3. acquire EGLConfig object
   eglChooseConfig(display, attribs, nullptr,0, &numConfigs);
   auto supportedConfigs = new EGLConfig[numConfigs];
   assert(supportedConfigs);
   eglChooseConfig(display, attribs, supportedConfigs, numConfigs, &numConfigs);
   
   auto i = 0;
   for (; i < numConfigs; i++) {
       auto& cfg = supportedConfigs[i];
       EGLint r, g, b, d;
       if (eglGetConfigAttrib(display, cfg, EGL_RED_SIZE, &r)   &&
           eglGetConfigAttrib(display, cfg, EGL_GREEN_SIZE, &g) &&
           eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b)  &&
           eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d) &&
           r == 8 && g == 8 && b == 8 && d == 0 ) {
           config = supportedConfigs[i];
           break;
       }
   }
   if (i == numConfigs) {
       config = supportedConfigs[0];
   }
   
   eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
   
4. Create EGLContext object
   context = eglCreateContext(display, config, NULL, NULL);
   
5. Create EGLSurface object
   surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);


6. bind EGLSurface with EGLContext
   eglMakeCurrent(display, surface, surface, context);


7. draw graphics
    glClearColor(((float)engine->state.x)/engine->width, engine->state.angle,
                 ((float)engine->state.y)/engine->height, 1);
    glClear(GL_COLOR_BUFFER_BIT);


    eglSwapBuffers(engine->display, engine->surface);

8. unbind EGLSurface with EGLContext
   eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
   
9. releas EGLContext object
   eglDestroyContext(engine->display, engine->context);
   
10. release EGLSurface object
   eglDestroySurface(engine->display, engine->surface);
   
11. Destory EGLDisplay object
   eglTerminate(engine->display);
   engine->display = EGL_NO_DISPLAY;
   engine->context = EGL_NO_CONTEXT;
   engine->surface = EGL_NO_SURFACE;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值