int main(int argc, char *argv[]) { int rc; int exit_application = 0; initBBSpecific(); initOpenGL(screen_cxt); while (closeApplication == 0) { handleEvent(); render(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char *argv[]) { //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 rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } while (!shutdown) { // Handle user input and accelerometer handle_events(); // Update scene contents update(); // Draw Scene render(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Use utility code to terminate EGL setup bbutil_terminate(); //Shut down BPS library for this process bps_shutdown(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
void finalize() { // Free allocated resources. if (_vertices) { free(_vertices); _vertices = NULL; } if (_indices) { free(_indices); _indices = NULL; } if (_textureCoords) { free(_textureCoords); _textureCoords = NULL; } // Destroy the font. bbutil_destroy_font(_font); // Stop requesting events from libscreen. SCREEN_API(screen_stop_events(_screen_ctx), "stop_events"); // Shut down BPS library for this process. bps_shutdown(); // Use utility code to terminate EGL setup. bbutil_terminate(); // Destroy libscreen context. SCREEN_API(screen_destroy_context(_screen_ctx), "destroy_context"); }
void QQnxBpsEventFilter::unregisterForScreenEvents(QQnxScreen *screen) { if (!m_screenEventHandler) { qWarning("QQNX: trying to unregister for screen events, but no handler provided."); return; } if (screen_stop_events(screen->nativeContext()) != BPS_SUCCESS) qWarning("QQNX: failed to unregister for screen events on screen %p", screen->nativeContext()); }
void BlackberryMain::endMain() { screen_stop_events(screen_cxt); bps_shutdown(); NativeShutdownGraphics(); delete audio; NativeShutdown(); killDisplays(); net::Shutdown(); screen_destroy_context(screen_cxt); }
int main(int argc, char **argv) { const int usage = SCREEN_USAGE_NATIVE; screen_window_t screen_win; screen_buffer_t screen_buf = NULL; int rect[4] = { 0, 0, 0, 0 }; // create an application window which will just act as a background screen_create_context(&screen_ctx, 0); screen_create_window(&screen_win, screen_ctx); screen_create_window_group(screen_win, vf_group); screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage); screen_create_window_buffers(screen_win, 1); screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf); screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); // fill the window with black int attribs[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_END }; screen_fill(screen_ctx, screen_buf, attribs); screen_post_window(screen_win, screen_buf, 1, rect, 0); // position the window at an arbitrary z-order int i = APP_ZORDER; screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &i); // Signal bps library that navigator and screen events will be requested bps_initialize(); screen_request_events(screen_ctx); navigator_request_events(0); // open camera and configure viewfinder if (init_camera() == EOK) { // our main loop just runs a state machine and handles input while (!shutdown) { run_state_machine(); // Handle user input handle_event(); } if (state == STATE_VIEWFINDER) { // clean up camera camera_stop_photo_viewfinder(handle); camera_close(handle); } } // Clean up screen_stop_events(screen_ctx); bps_shutdown(); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return 0; }
void fgPlatformMainLoopPostWork ( void ) { LOGI("fgPlatformMainLoopPostWork"); /* Stop all events */ screen_stop_events(fgDisplay.pDisplay.screenContext); #ifndef __PLAYBOOK__ navigator_stop_events(0); #endif }
void ScreenWindow::quit() { screen_stop_events(m_context); if (m_window) screen_destroy_window(m_window); if (m_appWindow) screen_destroy_window(m_appWindow); if (m_context) screen_destroy_context(m_context); }
void CCEGLView::release() { screen_stop_events(m_screenContext); bps_shutdown(); if (m_eglDisplay != EGL_NO_DISPLAY) { eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } if (m_eglSurface != EGL_NO_SURFACE) { eglDestroySurface(m_eglDisplay, m_eglSurface); m_eglSurface = EGL_NO_SURFACE; } if (m_eglContext != EGL_NO_CONTEXT) { eglDestroyContext(m_eglDisplay, m_eglContext); m_eglContext = EGL_NO_CONTEXT; } if (m_eglDisplay != EGL_NO_DISPLAY) { eglTerminate(m_eglDisplay); m_eglDisplay = EGL_NO_DISPLAY; } if (m_screenWindow) { screen_destroy_window(m_screenWindow); m_screenWindow = NULL; } if (m_screenEvent) { screen_destroy_event(m_screenEvent); m_screenEvent = NULL; } if (m_screenContext) { screen_destroy_context(m_screenContext); m_screenContext = NULL; } eglReleaseThread(); m_isGLInitialized = false; exit(0); }
int main(int argc, char *argv[]) { int exit_application = 0; screen_context_t screen_cxt; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt,0); //Use utility code to initialize EGL for 2D rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init(screen_cxt, GL_ES_1)) { bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize app data initialize(); //Initialize BPS library bps_initialize(); //Signal BPS library that navigator, screen, and keyboard events will be requested screen_request_events(screen_cxt); navigator_request_events(0); virtualkeyboard_request_events(0); virtualkeyboard_show(); for (;;) { //Request and process BPS next available event bps_event_t *event = NULL; if (bps_get_event(&event, 0) != BPS_SUCCESS) return EXIT_FAILURE; if (event) { int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { handleScreenEvent(event); } else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } if (exit_application) { break; } render(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; //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 rendering with GL ES 2.0 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic osg::setNotifyLevel(osg::DEBUG_INFO); // node: interesting geometry CTMcontext cContext; CTMuint vertCount,triCount; CTMuint const * indices; CTMfloat const * vertices; CTMfloat const * normals; cContext = ctmNewContext(CTM_IMPORT); ctmLoad(cContext,"app/native/models/cow.ctm"); if(ctmGetError(cContext) == CTM_NONE) { // access the mesh data vertCount = ctmGetInteger(cContext, CTM_VERTEX_COUNT); vertices = ctmGetFloatArray(cContext, CTM_VERTICES); triCount = ctmGetInteger(cContext, CTM_TRIANGLE_COUNT); indices = ctmGetIntegerArray(cContext, CTM_INDICES); std::cout << "# Mesh has " << vertCount << " vertices\n"; std::cout << "# Mesh has " << triCount << " triangles\n"; } else { std::cout << "Error Reading CTM File!" << std::endl; return -1; } // build up openscenegraph geometry osg::ref_ptr<osg::Vec3Array> listVxArray = new osg::Vec3Array(vertCount); unsigned int vxIdx=0; for(int i=0; i < listVxArray->size(); i++) { osg::Vec3 vertex; vertex.x() = vertices[vxIdx]; vxIdx++; vertex.y() = vertices[vxIdx]; vxIdx++; vertex.z() = vertices[vxIdx]; vxIdx++; listVxArray->at(i) = vertex; } osg::ref_ptr<osg::DrawElementsUInt> listIdxs = new osg::DrawElementsUInt(GL_TRIANGLES,triCount*3); for(int i=0; i < listIdxs->size(); i++) { listIdxs->at(i) = indices[i]; } osg::ref_ptr<osg::Geometry> geomMesh = new osg::Geometry; geomMesh->setVertexArray(listVxArray.get()); geomMesh->addPrimitiveSet(listIdxs.get()); osgUtil::SmoothingVisitor::smooth(*geomMesh); osg::ref_ptr<osg::Geode> geodeMesh = new osg::Geode; geodeMesh->addDrawable(geomMesh.get()); osg::ref_ptr<osg::Group> groupRoot = new osg::Group; groupRoot->addChild(geodeMesh.get()); // free ctm memory ctmFreeContext(cContext); // shader osg::StateSet *ss = geodeMesh->getOrCreateStateSet(); osg::ref_ptr<osg::Program> program = new osg::Program; program->setName( "simpleshader" ); program->addShader( new osg::Shader( osg::Shader::VERTEX, gVertexShader ) ); program->addShader( new osg::Shader( osg::Shader::FRAGMENT, gFragmentShader ) ); ss->setAttributeAndModes(program, osg::StateAttribute::ON); // ss->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::FRONT), osg::StateAttribute::OFF); // ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK), osg::StateAttribute::ON); // rotate that cube osg::ref_ptr<osg::MatrixTransform> nodeSpin = new osg::MatrixTransform; nodeSpin->addChild(geodeMesh.get()); nodeSpin->addUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(0,0,0), osg::Y_AXIS, osg::inDegrees(45.0f))); // node: root osg::ref_ptr<osg::Group> nodeRoot = new osg::Group; nodeRoot->addChild(nodeSpin.get()); // center point osg::BoundingBox modelBounds = geodeMesh->getBoundingBox(); // viewer osgViewer::Viewer myViewer; myViewer.setSceneData(nodeRoot.get()); myViewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3((modelBounds.xMax()-modelBounds.xMin())*2, (modelBounds.yMax()-modelBounds.yMin())*2, (modelBounds.zMax()-modelBounds.zMin())*2), modelBounds.center(), osg::Vec3(0,1,0)); // graphics window embedded osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> myWindow = new osgViewer::GraphicsWindowEmbedded(0,0,1024,600); myWindow->getState()->setUseModelViewAndProjectionUniforms(true); myWindow->getState()->setUseVertexAttributeAliasing(true); // setup viewer myViewer.getCamera()->setViewport(new osg::Viewport(0,0,1024,600)); myViewer.getCamera()->setGraphicsContext(myWindow.get()); myViewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); bps_shutdown(); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); bps_shutdown(); return 0; } //Signal BPS library that navigator orientation is not to be locked if (BPS_SUCCESS != navigator_rotation_lock(false)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); bps_shutdown(); return 0; } while (!exit_application) { //Request and process all available BPS events bps_event_t *event = NULL; for(;;) { rc = bps_get_event(&event, 0); assert(rc == BPS_SUCCESS); if (event) { int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { handleScreenEvent(event); } else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } else { break; } } myViewer.frame(); bbutil_swap(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; bps_initialize(); // Create and set up the app window. if (EXIT_FAILURE == setup_screen()) return EXIT_FAILURE; bbads_set_log_verbosity(2); // Display Banner on screen load_ad(screen_window, WINDOW_GROUP_NAME); screen_request_events(screen_context); navigator_request_events(0); /** * Handle keyboard events and stop playback upon user request. */ for (;;) { bps_event_t *event = 0; if (BPS_SUCCESS != bps_get_event(&event, -1)) { fprintf(stderr, "ERROR: Could not get BPS event!\n"); return EXIT_FAILURE; } if (event) { if (navigator_get_domain() == bps_event_get_domain(event)) { int code = bps_event_get_code(event); if (NAVIGATOR_EXIT == code) { if (BBADS_EOK != bbads_banner_destroy(ad_banner)) { fprintf(stderr, "cannot destroy banner"); } else { fprintf(stderr, "banner destroy"); } exit_application = 1; } } else if (bbads_get_domain() == bps_event_get_domain(event)) { bbads_banner_t* event_banner; bbads_event_get_banner(event, &event_banner); bbads_banner_event_type_t event_type = (bbads_banner_event_type_t)bps_event_get_code(event); banner_event_handler(event_banner, event_type); } else if (screen_get_domain() == bps_event_get_domain(event)) { int screen_val; char buf[1024]; int pos[2]; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); screen_get_event_property_cv(screen_event, SCREEN_PROPERTY_ID_STRING, sizeof(buf), buf); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos); switch (screen_val) { case SCREEN_EVENT_CREATE: fprintf(stderr, "create\n"); if (BBADS_EOK != bbads_banner_is_visible(ad_banner, &ad_is_visible)) { fprintf(stderr, "cannot get banner visibility"); } if (!ad_is_visible) { if (BBADS_EOK != bbads_banner_set_window_visible(ad_banner)) fprintf(stderr, "bbads_banner_set_window_visible has errors\n"); if (BBADS_EOK != bbads_banner_display(ad_banner, screen_context, event)) fprintf(stderr, "create cannot display banner\n"); } break; } if (exit_application) break; } } } screen_stop_events(screen_context); bps_shutdown(); if (screen_destroy_window(screen_window) != 0) return EXIT_FAILURE; if (screen_destroy_context(screen_context) != 0) return EXIT_FAILURE; screen_context = 0; screen_window = 0; return EXIT_SUCCESS; }
// Entry Point int main(int argc, char *argv[]) { static screen_context_t screen_cxt; // Receive events from window manager screen_create_context(&screen_cxt, 0); //Initialise Blackberry Platform Services bps_initialize(); net::Init(); init_GLES2(screen_cxt); #ifdef BLACKBERRY10 // Dev Alpha: 1280x768, 4.2", 356DPI, 0.6f scale int dpi; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_DPI, &dpi); #else // Playbook: 1024x600, 7", 170DPI, 1.25f scale int screen_phys_size[2]; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size); int screen_resolution[2]; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution); double diagonal_pixels = sqrt(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]); double diagonal_inches = 0.0393700787 * sqrt(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]); int dpi = (int)(diagonal_pixels / diagonal_inches + 0.5); #endif float dpi_scale = 213.6f / dpi; dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale); NativeInit(argc, (const char **)argv, "data/", "/accounts/1000/shared", "BADCOFFEE"); NativeInitGraphics(); screen_request_events(screen_cxt); navigator_request_events(0); dialog_request_events(0); #ifdef BLACKBERRY10 vibration_request_events(0); #endif BlackberryAudio* audio = new BlackberryAudio(); InputState input_state; bool running = true; while (running) { input_state.mouse_valid = false; input_state.accelerometer_valid = false; SimulateGamepad(&input_state); while (true) { // Handle Blackberry events bps_event_t *event = NULL; bps_get_event(&event, 0); if (event == NULL) break; // Ran out of events int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { int screen_val, buttons, pointerId; int pair[2]; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pair); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pointerId); input_state.mouse_valid = true; switch(screen_val) { // Touchscreen case SCREEN_EVENT_MTOUCH_TOUCH: case SCREEN_EVENT_MTOUCH_RELEASE: // Up, down input_state.pointer_down[pointerId] = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH); case SCREEN_EVENT_MTOUCH_MOVE: input_state.pointer_x[pointerId] = pair[0] * dpi_scale; input_state.pointer_y[pointerId] = pair[1] * dpi_scale; break; // Mouse, Simulator case SCREEN_EVENT_POINTER: screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &buttons); if (buttons == SCREEN_LEFT_MOUSE_BUTTON) { // Down input_state.pointer_x[pointerId] = pair[0] * dpi_scale; input_state.pointer_y[pointerId] = pair[1] * dpi_scale; input_state.pointer_down[pointerId] = true; } else if (input_state.pointer_down[pointerId]) { // Up input_state.pointer_x[pointerId] = pair[0] * dpi_scale; input_state.pointer_y[pointerId] = pair[1] * dpi_scale; input_state.pointer_down[pointerId] = false; } break; // Keyboard case SCREEN_EVENT_KEYBOARD: int flags, value; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &value); if (flags & (KEY_DOWN | KEY_SYM_VALID)) { for (int b = 0; b < 14; b++) { if (value == buttonMappings[b]) input_state.pad_buttons |= (1<<b); } } break; } } else if (domain == navigator_get_domain()) { switch(bps_event_get_code(event)) { case NAVIGATOR_BACK: case NAVIGATOR_SWIPE_DOWN: input_state.pad_buttons |= PAD_BUTTON_MENU; break; case NAVIGATOR_EXIT: running = false; break; } } } UpdateInputState(&input_state); NativeUpdate(input_state); EndInputState(&input_state); NativeRender(); // On Blackberry, this handles VSync for us eglSwapBuffers(egl_disp, egl_surf); } screen_stop_events(screen_cxt); bps_shutdown(); NativeShutdownGraphics(); delete audio; NativeShutdown(); kill_GLES2(); net::Shutdown(); screen_destroy_context(screen_cxt); exit(0); return 0; }
static void *gfx_ctx_qnx_init(video_frame_info_t *video_info, void *video_driver) { EGLint n; EGLint major, minor; EGLint context_attributes[] = { #ifdef HAVE_OPENGLES2 EGL_CONTEXT_CLIENT_VERSION, 2, #elif HAVE_OPENGLES3 EGL_CONTEXT_CLIENT_VERSION, 3, #endif EGL_NONE }; const EGLint attribs[] = { #ifdef HAVE_OPENGLES2 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, #elif HAVE_OPENGLES3 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, #endif EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE }; qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)calloc(1, sizeof(*qnx)); if (!qnx) goto screen_error; /* Create a screen context that will be used to * create an EGL surface to receive libscreen events */ RARCH_LOG("Initializing screen context...\n"); if (!screen_ctx) { screen_create_context(&screen_ctx, 0); if (screen_request_events(screen_ctx) != BPS_SUCCESS) { RARCH_ERR("screen_request_events failed.\n"); goto screen_error; } if (navigator_request_events(0) != BPS_SUCCESS) { RARCH_ERR("navigator_request_events failed.\n"); goto screen_error; } if (navigator_rotation_lock(false) != BPS_SUCCESS) { RARCH_ERR("navigator_location_lock failed.\n"); goto screen_error; } } #ifdef HAVE_EGL if (!egl_init_context(&qnx->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor, &n, attribs)) { egl_report_error(); goto error; } if (!egl_create_context(&qnx->egl, context_attributes)) { egl_report_error(); goto error; } #endif if(!screen_win) { if (screen_create_window(&screen_win, screen_ctx)) { RARCH_ERR("screen_create_window failed:.\n"); goto error; } } int format = SCREEN_FORMAT_RGBX8888; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n"); goto error; } int usage; #ifdef HAVE_OPENGLES2 usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; #elif HAVE_OPENGLES3 usage = SCREEN_USAGE_OPENGL_ES3 | SCREEN_USAGE_ROTATION; #endif if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n"); goto error; } if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&qnx->screen_disp)) { RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n"); goto error; } int screen_resolution[2]; if (screen_get_display_property_iv(qnx->screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution)) { RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n"); goto error; } #ifndef HAVE_BB10 int angle, size[2]; angle = atoi(getenv("ORIENTATION")); screen_display_mode_t screen_mode; if (screen_get_display_property_pv(qnx->screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode)) { RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n"); goto error; } if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size)) { RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n"); goto error; } int buffer_size[2] = {size[0], 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]))) { buffer_size[1] = size[0]; buffer_size[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]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else { RARCH_ERR("Navigator returned an unexpected orientation angle.\n"); goto error; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n"); goto error; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n"); goto error; } #endif if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS)) { RARCH_ERR("screen_create_window_buffers failed.\n"); goto error; } if (!egl_create_surface(&qnx->egl, screen_win)) goto error; return qnx; error: RARCH_ERR("EGL error: %d.\n", eglGetError()); gfx_ctx_qnx_destroy(video_driver); screen_error: screen_stop_events(screen_ctx); return NULL; }
int main(int argc, char *argv[]) { int exit_application = 0; int rc; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt, 0); initGestures(); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for 2D rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt, GL_ES_1, AUTO)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator orientation is not to be locked if (BPS_SUCCESS != navigator_rotation_lock(false)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } // set up our box2D tests fprintf(stderr, "Box2D Version %d.%d.%d\n", b2_version.major, b2_version.minor, b2_version.revision); testCount = 0; while (g_testEntries[testCount].createFcn != NULL) { ++testCount; } testIndex = b2Clamp(testIndex, 0, testCount-1); testSelection = testIndex; entry = g_testEntries + testIndex; test = entry->createFcn(); test->m_debugDraw.SetFont(font); test->m_debugDraw.SetScreenSize(width, height); struct timespec time_struct; clock_gettime(CLOCK_REALTIME, &time_struct); long update_time = time2millis(&time_struct); long current_time, last_time; #ifdef FPS int frames = 0; last_time = update_time; #endif for (;;) { //Request and process BPS next available event bps_event_t *event = NULL; rc = bps_get_event(&event, 1); assert(rc == BPS_SUCCESS); if (event) { int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { handleScreenEvent(event); } else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } clock_gettime(CLOCK_REALTIME, &time_struct); current_time = time2millis(&time_struct); if ((current_time - update_time) > framePeriod) { update_time = current_time; render(); #ifdef FPS frames++; #endif } else { sleep(0); } #ifdef FPS if (current_time - last_time > 1000) { fprintf(stderr, "fps: %d\n", frames); frames = 0; last_time = current_time; } #endif if (exit_application) break; } // clean up gestures gesturesCleanup(); //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Destroy the font bbutil_destroy_font(font); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int rarch_main(int argc, char *argv[]) { //Initialize bps bps_initialize(); RARCH_LOG("Initializing screen context\n"); // Create a screen context that will be used to create an EGL surface to receive libscreen events screen_create_context(&screen_ctx, 0); if (screen_request_events(screen_ctx) != BPS_SUCCESS) { RARCH_ERR("screen_request_events failed.\n"); goto error; } if (navigator_request_events(0) != BPS_SUCCESS) { RARCH_ERR("navigator_request_events failed.\n"); goto error; } if (navigator_rotation_lock(false) != BPS_SUCCESS) { RARCH_ERR("navigator_location_lock failed.\n"); goto error; } rarch_main_clear_state(); g_extern.verbose = true; int init_ret; struct rarch_main_wrap args = {0}; args.verbose = g_extern.verbose; args.sram_path = NULL; args.state_path = NULL; args.rom_path = "/accounts/1000/shared/documents/roms/quake/pak0.pak"; args.libretro_path = "/accounts/1000/appdata/com.RetroArch.testDev_m_RetroArch181dafc7/app/native/lib/test.so"; args.config_path = "/accounts/1000/appdata/com.RetroArch.testDev_m_RetroArch181dafc7/app/native/retroarch.cfg"; if ((init_ret = rarch_main_init_wrap(&args))) { return init_ret; } rarch_init_msg_queue(); while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()); rarch_main_deinit(); rarch_deinit_msg_queue(); #ifdef PERF_TEST rarch_perf_log(); #endif error: screen_stop_events(screen_ctx); bps_shutdown(); return 0; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; static screen_context_t screen_cxt; //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 in landscape orientation if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt, GL_ES_1, LANDSCAPE)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator orientation is not to be locked if (BPS_SUCCESS != navigator_rotation_lock(false)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } while (!exit_application) { //Request and process BPS next available event bps_event_t *event = NULL; rc = bps_get_event(&event, 0); assert(rc == BPS_SUCCESS); if (event) { int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { handleScreenEvent(event); } else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } render(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char *argv[]) { int exit_application = 0; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_ctx, 0); // Get display configuration (dimensions) int count = 0; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &count); screen_display_t *screen_disps = (screen_display_t *)calloc(count, sizeof(screen_display_t)); screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)screen_disps); screen_display_t screen_disp = screen_disps[0]; free(screen_disps); int dims[2] = { 0, 0 }; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, dims); nScreenWidth = dims[0]; nScreenHeight = dims[1]; //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for rendering with GL ES 2.0 if (EXIT_SUCCESS != bbutil_init_egl(screen_ctx)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); bps_shutdown(); return 0; } while (!exit_application) { //Request and process all available BPS events bps_event_t *event = NULL; for(;;) { if (BPS_SUCCESS != bps_get_event(&event, 0)) { fprintf(stderr, "bps_get_event failed\n"); break; } if (event) { int domain = bps_event_get_domain(event); if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } else { break; } } render(); } //Stop requesting events from libscreen screen_stop_events(screen_ctx); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_ctx); return 0; }
int Platform::enterMessagePump() { GP_ASSERT(_game); int rc; int eventType; int flags; int value; int position[2]; int domain; mtouch_event_t touchEvent; bool suspended = false; // Get the initial time. clock_gettime(CLOCK_REALTIME, &__timespec); __timeStart = timespec2millis(&__timespec); __timeAbsolute = 0L; _game->run(); // Message loop. while (true) { bps_event_t* event = NULL; while (true) { rc = bps_get_event(&event, 1); GP_ASSERT(rc == BPS_SUCCESS); if (event == NULL) break; domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { __screenEvent = screen_event_get_event(event); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_TYPE, &eventType); switch (eventType) { case SCREEN_EVENT_MTOUCH_TOUCH: { screen_get_mtouch_event(__screenEvent, &touchEvent, 0); if (__gestureEventsProcessed.any()) rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL); if ( !rc && (__multiTouch || touchEvent.contact_id == 0) ) { gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, touchEvent.x, touchEvent.y, touchEvent.contact_id); } break; } case SCREEN_EVENT_MTOUCH_RELEASE: { screen_get_mtouch_event(__screenEvent, &touchEvent, 0); if (__gestureEventsProcessed.any()) rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL); if ( !rc && (__multiTouch || touchEvent.contact_id == 0) ) { gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, touchEvent.x, touchEvent.y, touchEvent.contact_id); } if (__gestureSwipeRecognized) { __gestureSwipeRecognized = false; } break; } case SCREEN_EVENT_MTOUCH_MOVE: { screen_get_mtouch_event(__screenEvent, &touchEvent, 0); if (__gestureEventsProcessed.any()) rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL); if ( !rc && (__multiTouch || touchEvent.contact_id == 0) ) { gameplay::Platform::touchEventInternal(Touch::TOUCH_MOVE, touchEvent.x, touchEvent.y, touchEvent.contact_id); } break; } case SCREEN_EVENT_POINTER: { static int mouse_pressed = 0; int buttons; int wheel; // A move event will be fired unless a button state changed. bool move = true; bool left_move = false; // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); // Handle left mouse. Interpret as touch if the left mouse event is not consumed. if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { left_move = true; } else { move = false; mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; mouseOrTouchEvent(Mouse::MOUSE_PRESS_LEFT_BUTTON, Touch::TOUCH_PRESS, position[0], position[1]); } } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { move = false; mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; mouseOrTouchEvent(Mouse::MOUSE_RELEASE_LEFT_BUTTON, Touch::TOUCH_RELEASE, position[0], position[1]); } // Handle right mouse. if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { move = false; mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_PRESS_RIGHT_BUTTON, position[0], position[1], 0); } } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { move = false; mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_RELEASE_RIGHT_BUTTON, position[0], position[1], 0); } // Handle middle mouse. if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { move = false; mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_PRESS_MIDDLE_BUTTON, position[0], position[1], 0); } } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { move = false; mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_RELEASE_MIDDLE_BUTTON, position[0], position[1], 0); } // Fire a move event if none of the buttons changed. if (left_move) { mouseOrTouchEvent(Mouse::MOUSE_MOVE, Touch::TOUCH_MOVE, position[0], position[1]); } else if (move) { gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, position[0], position[1], 0); } // Handle mouse wheel events. if (wheel) { gameplay::Platform::mouseEventInternal(Mouse::MOUSE_WHEEL, position[0], position[1], -wheel); } break; } case SCREEN_EVENT_KEYBOARD: { screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); gameplay::Keyboard::KeyEvent evt = (flags & KEY_DOWN) ? gameplay::Keyboard::KEY_PRESS : gameplay::Keyboard::KEY_RELEASE; // Suppress key repeats. if ((flags & KEY_REPEAT) == 0) { keyEventInternal(evt, getKey(value)); if (evt == gameplay::Keyboard::KEY_PRESS && (flags & KEY_SYM_VALID)) { int unicode = getUnicode(value); if (unicode) keyEventInternal(gameplay::Keyboard::KEY_CHAR, unicode); } } break; } } } else if (domain == navigator_get_domain()) { switch (bps_event_get_code(event)) { case NAVIGATOR_SWIPE_DOWN: _game->menuEvent(); break; case NAVIGATOR_WINDOW_STATE: { navigator_window_state_t state = navigator_event_get_window_state(event); switch (state) { case NAVIGATOR_WINDOW_FULLSCREEN: _game->resume(); suspended = false; break; case NAVIGATOR_WINDOW_THUMBNAIL: case NAVIGATOR_WINDOW_INVISIBLE: if (!suspended) _game->pause(); suspended = true; break; } break; } case NAVIGATOR_EXIT: _game->exit(); break; } } else if (domain == sensor_get_domain()) { if (bps_event_get_code(event) == SENSOR_AZIMUTH_PITCH_ROLL_READING) { float azimuth; sensor_event_get_apr(event, &azimuth, &__pitch, &__roll); } } } // If we are done, then exit. if (_game->getState() == Game::UNINITIALIZED) break; if (!suspended) { _game->frame(); // Post the new frame to the display. // Note that there are a couple cases where eglSwapBuffers could fail // with an error code that requires a certain level of re-initialization: // // 1) EGL_BAD_NATIVE_WINDOW - Called when the surface we're currently using // is invalidated. This would require us to destroy our EGL surface, // close our OpenKODE window, and start again. // // 2) EGL_CONTEXT_LOST - Power management event that led to our EGL context // being lost. Requires us to re-create and re-initalize our EGL context // and all OpenGL ES state. // // For now, if we get these, we'll simply exit. rc = eglSwapBuffers(__eglDisplay, __eglSurface); if (rc != EGL_TRUE) { _game->exit(); perror("eglSwapBuffers"); break; } } } screen_stop_events(__screenContext); bps_shutdown(); screen_destroy_context(__screenContext); return 0; }
int main(int argc, char *argv[]) { char windowGroupId[64] = {0}; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt, 0); // Get the application's window group id so that it can be passed the identity library in cases // where a user may need to be interacted with on the application's behalf. screen_create_window(&screen_wnd, screen_cxt); screen_create_window_group( screen_wnd, NULL ); screen_get_window_property_cv( screen_wnd, SCREEN_PROPERTY_GROUP, sizeof( windowGroupId ), windowGroupId ); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } if( EXIT_SUCCESS != identity_initialize( windowGroupId ) ) { fprintf(stderr, "Initialization of IDS Library failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } identity_trigger_get_username(); // ENTER APPLICATION EVENT LOOP while (!shutdown) { // Handle bps events, includes input and fd changes handle_events(); } identity_shutdown(); //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Use utility code to terminate EGL setup bbutil_terminate(); //Shut down BPS library for this process bps_shutdown(); screen_destroy_window(screen_wnd); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
static bool gfx_ctx_qnx_init(void *data) { /* Create a screen context that will be used to * create an EGL surface to receive libscreen events */ RARCH_LOG("Initializing screen context...\n"); if (!screen_ctx) { screen_create_context(&screen_ctx, 0); if (screen_request_events(screen_ctx) != BPS_SUCCESS) { RARCH_ERR("screen_request_events failed.\n"); goto screen_error; } if (navigator_request_events(0) != BPS_SUCCESS) { RARCH_ERR("navigator_request_events failed.\n"); goto screen_error; } if (navigator_rotation_lock(false) != BPS_SUCCESS) { RARCH_ERR("navigator_location_lock failed.\n"); goto screen_error; } } const EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE }; EGLint num_config; EGLint egl_version_major, egl_version_minor; int format = SCREEN_FORMAT_RGBX8888; EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; int usage; usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; RARCH_LOG("Initializing context\n"); if ((g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) { RARCH_ERR("eglGetDisplay failed.\n"); goto error; } if (!eglInitialize(g_egl_dpy, &egl_version_major, &egl_version_minor)) { RARCH_ERR("eglInitialize failed.\n"); goto error; } if (!eglBindAPI(EGL_OPENGL_ES_API)) { RARCH_ERR("eglBindAPI failed.\n"); goto error; } RARCH_LOG("[BLACKBERRY QNX/EGL]: EGL version: %d.%d\n", egl_version_major, egl_version_minor); if (!eglChooseConfig(g_egl_dpy, attribs, &egl_config, 1, &num_config)) { RARCH_ERR("eglChooseConfig failed.\n"); goto error; } if ((g_egl_ctx = eglCreateContext(g_egl_dpy, egl_config, 0, context_attributes)) == EGL_NO_CONTEXT) { RARCH_ERR("eglCreateContext failed.\n"); goto error; } if(!screen_win) { if (screen_create_window(&screen_win, screen_ctx)) { RARCH_ERR("screen_create_window failed:.\n"); goto error; } } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n"); goto error; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n"); goto error; } if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp)) { RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n"); goto error; } int screen_resolution[2]; if (screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution)) { RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n"); goto error; } #ifndef HAVE_BB10 int angle = atoi(getenv("ORIENTATION")); screen_display_mode_t screen_mode; if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode)) { RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n"); goto error; } int size[2]; if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size)) { RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n"); goto error; } int buffer_size[2] = {size[0], 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]))) { buffer_size[1] = size[0]; buffer_size[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]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else { RARCH_ERR("Navigator returned an unexpected orientation angle.\n"); goto error; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n"); goto error; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle)) { RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n"); goto error; } #endif if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS)) { RARCH_ERR("screen_create_window_buffers failed.\n"); goto error; } if (!(g_egl_surf = eglCreateWindowSurface(g_egl_dpy, egl_config, screen_win, 0))) { RARCH_ERR("eglCreateWindowSurface failed.\n"); goto error; } if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx)) { RARCH_ERR("eglMakeCurrent failed.\n"); goto error; } return true; error: RARCH_ERR("EGL error: %d.\n", eglGetError()); gfx_ctx_qnx_destroy(data); screen_error: screen_stop_events(screen_ctx); return false; }
int main(int argc, char **argv) { shutdown = false; //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(); //Determine initial orientation angle orientation_direction_t direction; orientation_get(&direction, &orientation_angle); //Use utility code to initialize EGL for rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt, GL_ES_1)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != init_blocks()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator orientation is not to be locked if (BPS_SUCCESS != navigator_rotation_lock(false)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Setup Sensors if (sensor_is_supported(SENSOR_TYPE_AZIMUTH_PITCH_ROLL)) { //Microseconds between sensor reads. This is the rate at which the //sensor data will be updated from hardware. The hardware update //rate is set below using sensor_set_rate. static const int SENSOR_RATE = 25000; //Initialize the sensor by setting the rates at which the //sensor values will be updated from hardware sensor_set_rate(SENSOR_TYPE_AZIMUTH_PITCH_ROLL, SENSOR_RATE); sensor_set_skip_duplicates(SENSOR_TYPE_AZIMUTH_PITCH_ROLL, true); sensor_request_events(SENSOR_TYPE_AZIMUTH_PITCH_ROLL); } else { set_gravity(0.0f, -1.0f); } //Start with one cube on the screen add_cube(200, 100); int i = 0; while (!shutdown) { i = check(1); // Handle user input and sensors handle_events(); //Update cube positions update(); // Draw Scene render(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Free app data free(boxes); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char **argv) { int rc; //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 rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "Unable to initialize EGL\n"); screen_destroy_context(screen_cxt); return 0; } //Initialize app data if (EXIT_SUCCESS != init()) { fprintf(stderr, "Unable to initialize app logic\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator orientation is to be locked if (BPS_SUCCESS != navigator_rotation_lock(true)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } for (;;) { //Request and process BPS next available event bps_event_t *event = NULL; rc = bps_get_event(&event, 0); assert(rc == BPS_SUCCESS); if ((event) && (bps_event_get_domain(event) == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { break; } render(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Destroy the font bbutil_destroy_font(font); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char *argv[]) { int rc; // Renderer variables mmr_connection_t* mmr_connection = 0; mmr_context_t* mmr_context = 0; strm_dict_t* dict = NULL; // I/O variables int video_device_output_id = -1; int audio_device_output_id = -1; // Position of the play and stop button. static int ctrl_x = 0; static int ctrl_y = 0; EGLint surface_width; EGLint surface_height; srand(time(0)); app_id = rand(); // I/O devices static char *audio_device_url = "audio:default"; static char video_device_url[PATH_MAX]; rc = snprintf(video_device_url, PATH_MAX, "screen:?winid=videosamplewindowgroup_%d&wingrp=videosamplewindowgroup_%d", app_id, app_id); if (rc >= PATH_MAX) { fprintf(stderr, "URL too long\n"); } // Name of video context...with a random number appended. static char video_context_name[PATH_MAX]; rc = snprintf(video_context_name, PATH_MAX, "samplevideocontextname_%d", app_id); if (rc >= PATH_MAX) { fprintf(stderr, "Video context name too long\n"); } // Window group name...with the same random number appended. static char window_group_name[PATH_MAX]; rc = snprintf(window_group_name, PATH_MAX, "videosamplewindowgroup_%d", app_id); if (rc >= PATH_MAX) { fprintf(stderr, "Video context name too long\n"); } // Video file bundled with our app static const char *video_file_relative_path = "app/native/pb_sample.mp4"; bps_initialize(); // Create the Screen Context. if (screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { fprintf(stderr, "screen_create_context failed\n"); return EXIT_FAILURE; } // Create the window and initialize EGL for GL_ES_1 rendering rc = initialize_egl_window(g_screen_ctx, window_group_name); if (rc != EXIT_SUCCESS) { fprintf(stderr, "initialize_egl_window failed\n"); return EXIT_FAILURE; } // Query width and height of the window surface created by utility code eglQuerySurface(g_egl_disp, g_egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(g_egl_disp, g_egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != EGL_SUCCESS) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } // Initialize GL for 2D rendering glViewport(0, 0, (int)surface_width, (int) surface_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Set world coordinates to coincide with screen pixels glScalef(1.0f / (float)surface_width, 1.0f / (float)surface_height, 1.0f); // We can calculate location and verticies of the controls ctrl_x = (float)surface_width / 2 - ctrl_w / 2; ctrl_y = (float)surface_height / 2 - ctrl_h / 2; g_triangle_vertices[0] = ctrl_x; g_triangle_vertices[1] = ctrl_y; g_triangle_vertices[2] = ctrl_x; g_triangle_vertices[3] = ctrl_y + ctrl_h; g_triangle_vertices[4] = ctrl_x + ctrl_w; g_triangle_vertices[5] = ctrl_y + ctrl_h / 2; g_square_vertices[0] = ctrl_x; g_square_vertices[1] = ctrl_y; g_square_vertices[2] = ctrl_x; g_square_vertices[3] = ctrl_y + ctrl_h; g_square_vertices[4] = ctrl_x + ctrl_w; g_square_vertices[5] = ctrl_y + ctrl_h; g_square_vertices[6] = ctrl_x + ctrl_w; g_square_vertices[7] = ctrl_y; g_square_vertices[8] = ctrl_x; g_square_vertices[9] = ctrl_y; // Configure mm-renderer. mmr_connection = mmr_connect(NULL); if (mmr_connection == NULL) { fprintf(stderr, "mmr_connect failed\n"); return EXIT_FAILURE; } mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO); if (mmr_context == NULL) { fprintf(stderr, "mmr_context_create failed\n"); return EXIT_FAILURE; } // Configure video and audio output. video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video"); if (video_device_output_id == -1) { fprintf(stderr, "mmr_output_attach(video) failed\n"); return EXIT_FAILURE; } audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio"); if (audio_device_output_id == -1) { fprintf(stderr, "mmr_output_attach(audio) failed\n"); return EXIT_FAILURE; } // render 'paused' render(true); // Build up the path where our bundled resource is. char cwd[PATH_MAX]; char media_file[PATH_MAX]; getcwd(cwd,PATH_MAX); rc = snprintf(media_file, PATH_MAX, "file://%s/%s", cwd, video_file_relative_path); if ((rc == -1) || (rc >= PATH_MAX)) { fprintf(stderr, "snprintf(media_file) failed\n"); return EXIT_FAILURE; } // Attach the input media. if (mmr_input_attach(mmr_context, media_file, "track") != 0) { fprintf(stderr, "mmr_input_attach(track) failed\n"); return EXIT_FAILURE; } int video_speed = 0; // Set the speed to 0 to pause the video initially if (mmr_speed_set(mmr_context, video_speed) != 0) { fprintf(stderr, "mmr_set_speed(0) failed\n"); return EXIT_FAILURE; } // Change to the play state, although speed is zero if (mmr_play(mmr_context) != 0) { fprintf(stderr, "mmr_play failed\n"); return EXIT_FAILURE; } /* Do some work to make the aspect ratio correct. */ dict = calculate_rect(surface_width, surface_height); if (NULL == dict) { fprintf(stderr, "calculate_rect failed\n"); return EXIT_FAILURE; } if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) { fprintf(stderr, "mmr_output_parameters failed\n"); return EXIT_FAILURE; } /* Note that we allocated memory for the dictionary, but the call to * mmr_output_parameters() deallocates that memory even on failure. */ dict = NULL; screen_request_events(g_screen_ctx); navigator_request_events(0); screen_window_t video_window = (screen_window_t)0; bool app_window_above = true; int screen_val; int exit_value = EXIT_SUCCESS; // Handle keyboard events and stop playback upon user request. for (;;) { bps_event_t *event = NULL; if (bps_get_event(&event, 0) != BPS_SUCCESS) { return EXIT_FAILURE; } if (event) { if (bps_event_get_domain(event) == navigator_get_domain()) { if (bps_event_get_code(event) == NAVIGATOR_EXIT) { break; } else if(NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) { if ((screen_window_t)0 != video_window) { app_window_above = !app_window_above; if (app_window_above) { screen_val = 1; } else { screen_val = -1; } if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_ZORDER, &screen_val) != 0) { fprintf(stderr, "screen_set_window_property(ZORDER) failed\n"); exit_value = EXIT_FAILURE; break; } screen_val = 1; if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_VISIBLE, &screen_val) != 0) { fprintf(stderr, "screen_set_window_property(VISIBLE) failed\n"); exit_value = EXIT_FAILURE; break; } rc = screen_flush_context(g_screen_ctx, SCREEN_WAIT_IDLE); if (rc != 0) { fprintf (stderr, "Warning: Failed to flush\n"); } } } } else if (bps_event_get_domain(event) == screen_get_domain()) { screen_event_t screen_event = screen_event_get_event(event); int event_type; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type); if (event_type == SCREEN_EVENT_CREATE && (video_window == (screen_window_t)0)) { char id[256]; rc = screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&video_window); if (rc != 0) { fprintf(stderr, "screen_get_event_property(WINDOW) failed\n"); exit_value = EXIT_FAILURE; break; } fprintf(stderr, "video_window%d\n",(int)video_window); rc = screen_get_window_property_cv(video_window, SCREEN_PROPERTY_ID_STRING, 256, id); if (rc != 0) { fprintf(stderr, "screen_get_window_property(ID) failed\n"); exit_value = EXIT_FAILURE; break; } fprintf(stderr, "window ID is %s\n", id); if (strncmp(id, window_group_name, strlen(window_group_name)) != 0) { fprintf(stderr, "window ID mismatch\n"); exit_value = EXIT_FAILURE; break; } } else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) { if (video_speed == 0) { video_speed = 1000; render(false); } else { video_speed = 0; render(true); } if (mmr_speed_set(mmr_context, video_speed) != 0) { fprintf(stderr, "mmr_speed_set(%d) failed\n", video_speed); exit_value = EXIT_FAILURE; break; } } } } } screen_stop_events(g_screen_ctx); if (mmr_stop(mmr_context) != 0) { fprintf(stderr, "mmr_stop failed\n"); exit_value = EXIT_FAILURE; } if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) { fprintf(stderr, "mmr_output_detach(audio) failed\n"); exit_value = EXIT_FAILURE; } if (mmr_output_detach(mmr_context, video_device_output_id) != 0) { fprintf(stderr, "mmr_output_detach(video) failed\n"); exit_value = EXIT_FAILURE; } if (mmr_context_destroy(mmr_context) != 0) { fprintf(stderr, "mmr_context_destroy failed\n"); exit_value = EXIT_FAILURE; } mmr_context = 0; video_device_output_id = -1; audio_device_output_id = -1; mmr_disconnect(mmr_connection); mmr_connection = 0; bps_shutdown(); if (screen_destroy_window(g_screen_win) != 0) { fprintf(stderr, "screen_destroy_window failed\n"); exit_value = EXIT_FAILURE; } if (screen_destroy_context(g_screen_ctx) != 0) { fprintf(stderr, "screen_destroy_context failed\n"); exit_value = EXIT_FAILURE; } g_screen_ctx = 0; g_screen_win = 0; return exit_value; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; // Screen variables screen_context_t screen_context = 0; screen_window_t screen_window = 0; int screen_size[2] = {0,0}; // Renderer variables mmr_connection_t* mmr_connection = 0; mmr_context_t* mmr_context = 0; strm_dict_t* dict = NULL; // I/O variables int video_device_output_id = -1; int audio_device_output_id = -1; bps_initialize(); /* * Create the window used for video output. */ if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } if (screen_create_window(&screen_window, screen_context) != 0) { screen_destroy_context(screen_context); return EXIT_FAILURE; } if (screen_create_window_group(screen_window, window_group_name) != 0) { return EXIT_FAILURE; } int format = SCREEN_FORMAT_RGBA8888; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) { return EXIT_FAILURE; } int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) { return EXIT_FAILURE; } if (screen_create_window_buffers(screen_window, 1) != 0) { return EXIT_FAILURE; } /* * Configure mm-renderer. */ mmr_connection = mmr_connect(NULL); if (mmr_connection == NULL) { return EXIT_FAILURE; } mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO); if (mmr_context == NULL) { return EXIT_FAILURE; } /* * Configure video and audio output. */ video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video"); if (video_device_output_id == -1) { return EXIT_FAILURE; } audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio"); if (audio_device_output_id == -1) { return EXIT_FAILURE; } // Get the render buffer screen_buffer_t temp_buffer[1]; if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) { return EXIT_FAILURE; } // Fill the buffer with a solid color (black) int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x0, SCREEN_BLIT_END}; if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) { return EXIT_FAILURE; } // Make the window visible if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) { return EXIT_FAILURE; } int temp_rectangle[4] = {0, 0, screen_size[0], screen_size[1]}; if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) { return EXIT_FAILURE; } // Prevent the backlight from going off int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE; if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) { return EXIT_FAILURE; } // Build up the path where our bundled resource is. char cwd[PATH_MAX]; char media_file[PATH_MAX]; getcwd(cwd,PATH_MAX); rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/pb_sample.mp4", cwd); if ((rc == -1) || (rc >= PATH_MAX)) { return EXIT_FAILURE; } /* * Start the playback. */ if (mmr_input_attach(mmr_context, media_file, "track") != 0) { return EXIT_FAILURE; } if (mmr_play(mmr_context) != 0) { return EXIT_FAILURE; } /* Do some work to make the aspect ratio correct. */ dict = calculate_rect(screen_size[0], screen_size[1]); if (NULL == dict) { return EXIT_FAILURE; } if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) { return EXIT_FAILURE; } /* Note that we allocated memory for the dictionary, but the call to * mmr_output_parameters() deallocates that memory even on failure. */ dict = NULL; screen_request_events(screen_context); navigator_request_events(0); /* * Handle keyboard events and stop playback upon user request. */ for (;;) { bps_event_t *event = NULL; if (bps_get_event(&event, -1) != BPS_SUCCESS) { return EXIT_FAILURE; } if (event) { if (bps_event_get_domain(event) == navigator_get_domain() && bps_event_get_code(event) == NAVIGATOR_EXIT) { exit_application = 1; } if (exit_application) { break; } } } screen_stop_events(screen_context); if (mmr_stop(mmr_context) != 0) { return EXIT_FAILURE; } if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) { return EXIT_FAILURE; } if (mmr_output_detach(mmr_context, video_device_output_id) != 0) { return EXIT_FAILURE; } if (mmr_context_destroy(mmr_context) != 0) { return EXIT_FAILURE; } mmr_context = 0; video_device_output_id = -1; audio_device_output_id = -1; mmr_disconnect(mmr_connection); mmr_connection = 0; bps_shutdown(); if (screen_destroy_window(screen_window) != 0) { return EXIT_FAILURE; } if (screen_destroy_context(screen_context) != 0) { return EXIT_FAILURE; } screen_context = 0; screen_window = 0; return EXIT_SUCCESS; }
int main(int argc, char **argv) { int rc; #if USE_SKIA_OPENGL RENDERING_API api = GL_ES_2; #else RENDERING_API api = NATIVE; #endif //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 if (EXIT_SUCCESS != bbutil_init(screen_cxt, api)) { fprintf(stderr, "Unable to initialize rendering API\n"); screen_destroy_context(screen_cxt); return 0; } //Initialize app data if (EXIT_SUCCESS != init()) { fprintf(stderr, "Unable to initialize app logic\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator orientation is to be locked if (BPS_SUCCESS != navigator_rotation_lock(true)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } static int counter = 0; for (;;) { //Request and process BPS next available event bps_event_t *event = NULL; rc = bps_get_event(&event, 0); assert(rc == BPS_SUCCESS); if (event) { if (bps_event_get_domain(event) == navigator_get_domain()) { if (bps_event_get_code(event) == NAVIGATOR_EXIT) { break; } } else if (bps_event_get_domain(event) == screen_get_domain()) { int type; int screenPos[2]; screen_event_t se = screen_event_get_event(event); screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &type); screen_get_event_property_iv(se, SCREEN_PROPERTY_POSITION, screenPos); /********************** BEGIN USER EVENT HANDLING CODE ***********************/ if (type == SCREEN_EVENT_MTOUCH_RELEASE) { if (screenPos[1] > height - 100) { if (screenPos[0] > width - 80) { currentIndex++; if (currentIndex > DemoFactory::demoCount() - 1) currentIndex = 0; } else if (screenPos[0] < 80) { currentIndex--; if (currentIndex < 0) currentIndex = DemoFactory::demoCount() - 1; } } } /*********************** END USER EVENT HANDLING CODE ************************/ } } render(); } delete canvas; #if USE_SKIA_OPENGL delete device; delete factory; #endif DemoFactory::deleteDemos(demos); //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }