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; }
CCAccelerometer::CCAccelerometer() { m_pAccelDelegate = NULL; accelerometer_set_update_frequency(FREQ_40_HZ); }
Platform* Platform::create(Game* game) { FileSystem::setResourcePath("./app/native/"); Platform* platform = new Platform(game); bps_initialize(); accelerometer_set_update_frequency(FREQ_40_HZ); navigator_request_events(0); navigator_rotation_lock(true); // Determine initial orientation angle. orientation_direction_t direction; orientation_get(&direction, &__orientationAngle); int rc = 0; int screenFormat = SCREEN_FORMAT_RGBA8888; int screenUsage = SCREEN_USAGE_DISPLAY|SCREEN_USAGE_OPENGL_ES2; int screenSwapInterval = WINDOW_VSYNC ? 1 : 0; int screenTransparency = SCREEN_TRANSPARENCY_NONE; int angle = atoi(getenv("ORIENTATION")); // Hard-coded to (0,0). int windowPosition[] = { 0, 0 }; EGLint eglConfigCount; // Hard-coded to 32-bit/OpenGL ES 2.0. const EGLint eglConfigAttrs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_STENCIL_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; const EGLint eglContextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; const EGLint eglSurfaceAttrs[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE }; // Create the screen context. rc = screen_create_context(&__screenContext, 0); if (rc) { perror("screen_create_context"); goto error; } // Create the screen window. rc = screen_create_window(&__screenWindow, __screenContext); if (rc) { perror("screen_create_window"); goto error; } // Set/get any window prooperties. rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_FORMAT, &screenFormat); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)"); goto error; } rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_USAGE, &screenUsage); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)"); goto error; } screen_display_t screen_display; rc = screen_get_window_property_pv(__screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display); if (rc) { perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)"); goto error; } screen_display_mode_t screen_mode; rc = screen_get_display_property_pv(screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode); if (rc) { perror("screen_get_display_property_pv(SCREEN_PROPERTY_MODE)"); goto error; } int size[2]; rc = screen_get_window_property_iv(__screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, size); if (rc) { perror("screen_get_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)"); goto error; } __screenWindowSize[0] = size[0]; __screenWindowSize[1] = size[1]; if ((angle == 0) || (angle == 180)) { if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) || ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) { __screenWindowSize[1] = size[0]; __screenWindowSize[0] = size[1]; } } else if ((angle == 90) || (angle == 270)) { if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) || ((screen_mode.width < screen_mode.height) && (size[0] < size[1]))) { __screenWindowSize[1] = size[0]; __screenWindowSize[0] = size[1]; } } else { perror("Navigator returned an unexpected orientation angle."); goto error; } rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, __screenWindowSize); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)"); goto error; } rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_ROTATION, &angle); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)"); goto error; } if (windowPosition[0] != 0 || windowPosition[1] != 0) { rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_POSITION, windowPosition); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)"); goto error; } } rc = screen_set_window_property_iv(__screenWindow, SCREEN_PROPERTY_TRANSPARENCY, &screenTransparency); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY)"); goto error; } // Double buffered. rc = screen_create_window_buffers(__screenWindow, 2); if (rc) { perror("screen_create_window_buffers"); goto error; } // Create screen event object. rc = screen_create_event(&__screenEvent); if (rc) { perror("screen_create_event"); goto error; } // Request screen events. screen_request_events(__screenContext); // Get the EGL display and initialize. __eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (__eglDisplay == EGL_NO_DISPLAY) { perror("eglGetDisplay"); goto error; } if (eglInitialize(__eglDisplay, NULL, NULL) != EGL_TRUE) { perror("eglInitialize"); goto error; } if (eglChooseConfig(__eglDisplay, eglConfigAttrs, &__eglConfig, 1, &eglConfigCount) != EGL_TRUE || eglConfigCount == 0) { checkErrorEGL("eglChooseConfig"); goto error; } __eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextAttrs); if (__eglContext == EGL_NO_CONTEXT) { checkErrorEGL("eglCreateContext"); goto error; } __eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, __screenWindow, eglSurfaceAttrs); if (__eglSurface == EGL_NO_SURFACE) { checkErrorEGL("eglCreateWindowSurface"); goto error; } if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) != EGL_TRUE) { checkErrorEGL("eglMakeCurrent"); goto error; } // Set vsync. eglSwapInterval(__eglDisplay, screenSwapInterval); // Initialize OpenGL ES extensions. __glExtensions = (const char*)glGetString(GL_EXTENSIONS); if (strstr(__glExtensions, "GL_OES_vertex_array_object") || strstr(__glExtensions, "GL_ARB_vertex_array_object")) { // Disable VAO extension for now. glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES"); glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArrays"); glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES"); glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES"); } return platform; error: // TODO: cleanup // return NULL; }