Created
November 24, 2012 21:33
-
-
Save jvcleave/4141486 to your computer and use it in GitHub Desktop.
setupRPiNativeWindow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------ | |
bool ofAppEGLWindow::setupRPiNativeWindow(int w, int h, int screenMode){ | |
#ifdef TARGET_RASPBERRY_PI | |
bcm_host_init(); | |
//boolean force HDMI vs. composite | |
int32_t success = 0; | |
uint32_t sw; | |
uint32_t sh; | |
// create an EGL window surface | |
// IF SCREENMODE==FULLSCREEN | |
success = graphics_get_display_size(0 /* LCD */, &sw, &sh); | |
if(!success) return false; | |
cout << " REQUESTED SCREEN SIZE w=" << w << " and h=" << h << endl; | |
cout << "HARDWARE SCREEN SIZE IS sw=" << sw << " and sh=" << sh << endl; | |
////////////////////////// | |
VC_RECT_T dst_rect; | |
VC_RECT_T src_rect; | |
dst_rect.x = 0; | |
dst_rect.y = 0; | |
dst_rect.width = sw; | |
dst_rect.height = sh; | |
src_rect.x = 0; | |
src_rect.y = 0; | |
src_rect.width = sw << 16; | |
src_rect.height = sh << 16; | |
DISPMANX_ELEMENT_HANDLE_T dispman_element; | |
DISPMANX_DISPLAY_HANDLE_T dispman_display; | |
DISPMANX_UPDATE_HANDLE_T dispman_update; | |
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*/, | |
(DISPMANX_TRANSFORM_T)0/*transform*/ | |
); | |
EGL_DISPMANX_WINDOW_T nativeWindow; | |
nativeWindow.element = dispman_element; | |
nativeWindow.width = sw; | |
nativeWindow.height = sh; | |
vc_dispmanx_update_submit_sync( dispman_update ); | |
EGLBoolean result; | |
EGLint num_config; | |
EGLConfig config; | |
ofLogNotice() << "setting EGL Display"; | |
Display *display = NULL; | |
// get an EGL eglDisplay connection | |
if(display==NULL){ | |
ofLogNotice() << "setting default Display"; | |
eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); | |
}else{ | |
ofLogNotice() << "setting argument Display"; | |
eglDisplay = eglGetDisplay((NativeDisplayType)display); | |
} | |
if(eglDisplay == EGL_NO_DISPLAY) { | |
ofLogError("ofAppEGLWindow::setupEGL") << "eglGetDisplay returned: " << eglDisplay; | |
return false; | |
}else{ | |
ofLogNotice() << "EGL Display correctly set"; | |
} | |
EGLint eglVersionMajor = 0; | |
EGLint eglVersionMinor = 0; | |
// initialize the EGL eglDisplay connection | |
ofLogNotice() << "eglInitialize"; | |
result = eglInitialize(eglDisplay, &eglVersionMajor, &eglVersionMinor); | |
if(result == EGL_BAD_DISPLAY) { | |
// eglDisplay is not an EGL connection | |
ofLogError("ofAppEGLWindow::setupEGL") << "eglInitialize returned EGL_BAD_DISPLAY"; | |
return false; | |
} else if(result == EGL_NOT_INITIALIZED) { | |
// eglDisplay cannot be intitialized | |
ofLogError("ofAppEGLWindow::setupEGL") << "eglInitialize returned EGL_NOT_INITIALIZED"; | |
return false; | |
} else if(result == EGL_FALSE) { | |
// eglinitialize was not initialiezd | |
ofLogError("ofAppEGLWindow::setupEGL") << "eglInitialize returned EGL_FALSE"; | |
return false; | |
} else { | |
// result == EGL_TRUE | |
// success! | |
} | |
// TODO -- give the ability to send in this list when setting up. | |
static const EGLint attribute_list[] = | |
{ | |
EGL_RED_SIZE, 8, // 8 bits for red | |
EGL_GREEN_SIZE, 8, // 8 bits for green | |
EGL_BLUE_SIZE, 8, // 8 bits for blue | |
EGL_ALPHA_SIZE, 8, // 8 bits for alpha | |
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // default eglSurface type | |
EGL_NONE // attribute list is termintated with EGL_NONE | |
}; | |
// get an appropriate EGL frame buffer configuration | |
ofLogNotice() << "eglChooseConfig"; | |
result = eglChooseConfig(eglDisplay, | |
attribute_list, | |
&config, | |
1, | |
&num_config); | |
assert(EGL_FALSE != result); | |
ofLogNotice() << "eglCreateWindowSurface"; | |
eglSurface = eglCreateWindowSurface( eglDisplay, config, (EGLNativeDisplayType)&nativeWindow, NULL ); | |
assert(eglSurface != EGL_NO_SURFACE); | |
// create an EGL rendering eglContext | |
ofLogNotice() << "eglCreateContext"; | |
eglContext = eglCreateContext(eglDisplay, config, EGL_NO_CONTEXT, NULL); | |
assert(eglContext != EGL_NO_CONTEXT); | |
// connect the eglContext to the eglSurface | |
ofLogNotice() << "eglMakeCurrent"; | |
result = eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); | |
assert(EGL_FALSE != result); | |
// Set background color and clear buffers | |
glClearColor(0.15f, 0.15f, 0.15f, 1.0f); | |
glClear( GL_COLOR_BUFFER_BIT ); | |
glClear( GL_DEPTH_BUFFER_BIT ); | |
return true; | |
#else | |
return false; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment