/****************************************************************************** ** Includes *****************************************************************************/ #include "GLES/egl.h" #include "GLES/gl.h" #include #include #include "oglx.h" #include #include #include #include #include "specific.h" /***********************************/ extern void init_scene_disk(); extern void render_scene_disk(); /*************************************/ /****************************************************************************** ** File variables *****************************************************************************/ gf_dev_t gfdev; gf_layer_t layer; int layer_idx; static EGLDisplay eglDisplay; static EGLSurface eglSurface; static EGLint attribute_list[]= { EGL_NATIVE_VISUAL_ID, 0, EGL_NATIVE_RENDERABLE, EGL_TRUE, EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 5, EGL_BLUE_SIZE, 5, EGL_DEPTH_SIZE, 16, EGL_STENCIL_SIZE, 8, EGL_NONE }; int main(int argc, char** argv) { gf_3d_target_t target; gf_display_t gf_disp; EGLConfig config; EGLContext econtext; EGLint num_config; gf_dev_info_t info; gf_layer_info_t linfo; gf_display_info_t disp_info; GLuint width, height; GLuint it; /* initialize the graphics device */ if (gf_dev_attach(&gfdev, NULL, &info)!=GF_ERR_OK) { perror("gf_dev_attach()"); return -1; } /* Setup the layer we will use */ if (gf_display_attach(&gf_disp, gfdev, 0, &disp_info)!=GF_ERR_OK) { fprintf(stderr, "gf_display_attach() failed\n"); return -1; } layer_idx=disp_info.main_layer_index; /* get an EGL display connection */ eglDisplay=eglGetDisplay(gfdev); if (eglDisplay==EGL_NO_DISPLAY) { fprintf(stderr, "eglGetDisplay() failed\n"); return -1; } width=disp_info.xres; height=disp_info.yres; if (gf_layer_attach(&layer, gf_disp, layer_idx, 0)!=GF_ERR_OK) { fprintf(stderr, "gf_layer_attach() failed\n"); return -1; } /* initialize the EGL display connection */ if (eglInitialize(eglDisplay, NULL, NULL)!=EGL_TRUE) { fprintf(stderr, "eglInitialize: error 0x%x\n", eglGetError()); return -1; } /* eglBindAPI(EGL_OPENGL_API); */ for (it=0;; it++) { /* Walk through all possible pixel formats for this layer */ if (gf_layer_query(layer, it, &linfo)!= GF_ERR_OK) { fprintf(stderr, "Couldn't find a compatible frame " "buffer configuration on layer %d\n", layer_idx); return -1; } /* * We want the color buffer format to match the layer format, * so request the layer format through EGL_NATIVE_VISUAL_ID. */ attribute_list[1]=linfo.format; /* Look for a compatible EGL frame buffer configuration */ /* Problem: num_config is always 0 */ if (eglChooseConfig(eglDisplay, attribute_list, &config, 1, &num_config)==EGL_TRUE) { if (num_config>0) { break; } } } /* create a 3D rendering target */ if (gf_3d_target_create(&target, layer, NULL, 0, width, height, linfo.format)!=GF_ERR_OK) { fprintf(stderr, "Unable to create rendering target\n"); return -1; } gf_layer_set_src_viewport(layer, 0, 0, width-1, height-1); gf_layer_set_dst_viewport(layer, 0, 0, width-1, height-1); gf_layer_enable(layer); /* * The layer settings haven't taken effect yet since we haven't * called gf_layer_update() yet. This is exactly what we want, * since we haven't supplied a valid surface to display yet. * Later, the OpenGL ES library calls will call gf_layer_update() * internally, when displaying the rendered 3D content. */ /* create an EGL rendering context */ econtext=eglCreateContext(eglDisplay, config, EGL_NO_CONTEXT, NULL); if (econtext==EGL_NO_CONTEXT) { fprintf(stderr, "Create context failed: 0x%x\n", eglGetError()); return -1; } /* create an EGL window surface */ eglSurface=eglCreateWindowSurface(eglDisplay, config, target, NULL); if (eglSurface==EGL_NO_SURFACE) { fprintf(stderr, "Create surface failed: 0x%x\n", eglGetError()); return -1; } /* connect the context to the surface */ if (eglMakeCurrent(eglDisplay, eglSurface, eglSurface, econtext)==EGL_FALSE) { fprintf(stderr, "Make current failed: 0x%x\n", eglGetError()); return -1; } return 0; }