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; }
int OpenGLThread::initBPS() { //Initialize BPS library bps_initialize(); m_api = GL_ES_1; //Create a screen context that will be used to create an EGL surface to to receive libscreen events if (EXIT_SUCCESS != screen_create_context(&m_screen_ctx, 0)) { fprintf(stderr, "screen_request_events failed\n"); return EXIT_FAILURE; } // wait for rendering API to be set while (m_api == GL_UNKNOWN) { usleep(10); }; // initialize EGL if (EXIT_SUCCESS != initEGL()) { fprintf(stderr, "initialize EGL failed\n"); return EXIT_FAILURE; } //Signal BPS library that screen events will be requested if (BPS_SUCCESS != screen_request_events(m_screen_ctx)) { fprintf(stderr, "screen_request_events failed\n"); return EXIT_FAILURE; } setInitialized(true); return EXIT_SUCCESS; }
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; }
int main(int argc, char **argv) { // Create a screen context that will be used to create an EGL surface to receive libscreen events. SCREEN_API(screen_create_context(&_screen_ctx, SCREEN_APPLICATION_CONTEXT), "create_context"); // 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_ctx)) { fprintf(stderr, "Unable to initialize EGL.\n"); screen_destroy_context(_screen_ctx); return 0; } // Initialize app data. if (EXIT_SUCCESS != init()) { fprintf(stderr, "Unable to initialize app logic.\n"); bbutil_terminate(); screen_destroy_context(_screen_ctx); return 0; } // Signal BPS library that navigator and screen events will be requested. if (BPS_SUCCESS != screen_request_events(_screen_ctx)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(_screen_ctx); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(_screen_ctx); return 0; } // Look for attached gamepad and joystick devices. discoverControllers(); // Enter the event loop. while (!_shutdown) { update(); render(); } // Clean up resources and shut everything down. finalize(); return 0; }
void fgPlatformMainLoopPreliminaryWork ( void ) { LOGI("fgPlatformMainLoopPreliminaryWork"); /* Request navigator events */ navigator_request_events(0); /* Allow rotation */ navigator_rotation_lock(false); #ifdef __PLAYBOOK__ /* Request keyboard events */ virtualkeyboard_request_events(0); #endif /* Request window events */ screen_request_events(fgDisplay.pDisplay.screenContext); }
bool QNXEnvironment::init(Game *game) { Environment::init(game); openLogFile(); printLog("--------------------------------------------------------\n"); printLog(" %s - %s\n", m_game->getName(), m_game->getVersion()); printLog("--------------------------------------------------------\n"); bps_initialize(); screen_create_context(&screen_ctx, 0); if (BPS_SUCCESS != screen_request_events(screen_ctx)) { printLog("screen_request_events failed\n"); screen_destroy_context(screen_ctx); return false; } m_screen = new QNXScreen(screen_ctx); m_audio = emyl::manager::get_instance(); m_input = new QNXInput(screen_ctx); setFramesPerSecond(0, false, false); m_game->init(); if (!m_screen->init()) { printLog("ERROR: Couldn't init screen.\n"); return false; } //m_screen->setCaption(m_game->getName()); if (!m_audio-> init()) { printLog("ERROR: Couldn't run sound.\n"); } emyl::setErrorCallback(emylErrorCallback); m_game->load(); return true; }
void BlackberryMain::startMain(int argc, char *argv[]) { g_quitRequested = false; // Receive events from window manager screen_create_context(&screen_cxt, 0); // Initialise Blackberry Platform Services bps_initialize(); // TODO: Enable/disable based on setting sensor_set_rate(SENSOR_TYPE_ACCELEROMETER, 25000); sensor_request_events(SENSOR_TYPE_ACCELEROMETER); net::Init(); startDisplays(); screen_request_events(screen_cxt); navigator_request_events(0); dialog_request_events(0); vibration_request_events(0); NativeInit(argc, (const char **)argv, "/accounts/1000/shared/misc/", "app/native/assets/", "BADCOFFEE"); NativeInitGraphics(); audio = new BlackberryAudio(); runMain(); }
void QQnxBpsEventFilter::registerForScreenEvents(QQnxScreen *screen) { if (!m_screenEventHandler) { qWarning("QQNX: trying to register for screen events, but no handler provided."); return; } int attached; if (screen_get_display_property_iv(screen->nativeDisplay(), SCREEN_PROPERTY_ATTACHED, &attached) != BPS_SUCCESS) { qWarning() << "QQNX: unable to query display attachment"; return; } if (!attached) { qBpsEventFilterDebug() << "skipping event registration for non-attached screen"; return; } if (screen_request_events(screen->nativeContext()) != BPS_SUCCESS) qWarning("QQNX: failed to register for screen events on screen %p", screen->nativeContext()); }
Platform* Platform::create(Game* game, void* attachToWindow) { FileSystem::setResourcePath("./app/native/"); Platform* platform = new Platform(game); // Query game config int samples = 0; Properties* config = Game::getInstance()->getConfig()->getNamespace("window", true); if (config) { samples = std::max(config->getInt("samples"), 0); } __gestureSet = gestures_set_alloc(); swipe_gesture_alloc(NULL, gesture_callback, __gestureSet); pinch_gesture_alloc(NULL, gesture_callback, __gestureSet); tap_gesture_alloc(NULL, gesture_callback, __gestureSet); bps_initialize(); // Initialize navigator and orientation static const int SENSOR_RATE = 25000; 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); navigator_request_events(0); navigator_rotation_lock(true); __orientationAngle = atoi(getenv("ORIENTATION")); int rc = 0; int screenFormat = SCREEN_FORMAT_RGBA8888; #ifdef __X86__ int screenUsage = SCREEN_USAGE_OPENGL_ES2; #else int screenUsage = SCREEN_USAGE_DISPLAY|SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display #endif int screenSwapInterval = WINDOW_VSYNC ? 1 : 0; int screenTransparency = SCREEN_TRANSPARENCY_NONE; char *width_str = getenv("WIDTH"); char *height_str = getenv("HEIGHT"); // Hard-coded to (0,0). int windowPosition[] = { 0, 0 }; EGLint eglConfigCount; // Hard-coded to 32-bit/OpenGL ES 2.0. // NOTE: EGL_SAMPLE_BUFFERS and EGL_SAMPLES MUST remain at the beginning of the attribute list // since they are expected to be at indices 0-3 in config fallback code later. EGLint eglConfigAttrs[] = { EGL_SAMPLE_BUFFERS, samples > 0 ? 1 : 0, EGL_SAMPLES, samples, 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 properties. 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; } if (width_str && height_str) { __screenWindowSize[0] = atoi(width_str); __screenWindowSize[1] = atoi(height_str); } else { 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 ((__orientationAngle == 0) || (__orientationAngle == 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 ((__orientationAngle == 90) || (__orientationAngle == 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_ROTATION, &__orientationAngle); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)"); 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; } 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) { bool success = false; while (samples) { // Try lowering the MSAA sample count until we find a supported config GP_WARN("Failed to find a valid EGL configuration with EGL samples=%d. Trying samples=%d instead.", samples, samples/2); samples /= 2; eglConfigAttrs[1] = samples > 0 ? 1 : 0; eglConfigAttrs[3] = samples; if (eglChooseConfig(__eglDisplay, eglConfigAttrs, &__eglConfig, 1, &eglConfigCount) == EGL_TRUE && eglConfigCount > 0) { success = true; break; } } if (!success) { 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")) { glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES"); glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES"); glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES"); glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES"); } return platform; error: // TODO: cleanup return NULL; }
bool CCEGLView::initGL() { int rc = 0; int screenFormat = SCREEN_FORMAT_RGBA8888; #ifdef __X86__ int screenUsage = SCREEN_USAGE_OPENGL_ES2; #else int screenUsage = SCREEN_USAGE_DISPLAY|SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display #endif // 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; EGLConfig config; // 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(&m_screenContext, 0); if (rc) { perror("screen_create_context"); return false; } // Create the screen window. rc = screen_create_window(&m_screenWindow, m_screenContext); if (rc) { perror("screen_create_window"); return false; } // Set/get any window prooperties. rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_FORMAT, &screenFormat); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)"); return false; } rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_USAGE, &screenUsage); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)"); return false; } char *width_str = getenv("WIDTH"); char *height_str = getenv("HEIGHT"); if (width_str && height_str) { int screen_res[2]; screen_res[0] = atoi(width_str); screen_res[1] = atoi(height_str); int rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, screen_res); if (rc) { fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)"); return false; } } else { screen_display_t screen_display; rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display); if (rc) { perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)"); return false; } 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)"); return false; } int size[2]; rc = screen_get_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, size); if (rc) { perror("screen_get_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)"); return false; } 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 { perror("Navigator returned an unexpected orientation angle."); return false; } rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_ROTATION, &angle); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_ROTATION)"); return false; } rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)"); return false; } } if (windowPosition[0] != 0 || windowPosition[1] != 0) { rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_POSITION, windowPosition); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)"); return false; } } rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_TRANSPARENCY, &screenTransparency); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY)"); return false; } // Double buffered. rc = screen_create_window_buffers(m_screenWindow, 2); if (rc) { perror("screen_create_window_buffers"); return false; } // Create screen event object. rc = screen_create_event(&m_screenEvent); if (rc) { perror("screen_create_event"); return false; } // Request screen events. screen_request_events(m_screenContext); // Get the EGL display and initialize. m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (m_eglDisplay == EGL_NO_DISPLAY) { perror("eglGetDisplay"); return false; } if (eglInitialize(m_eglDisplay, NULL, NULL) != EGL_TRUE) { perror("eglInitialize"); return false; } if (eglChooseConfig(m_eglDisplay, eglConfigAttrs, &config, 1, &eglConfigCount) != EGL_TRUE || eglConfigCount == 0) { checkErrorEGL("eglChooseConfig"); return false; } m_eglContext = eglCreateContext(m_eglDisplay, config, EGL_NO_CONTEXT, eglContextAttrs); if (m_eglContext == EGL_NO_CONTEXT) { checkErrorEGL("eglCreateContext"); return false; } m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_screenWindow, eglSurfaceAttrs); if (m_eglSurface == EGL_NO_SURFACE) { checkErrorEGL("eglCreateWindowSurface"); return false; } if (eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext) != EGL_TRUE) { checkErrorEGL("eglMakeCurrent"); return false; } EGLint width, height; if ((m_eglDisplay == EGL_NO_DISPLAY) || (m_eglSurface == EGL_NO_SURFACE) ) return EXIT_FAILURE; eglQuerySurface(m_eglDisplay, m_eglSurface, EGL_WIDTH, &width); eglQuerySurface(m_eglDisplay, m_eglSurface, EGL_HEIGHT, &height); m_obScreenSize.width = width; m_obScreenSize.height = height; // Set vsync. // eglSwapInterval(m_eglDisplay, screenSwapInterval); return true; }
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; }
void ConfigWindow::runEventLoop(TCOContext *emuContext) { screen_buffer_t buffer = draw(emuContext); bool showingWindow = true; bps_initialize(); screen_request_events(m_context); bps_event_t *event; /* FIXME: How do we verify they ran bps_initialize? */ screen_event_t se; int eventType; int contactId; bool touching = false; bool releasedThisRound = false; int startPos[2] = {0,0}; int endPos[2] = {0,0}; bool scaling = false; while (showingWindow) { const int dirtyRects[4] = {0, 0, m_size[0], m_size[1]}; releasedThisRound = false; bps_get_event(&event, 0); while (showingWindow && event) { int domain = bps_event_get_domain(event); if (domain == navigator_get_domain()) { if (bps_event_get_code(event) == NAVIGATOR_SWIPE_DOWN) showingWindow = false; else if (bps_event_get_code(event) == NAVIGATOR_EXIT) { showingWindow = false; } } else if (domain == screen_get_domain()) { se = screen_event_get_event(event); screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &eventType); screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId); switch (eventType) { case SCREEN_EVENT_MTOUCH_TOUCH: screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId); if (contactId == 0 && !touching && !releasedThisRound) { touching = true; screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, startPos); endPos[0] = startPos[0]; endPos[1] = startPos[1]; } break; case SCREEN_EVENT_MTOUCH_MOVE: screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId); if (contactId == 0 && touching) { screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, endPos); } break; case SCREEN_EVENT_MTOUCH_RELEASE: screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId); if (contactId == 0 && touching) { touching = false; releasedThisRound = true; screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, endPos); } break; case SCREEN_EVENT_PROPERTY: break; default: #ifdef _DEBUG fprintf(stderr, "Unknown screen event: %d\n", eventType); #endif break; } } bps_get_event(&event, 0); } if (releasedThisRound) { m_selected = 0; } else if (touching) { if (!m_selected) m_selected = emuContext->controlAt(startPos); if (m_selected && (endPos[0] != startPos[0] || endPos[1] != startPos[1])) { m_selected->move(endPos[0] - startPos[0], endPos[1] - startPos[1], (unsigned*)m_size); buffer = draw(emuContext); startPos[0] = endPos[0]; startPos[1] = endPos[1]; } } if (buffer) post(buffer); } }
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; }
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; }
// 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; }
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; }
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; }
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; }
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; }
int InitQNX(const char *Title,int Width,int Height) { /* Initialize variables */ AppTitle = Title; XSize = Width; YSize = Height; TimerON = 0; TimerReady = 0; JoyState = 0; LastKey = 0; KeyModes = 0; FrameCount = 0; FrameRate = 0; /* Get initial timestamp */ gettimeofday(&TimeStamp,0); screen_create_context(&ctxt, SCREEN_APPLICATION_CONTEXT); int dispCount; screen_get_context_property_iv(ctxt, SCREEN_PROPERTY_DISPLAY_COUNT, &dispCount); screen_display_t* displays = new screen_display_t[dispCount]; screen_get_context_property_pv(ctxt, SCREEN_PROPERTY_DISPLAYS, (void**)displays); int resolution[2] = { 0, 0 }; screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_SIZE, resolution); delete[] displays; actualSize_x = resolution[0]; actualSize_y = resolution[1]; double scaleY; if (isPhysicalKeyboardDevice) scaleY = ((double)resolution[1]) / 600.0; else scaleY = ((double)resolution[1]) / 1024.0; double scaleX = ((double)resolution[0]) / 600.0; scaleTouchMap(scaleX, scaleY); if (BPS_SUCCESS != screen_request_events(ctxt)) { screen_destroy_context(ctxt); return 0; } #ifdef __BBTEN__ screen_create_window_type(&window, ctxt, SCREEN_CHILD_WINDOW); screen_join_window_group(window, windowGroup); screen_set_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, windowIdLength, "AlmostTIAppID"); int vis = 1; screen_set_window_property_iv(window, SCREEN_PROPERTY_VISIBLE, &vis); int z = -5; screen_set_window_property_iv(window, SCREEN_PROPERTY_ZORDER, &z); if (isPhysicalKeyboardDevice) virtualkeyboard_request_events(0); #else screen_create_window(&window, ctxt); int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_NATIVE; screen_set_window_property_iv(window, SCREEN_PROPERTY_USAGE, &usage); #endif screen_create_window_buffers(window, 1); screen_get_window_property_iv(window, SCREEN_PROPERTY_BUFFER_SIZE, rect+2); /* Done */ return(1); }
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 }
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) { 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; // 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; 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; }
void ScreenWindow::init() { int rc; rc = screen_create_context(&m_context, 0); // if (rc) fprintf(stderr, "Fail at %d: %s\n", __LINE__, strerror(errno)); rc = screen_create_window(&m_appWindow, m_context); char groupName[256]; snprintf(groupName, 256, "screen-%d", getpid()); rc = screen_create_window_group(m_appWindow, groupName); int sizeOfWindow[2] = {1024, 600}; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow); int sizeOfBuffer[2] = {1024, 600}; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer); int format = SCREEN_FORMAT_RGBX8888; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_FORMAT, &format); int usage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE; rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_USAGE, &usage); int angle = 0; char *orientation = getenv("ORIENTATION"); if (orientation) { angle = atoi(orientation); } rc = screen_set_window_property_iv(m_appWindow, SCREEN_PROPERTY_ROTATION, &angle); rc = screen_create_window_buffers(m_appWindow, 1); screen_buffer_t windowBuffer[1]; rc = screen_get_window_property_pv(m_appWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer); int attribs[] = {SCREEN_BLIT_DESTINATION_X, 0, SCREEN_BLIT_DESTINATION_Y, 0, SCREEN_BLIT_DESTINATION_WIDTH, 1024, SCREEN_BLIT_DESTINATION_HEIGHT, 600, SCREEN_BLIT_COLOR, 0xff30ffff, SCREEN_BLIT_END}; rc = screen_fill(m_context, windowBuffer[0], attribs); rc = screen_get_window_property_pv(m_appWindow, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&windowBuffer); int rect[4] = {0, 0, 1024, 600}; rc = screen_post_window(m_appWindow, windowBuffer[0], 1, rect, 0); screen_request_events(m_context); navigator_request_events(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 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 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; }