void OSBB10::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { data_dir = getenv("HOME"); //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt,0); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for 2D rendering with GL ES 1.1 enum RENDERING_API api = GL_ES_2; #ifdef BB10_LGLES_OVERRIDE api = GL_ES_1; #endif if (EXIT_SUCCESS != bbutil_init(screen_cxt, api)) { bbutil_terminate(); screen_destroy_context(screen_cxt); return; }; EGLint surface_width, surface_height; eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); printf("screen size: %ix%i\n", surface_width, surface_height); VideoMode mode; mode.width = surface_width; mode.height = surface_height; mode.fullscreen = true; mode.resizable = false; set_video_mode(mode); //Signal BPS library that navigator and screen events will be requested screen_request_events(screen_cxt); navigator_request_events(0); virtualkeyboard_request_events(0); audiodevice_request_events(0); #ifdef DEBUG_ENABLED bps_set_verbosity(3); #endif accel_supported = accelerometer_is_supported(); if (accel_supported) accelerometer_set_update_frequency(FREQ_40_HZ); pitch = 0; roll = 0; #ifdef BB10_LGLES_OVERRIDE rasterizer = memnew( RasterizerGLES1(false) ); #else rasterizer = memnew( RasterizerGLES2(false, false) ); #endif visual_server = memnew( VisualServerRaster(rasterizer) ); visual_server->init(); visual_server->cursor_set_visible(false, 0); audio_driver = memnew(AudioDriverBB10); audio_driver->set_singleton(); audio_driver->init(NULL); physics_server = memnew( PhysicsServerSW ); physics_server->init(); physics_2d_server = memnew( Physics2DServerSW ); physics_2d_server->init(); input = memnew( InputDefault ); #ifdef PAYMENT_SERVICE_ENABLED payment_service = memnew(PaymentService); Globals::get_singleton()->add_singleton(Globals::Singleton("InAppStore", payment_service)); #endif }
/** * A sample application demonstrates the BlackBerry Native APIs for accelerometer. * The sample initializes and reads the accelerometer periodically until a * NAVIGATOR_EXIT event is received. * The application also listens for window state changes from the navigator so that * it can stop reading the accelerometer when the application is no longer visible. */ int main(int argc, char *argv[]) { if (setup_screen() != EXIT_SUCCESS) { printf("Unable to set up the screen. Exiting."); return 0; } /* * The accelerometer forces */ double force_x, force_y, force_z; /* * Before we can listen for events from the BlackBerry Tablet OS platform * services, we need to initialize the BPS infrastructure */ bps_initialize(); /* * Once the BPS infrastructure has been initialized we can register for * events from the various BlackBerry Tablet OS platform services. The * Navigator service manages and delivers application life cycle and * visibility events. * For this sample, we request Navigator events so we can track when * the system is terminating the application (NAVIGATOR_EXIT event). This allows * us to clean up application resources. */ navigator_request_events(0); /* * Before initializing the accelerometer service we must ensure the device * supports it */ if (!accelerometer_is_supported()) { /* * If the device does not support accelerometer then notify the user, * clean up and exit */ printf("Accelerometer not supported by device!"); bps_shutdown(); return EXIT_FAILURE; } /* * Initialize the accelerometer by setting the rates at which the * accelerometer values will be updated from hardware */ accelerometer_set_update_frequency(FREQ_40_HZ); /* * Process Navigator events and take accelerometer readings periodically * until we receive a NAVIGATOR_EXIT event. */ int exit_application = 0; int paused = 0; while (!exit_application) { /* * By setting the bps_get_event timeout to ACCELEROMETER_MAX_POLL_INTERVAL, * we assign the maximum time (in millis) that we will wait before * unblocking so we can take an accelerometer reading. */ bps_event_t *event = NULL; bps_get_event(&event, ACCELEROMETER_MAX_POLL_INTERVAL); if (event) { if (bps_event_get_domain(event) == navigator_get_domain()) { /* * If it is a NAVIGATOR_EXIT event then set the * exit_application flag so the application will stop * processing events, clean up and exit. * * If it is a NAVIGATOR_WINDOW_STATE event, and the window * state is NAVIGATOR_WINDOW_INVISIBLE, set paused to true so * that we stop collecting accelerometer data. Otherwise, if * we're currently paused, then set paused back to false to * resume collecting accelerometer data. */ unsigned int event_code = bps_event_get_code(event); if (NAVIGATOR_EXIT == event_code) { exit_application = 1; } else if (NAVIGATOR_WINDOW_STATE == event_code) { if (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN) { /* * The application is now full screen. * Resume reading the accelerometer. */ paused = 0; printf("Resuming accelerometer reads.\n"); } else if (!paused){ /* * The application has become thumbnailed or invisible. * If it is not already paused, then pause it. * Otherwise, ignore the window state change. */ paused = 1; printf("Resuming accelerometer reads.\n"); } } } /* * Remember to destroy any delivered events as we need to trigger * the release of any event resources when we are done processing * it. */ bps_event_destroy(event); } else { /* * We've woken up. See if we are in the paused state. If not, * take an accelerometer reading */ if (!paused) { accelerometer_read_forces(&force_x, &force_y, &force_z); display_accelerometer_reading( ACCELEROMETER_CALCULATE_PITCH(force_x, force_y, force_z), ACCELEROMETER_CALCULATE_ROLL(force_x, force_y, force_z)); } } } /* * Clean up screen resources */ screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); /* * Clean up the BPS infrastructure and exit */ bps_shutdown(); return 0; }