/*********************************************************** * Name: init_ogl * * Arguments: * APP_STATE_T *state - holds OGLES model info * * Description: Sets the display, OpenGL|ES context and screen stuff * * Returns: void * ***********************************************************/ static void init_ogl (APP_STATE_T * state) { int32_t success = 0; EGLBoolean result; EGLint num_config; EGLNativeWindowType window_handle = (EGLNativeWindowType) 0; #if defined (USE_OMX_TARGET_RPI) static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, 255, 0 }; #endif static const EGLint attribute_list[] = { EGL_DEPTH_SIZE, 16, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; static const EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLConfig config; /* get an EGL display connection */ state->display = eglGetDisplay (EGL_DEFAULT_DISPLAY); assert (state->display != EGL_NO_DISPLAY); /* initialize the EGL display connection */ result = eglInitialize (state->display, NULL, NULL); assert (EGL_FALSE != result); #if defined (USE_OMX_TARGET_RPI) /* get an appropriate EGL frame buffer configuration * this uses a BRCM extension that gets the closest match, rather * than standard which returns anything that matches. */ result = eglSaneChooseConfigBRCM (state->display, attribute_list, &config, 1, &num_config); assert (EGL_FALSE != result); #else result = eglChooseConfig (state->display, attribute_list, &config, 1, &num_config); #endif /* create an EGL rendering context */ state->context = eglCreateContext (state->display, config, EGL_NO_CONTEXT, context_attributes); assert (state->context != EGL_NO_CONTEXT); #if defined (USE_OMX_TARGET_RPI) /* create an EGL window surface */ success = graphics_get_display_size (0 /* LCD */ , &state->screen_width, &state->screen_height); assert (success >= 0); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = state->screen_width; dst_rect.height = state->screen_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = state->screen_width << 16; src_rect.height = state->screen_height << 16; state->dispman_display = vc_dispmanx_display_open (0 /* LCD */ ); dispman_update = vc_dispmanx_update_start (0); state->dispman_element = vc_dispmanx_element_add (dispman_update, state->dispman_display, 0 /*layer */ , &dst_rect, 0 /*src */ , &src_rect, DISPMANX_PROTECTION_NONE, &alpha, 0 /*clamp */ , 0 /*transform */ ); nativewindow.element = state->dispman_element; nativewindow.width = state->screen_width; nativewindow.height = state->screen_height; vc_dispmanx_update_submit_sync (dispman_update); window_handle = &nativewindow; #endif state->surface = eglCreateWindowSurface (state->display, config, window_handle, NULL); assert (state->surface != EGL_NO_SURFACE); /* connect the context to the surface */ result = eglMakeCurrent (state->display, state->surface, state->surface, state->context); assert (EGL_FALSE != result); }
/*********************************************************** * Name: init_ogl * * Arguments: * APP_STATE_T *state - holds OGLES model info * * Description: Sets the display, OpenGL|ES context and screen stuff * * Returns: void * ***********************************************************/ static void init_ogl (APP_STATE_T * state) { int32_t success = 0; EGLBoolean result; EGLint num_config; static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 16, //EGL_SAMPLES, 4, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config; /* get an EGL display connection */ state->display = eglGetDisplay (EGL_DEFAULT_DISPLAY); assert (state->display != EGL_NO_DISPLAY); /* initialize the EGL display connection */ result = eglInitialize (state->display, NULL, NULL); assert (EGL_FALSE != result); /* get an appropriate EGL frame buffer configuration * this uses a BRCM extension that gets the closest match, rather * than standard which returns anything that matches. */ result = eglSaneChooseConfigBRCM (state->display, attribute_list, &config, 1, &num_config); assert (EGL_FALSE != result); /* create an EGL rendering context */ state->context = eglCreateContext (state->display, config, EGL_NO_CONTEXT, NULL); assert (state->context != EGL_NO_CONTEXT); /* create an EGL window surface */ success = graphics_get_display_size (0 /* LCD */ , &state->screen_width, &state->screen_height); assert (success >= 0); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = state->screen_width; dst_rect.height = state->screen_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = state->screen_width << 16; src_rect.height = state->screen_height << 16; state->dispman_display = vc_dispmanx_display_open (0 /* LCD */ ); dispman_update = vc_dispmanx_update_start (0); state->dispman_element = vc_dispmanx_element_add (dispman_update, state->dispman_display, 0 /*layer */ , &dst_rect, 0 /*src */ , &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha */ , 0 /*clamp */ , 0 /*transform */ ); nativewindow.element = state->dispman_element; nativewindow.width = state->screen_width; nativewindow.height = state->screen_height; vc_dispmanx_update_submit_sync (dispman_update); state->surface = eglCreateWindowSurface (state->display, config, &nativewindow, NULL); assert (state->surface != EGL_NO_SURFACE); /* connect the context to the surface */ result = eglMakeCurrent (state->display, state->surface, state->surface, state->context); assert (EGL_FALSE != result); /* Set background color and clear buffers */ glClearColor (0.15f, 0.25f, 0.35f, 1.0f); /* Enable back face culling. */ glEnable (GL_CULL_FACE); glMatrixMode (GL_MODELVIEW); }
/*********************************************************** * Name: init_ogl * * Arguments: * CUBE_STATE_T *state - holds OGLES model info * * Description: Sets the display, OpenGL|ES context and screen stuff * * Returns: void * ***********************************************************/ static void init_ogl(CUBE_STATE_T *state) { int32_t success = 0; EGLBoolean result; EGLint num_config; static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 16, EGL_SAMPLES, 4, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config; // get an EGL display connection state->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); assert(state->display!=EGL_NO_DISPLAY); // initialize the EGL display connection result = eglInitialize(state->display, NULL, NULL); assert(EGL_FALSE != result); // get an appropriate EGL frame buffer configuration // this uses a BRCM extension that gets the closest match, rather than standard which returns anything that matches result = eglSaneChooseConfigBRCM(state->display, attribute_list, &config, 1, &num_config); assert(EGL_FALSE != result); // create an EGL rendering context state->context = eglCreateContext(state->display, config, EGL_NO_CONTEXT, NULL); assert(state->context!=EGL_NO_CONTEXT); // create an EGL window surface success = graphics_get_display_size(0 /* LCD */, &state->screen_width, &state->screen_height); assert( success >= 0 ); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = state->screen_width; dst_rect.height = state->screen_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = state->screen_width << 16; src_rect.height = state->screen_height << 16; dispman_display = vc_dispmanx_display_open( 0 /* LCD */); dispman_update = vc_dispmanx_update_start( 0 ); dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/); nativewindow.element = dispman_element; nativewindow.width = state->screen_width; nativewindow.height = state->screen_height; vc_dispmanx_update_submit_sync( dispman_update ); state->surface = eglCreateWindowSurface( state->display, config, &nativewindow, NULL ); assert(state->surface != EGL_NO_SURFACE); // connect the context to the surface result = eglMakeCurrent(state->display, state->surface, state->surface, state->context); assert(EGL_FALSE != result); // Set background color and clear buffers glClearColor((0.3922f+7*0.5f)/8, (0.1176f+7*0.5f)/8, (0.5882f+7*0.5f)/8, 1.0f); // Enable back face culling. glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glClearDepthf(1.0); glDepthFunc(GL_LEQUAL); float noAmbient[] = {1.0f, 1.0f, 1.0f, 1.0f}; glLightfv(GL_LIGHT0, GL_AMBIENT, noAmbient); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); }