关闭

Android Dev Intro - Opengl ES and EGL

236人阅读 评论(0) 收藏 举报
分类:




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;

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:801713次
    • 积分:12928
    • 等级:
    • 排名:第1027名
    • 原创:414篇
    • 转载:665篇
    • 译文:0篇
    • 评论:44条
    最新评论