Beispiel #1
0
static void handle_events() {
	int screen_domain = screen_get_domain();
	int navigator_domain = navigator_get_domain();
	int sensor_domain = sensor_get_domain();

	int rc;

	//Request and process available BPS events
	for(;;) {
		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_domain) {
				handleScreenEvent(event);
			} else if (domain == navigator_domain) {
				handleNavigatorEvent(event);
			} else if (domain == sensor_domain) {
				handleSensorEvent(event);
			}
		} else {
			//No more events in the queue
			break;
		}
	}
}
Beispiel #2
0
static void handleEvents()
{
    int domain;

    // Get the first event in the queue.
    bps_event_t *event = NULL;
    if (BPS_SUCCESS != bps_get_event(&event, 0)) {
        fprintf(stderr, "bps_get_event() failed\n");
        return;
    }

    // Handle all events in the queue.
    // If we don't do this in a loop, we'll only handle one event per frame.
    // If many events are triggered quickly, e.g. by spinning the analog sticks,
    // the queue will grow and the user will see the analog sticks lag.
    while (event) {
        if (event) {
            domain = bps_event_get_domain(event);
            if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            } else if (domain == screen_get_domain()) {
                handleScreenEvent(event);
            }
        }

        if (BPS_SUCCESS != bps_get_event(&event, 0)) {
            fprintf(stderr, "bps_get_event() failed\n");
            return;
        }
    }
}
Beispiel #3
0
void handleEvent() {
	//Request and process BPS next available event
	int rc, domain;

	for (;;) {
		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()) {
                handleNavigatorEvent(event);

			} else if (domain == dialog_get_domain()) {
                handle_dialog_response(event);
            }
		} else {
			break;
		}
	}

}
Beispiel #4
0
static void handle_events() {
    //Request and process available BPS events
    for(;;) {
        bps_event_t *event = NULL;
        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 == screen_get_domain()) {
                handleScreenEvent(event);
            } else if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            }
        } else {
            break;
        }
    }
}
Beispiel #5
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;
}
Beispiel #6
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;
}
Beispiel #7
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;
}
Beispiel #8
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;
}