Ejemplo n.º 1
0
void render() {
#if USE_SKIA_OPENGL
    bbutil_clear();
#endif


/************************** BEGIN USER RENDER CODE ***************************/
    // Clear the entire canvas to a solid colour
    SkPaint clearColor;
    clearColor.setARGB(255,0xdd,0xdd,0xdd);
    SkRect fullScreen;
    fullScreen.set(0,0,width,height);
    canvas->drawRect(fullScreen, clearColor);

    // Draw the current demo
    if (demos[currentIndex])
        demos[currentIndex]->onDraw();
/**************************** END USER RENDER CODE ***************************/


    // Draw the contents of the canvas to the screen
#if USE_SKIA_OPENGL
    device->flush();
    bbutil_swap(0);
#else
    bbutil_swap(currentSurface);
    currentSurface = 1 - currentSurface;
    canvas->setBitmapDevice(drawingSurface[currentSurface]);
#endif
}
Ejemplo n.º 2
0
void render() {
    //Typical rendering pass
    glClear(GL_COLOR_BUFFER_BIT);

    //Render background quad first
    glEnable(GL_TEXTURE_2D);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, tex_coord);
    glBindTexture(GL_TEXTURE_2D, background);

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisable(GL_TEXTURE_2D);

    //Use utility code to render welcome text onto the screen
    bbutil_render_text(font, "Hello world", pos_x, pos_y, 0.35f, 0.35f, 0.35f, 1.0f);

    //Use utility code to update the screen
    bbutil_swap();
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: PamC/VSPlugin
void render() {
	int i;

	//Typical rendering pass
	glClear(GL_COLOR_BUFFER_BIT);

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, vertices);

	for (i = 0; i < num_boxes; i++) {
		glPushMatrix();

		glColor4f(boxes[i].color, 0.78f, 0, 1.0f);
		glTranslatef(boxes[i].x, boxes[i].y, 0.0f);
		glScalef(boxes[i].size, boxes[i].size, 1.0f);

		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glPopMatrix();
	}

	glDisableClientState(GL_VERTEX_ARRAY);

	//Use utility code to update the screen
	bbutil_swap();
}
void MinutesPerGameRenderer::render()
{
    if(m_startPos>94)
        return;

    glClear(GL_COLOR_BUFFER_BIT);

    //draw team a
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, m_teamACircle);

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4, GL_FLOAT, 0, m_teamAColors);
    //glColor4f(1.0, 0.0, 0.0, 1.0);

    glDrawArrays(GL_TRIANGLE_FAN, 0, m_startPos);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    //draw team b
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, m_teamBCircle);

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4, GL_FLOAT, 0, m_teamBColors);
    //glColor4f(0.0, 1.0, 0.0, 1.0);

    glDrawArrays(GL_TRIANGLE_FAN, 0, m_startPos);
    m_startPos++;

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    //inner black thing
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, m_innerCircle);

    glColor4f(0.0, 0.0, 0.0, 1.0);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 180);

    glDisableClientState(GL_VERTEX_ARRAY);

    GLfloat separator [] = {
        0.0f,0.0f,0.7f,0.0f,
        0.0f,0.0f,-0.7f,0.0f
    };
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, separator);
    glPointSize(5.0f);
    glColor4f(0.0, 0.0, 0.0, 1.0);
    glDrawArrays(GL_LINE_STRIP, 0, 4);
    glDisableClientState(GL_VERTEX_ARRAY);


    //Use utility code to update the screen
    bbutil_swap();
}
Ejemplo n.º 5
0
void render() {
    // Increment the angle by 0.5 degrees
    static float angle = 0.0f;
    angle += 0.5f * M_PI / 180.0f;

    //Typical render pass
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Draw text
    bbutil_render_text_angle(fontBold16, "Rotate Text", nScreenWidth/2, nScreenHeight/2, 0.75f, 0.75f, 0.75f, 1.0f, angle);

    bbutil_swap();
}
Ejemplo n.º 6
0
static void render() {
    //Typical render pass
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glViewport(0, 0, (int) width, (int) height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrthof(0.0f, width / height, 0.0f, 1.0f, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glScalef(1.0f / height, 1.0f / height, 1.0f);

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    pos_x = ( width / 2 ) - ( button_size_x / 2 );
    pos_y = ( height / 2 ) - ( button_size_y / 2 );
    glTranslatef(pos_x, pos_y, 0.0f);

    glVertexPointer(2, GL_FLOAT, 0, button_vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, button_tex_coord);
    glBindTexture(GL_TEXTURE_2D, button);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glTranslatef(-pos_x, -pos_y, 0.0f);

    pthread_mutex_lock( &textMux );
    bbutil_render_text(font, titleText, 10.0f, height - 100, 0.35f, 0.35f, 0.35f, 1.0f);
    bbutil_render_text(font, statusText, 10.0f, 10.0f, 0.35f, 0.35f, 0.35f, 1.0f);
    bbutil_render_text(font, countText, 10.0f, pos_y - 30, 0.35f, 0.35f, 0.35f, 1.0f);
    pthread_mutex_unlock( &textMux );

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_TEXTURE_2D);

    //Use utility code to update the screen
    bbutil_swap();
}
Ejemplo n.º 7
0
void render()
{
    //Typical render pass
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, vertices);

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4, GL_FLOAT, 0, colors);

    glRotatef(1.0f, 1.0f, 1.0f, 0.0f);

    glDrawArrays(GL_TRIANGLES, 0 , 36);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    //Use utility code to update the screen
    bbutil_swap();
}
Ejemplo n.º 8
0
void render()
{
    //Typical render pass
	bbutil_clear();

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, vertices);

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4, GL_FLOAT, 0, colors);

    glRotatef(angle, 0.0f, 1.0f, 0.0f);

    glDrawArrays(GL_TRIANGLE_STRIP, 0 , 4);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    //Use utility code to update the screen
    bbutil_swap();
}
Ejemplo n.º 9
0
void render()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

    // Render pass
    glEnableClientState(GL_VERTEX_ARRAY);

	test->SetTextLine(30);
	b2Vec2 oldCenter = settings.viewCenter;
	settings.hz = settingsHz;
	test->Step(&settings);
	if (oldCenter.x != settings.viewCenter.x || oldCenter.y != settings.viewCenter.y)
	{
		Resize(width, height);
	}

	test->DrawTitle(5, 15, entry->name);
    drawWidgets();

    glDisableClientState(GL_VERTEX_ARRAY);

	bbutil_swap();

	if (testSelection != testIndex)
	{
		testIndex = testSelection;
		delete test;
		entry = g_testEntries + testIndex;
		test = entry->createFcn();
		viewZoom = 1.0f;
		settings.viewCenter.Set(0.0f, 20.0f);
		Resize(width, height);
	}
}
Ejemplo n.º 10
0
void OSBB10::run() {

	if (!main_loop)
		return;

	main_loop->init();

	int flip = bbutil_is_flipped();
	int rot = bbutil_get_rotation();
	flip_accelerometer = rot == 90;
	printf("**************** rot is %i, flip %i\n", rot, (int)flip_accelerometer);
	/*
	orientation_direction_t orientation;
	int angle;
	orientation_get(&orientation, &angle);
	printf("******************** orientation %i, %i, %i\n", orientation, ORIENTATION_BOTTOM_UP, ORIENTATION_TOP_UP);
	if (orientation == ORIENTATION_BOTTOM_UP) {
		flip_accelerometer = true;
	};
	*/


	while (true) {

		process_events(); // get rid of pending events
		if (Main::iteration()==true)
			break;
		bbutil_swap();
		//#ifdef DEBUG_ENABLED
		fflush(stdout);
		//#endif
	};

	main_loop->finish();

};
Ejemplo n.º 11
0
void zaAppBase::run()
{
	ZaTweener::getInstance()->push(m_active, 2, 0, 0, 0, 1);
	for (;;)
	{
		bps_event_t *event = NULL;

		if (!ZaTweener::getInstance()->empty())
		{
			event = NULL;
		}
		else if (bps_get_event(&event, -1) == BPS_SUCCESS)
		{
			if (event)
			{
				dispatchevent(event);
			}
		}
		for (;;)
		{
			event = NULL;
			e.m_type = 0;
			//screen_get_mtouch_event()
			// wait for ever.
			bps_get_event(&event, 0);
			if (event)
			{
				dispatchevent(event);
			}
			else
				break;
		}
		try
		{
			glClear(GL_COLOR_BUFFER_BIT);
			glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
			int x = 0, y = 0, w = 0, h = 0;
			ZaTweener::getInstance()->run(x, y, w, h);
//			glEnable(GL_SCISSOR_TEST);
//			glScissor(0,0,600,500);
			//			glScissor(ZaTweener::getInstance()->m_x,
			//					ZaTweener::getInstance()->m_y,
			//					ZaTweener::getInstance()->m_w,
			//					ZaTweener::getInstance()->m_h);
//			glDisable(GL_SCISSOR_TEST);
			if (ZaResLib::getInstance()->m_next)
			{
				if (ZaResLib::getInstance()->m_next->m_x != 0)
				{
					ZaResLib::getInstance()->m_next->draw();
				}
				else
				{
					m_active = (ZaScreenBase *) ZaResLib::getInstance()->m_next;
					ZaResLib::getInstance()->m_next = NULL;
					m_active->draw();
				}
			}
			else
				m_active->draw();
//			if (ZaResLib::getInstance()->m_next)
//				ZaResLib::getInstance()->m_next->draw();
			glFlush();
			bbutil_swap();
		} catch (CException &e)
		{
			fprintf(stderr,"%s",e.GetString());
		}
//		getActive();
	}
}
Ejemplo n.º 12
0
void render()
{
    // Clear the screen.
    glClear(GL_COLOR_BUFFER_BIT);

    // Populate vertex and texture coordinate arrays.
    int i;
    for (i = 0; i < QUAD_COUNT; ++i) {
        const GLfloat x = _quads[i].x;
        const GLfloat y = _quads[i].y;
        const GLfloat width = _quads[i].width;
        const GLfloat height = _quads[i].height;
        _vertices[i*8 + 0] = x;
        _vertices[i*8 + 1] = y;
        _vertices[i*8 + 2] = x + width;
        _vertices[i*8 + 3] = y;
        _vertices[i*8 + 4] = x;
        _vertices[i*8 + 5] = y + height;
        _vertices[i*8 + 6] = x + width;
        _vertices[i*8 + 7] = y + height;

        const GLfloat u1 = _quads[i].uvs[0];
        const GLfloat v1 = _quads[i].uvs[1];
        const GLfloat u2 = _quads[i].uvs[2];
        const GLfloat v2 = _quads[i].uvs[3];
        _textureCoords[i*8 + 0] = u1;
        _textureCoords[i*8 + 1] = v2;
        _textureCoords[i*8 + 2] = u2;
        _textureCoords[i*8 + 3] = v2;
        _textureCoords[i*8 + 4] = u1;
        _textureCoords[i*8 + 5] = v1;
        _textureCoords[i*8 + 6] = u2;
        _textureCoords[i*8 + 7] = v1;
    }

    // Draw the virtual gamepad.
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);

    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

    glVertexPointer(2, GL_FLOAT, 0, _vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, _textureCoords);
    glBindTexture(GL_TEXTURE_2D, _gamepadTexture);

    // Draw only connected controllers.
    if (_controllers[0].handle && _controllers[1].handle) {
        glDrawElements(GL_TRIANGLE_STRIP, INDEX_COUNT, GL_UNSIGNED_SHORT, _indices);
    } else if (_controllers[0].handle) {
        glDrawElements(GL_TRIANGLE_STRIP, 120, GL_UNSIGNED_SHORT, _indices);
        glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, _indices + 240);
    } else if (_controllers[1].handle) {
        glDrawElements(GL_TRIANGLE_STRIP, 126, GL_UNSIGNED_SHORT, _indices + 120);
    }

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    // Use utility code to render text.
    for (i = 0; i < MAX_CONTROLLERS; ++i) {
        GameController* controller = &_controllers[i];
        float xOffset = (_surfaceWidth * 0.5f)*i;

        bbutil_render_text(_font, controller->deviceString0, 5 + xOffset, _surfaceHeight - 20, 1.0f, 0.0f, 0.0f, 1.0f);

        if (controller->handle) {
            // Controller is connected; display info about its current state.
            bbutil_render_text(_font, controller->deviceString1, 5 + xOffset, _surfaceHeight - 40, 1.0f, 0.0f, 0.0f, 1.0f);
            bbutil_render_text(_font, controller->buttonsString, 5 + xOffset, _surfaceHeight - 60, 1.0f, 0.0f, 0.0f, 1.0f);
            bbutil_render_text(_font, controller->analog0String, 5 + xOffset, _surfaceHeight - 80, 1.0f, 0.0f, 0.0f, 1.0f);
            bbutil_render_text(_font, controller->analog1String, 5 + xOffset, _surfaceHeight - 100, 1.0f, 0.0f, 0.0f, 1.0f);

            // Render button labels.
            int j;
            for (j = 0; j < MAX_BUTTONS; ++j) {
                Button* button = &_buttons[i][j];
                if (button->type == TRIGGER) {
                    bbutil_render_text(_font, button->label, button->quad->x + 20, button->quad->y + 20, 1.0f, 0.0f, 0.0f, 1.0f);
                } else if (button->type == DPAD_UP) {
                    bbutil_render_text(_font, button->label, button->quad->x + 30, button->quad->y + 70, 1.0f, 0.0f, 0.0f, 1.0f);
                } else if (button->type == DPAD_RIGHT) {
                    bbutil_render_text(_font, button->label, button->quad->x + 70, button->quad->y + 30, 1.0f, 0.0f, 0.0f, 1.0f);
                }
                else {
                    bbutil_render_text(_font, button->label, button->quad->x + 30, button->quad->y + 30, 1.0f, 0.0f, 0.0f, 1.0f);
                }
            }
        }
    }

    if (_controllers[0].handle || _controllers[1].handle) {
        bbutil_render_text(_font, _pollingButton.label, _pollingButton.quad->x + 20, _pollingButton.quad->y + 20, 1.0f, 0.0f, 0.0f, 1.0f);
    }

    // Use utility code to update the screen.
    bbutil_swap();
}
Ejemplo n.º 13
0
void render() {
	int i;
	//Typical render pass
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//First render background and menu if it is enabled
	enable_2d();

	glEnable(GL_TEXTURE_2D);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glVertexPointer(2, GL_FLOAT, 0, shadow_vertices);
	glTexCoordPointer(2, GL_FLOAT, 0, shadow_tex_coord);
	glBindTexture(GL_TEXTURE_2D, shadow);

	//glColor4f(0.85f, 0.85f, 0.85f, 1.0f);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	if (menu_active || menu_show_animation || menu_hide_animation) {
		glTranslatef(pos_x, pos_y, 0.0f);

		for (i = 0; i < 4; i++) {
			if (i == selected) {
				glVertexPointer(2, GL_FLOAT, 0, radio_btn_selected_vertices);
				glTexCoordPointer(2, GL_FLOAT, 0, radio_btn_selected_tex_coord);
				glBindTexture(GL_TEXTURE_2D, radio_btn_selected);
			} else {
				glVertexPointer(2, GL_FLOAT, 0, radio_btn_unselected_vertices);
				glTexCoordPointer(2, GL_FLOAT, 0,
						radio_btn_unselected_tex_coord);
				glBindTexture(GL_TEXTURE_2D, radio_btn_unselected);
			}

			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
			glTranslatef(0.0f, 60.0f, 0.0f);
		}

		glColor4f(0.35f, 0.35f, 0.35f, 1.0f);
		bbutil_render_text(font, "Color Menu", 10.0f, 10.0f);
		bbutil_render_text(font, "Red", 70.0f, -40.0f);
		bbutil_render_text(font, "Green", 70.0f, -100.0f);
		bbutil_render_text(font, "Blue", 70.0f, -160.0f);
		bbutil_render_text(font, "Yellow", 70.0f, -220.0f);
	}

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisable(GL_TEXTURE_2D);

	//Then render the cube
	enable_3d();
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_DEPTH_TEST);

	glTranslatef(cube_pos_x, cube_pos_y, cube_pos_z);

	glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
	glRotatef(15.0f, 0.0f, 0.0f, 1.0f);
	glRotatef(angle, 0.0f, 1.0f, 0.0f);

	glColor4f(cube_color[0], cube_color[1], cube_color[2], cube_color[3]);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);

	glVertexPointer(3, GL_FLOAT, 0, cube_vertices);
	glNormalPointer(GL_FLOAT, 0, cube_normals);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
	glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
	glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
	glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
	glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_DEPTH_TEST);

	//Use utility code to update the screen
	bbutil_swap();
}
Ejemplo n.º 14
0
/**
 * main render function
 */
void render() {
	counter++;
	if(counter >= 36000){
		counter = 0;
	}
	//Typical render pass
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// update dimensions
	enable_2d();

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glPushMatrix();

		// if in portrait mode
		if (oriention_side_up > 0)
		{
			glVertexPointer(2, GL_FLOAT, 0, verticesH);
			glTexCoordPointer(2, GL_FLOAT, 0, tex_coordH);
		}
		// if in landscape mode
		else
		{
			glVertexPointer(2, GL_FLOAT, 0, vertices);
			glTexCoordPointer(2, GL_FLOAT, 0, tex_coord);
		}

		//portrait or landscape?
		glBindTexture(GL_TEXTURE_2D, oriention_side_up>0?backgroundH:background);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glPopMatrix();

	pp = points.begin();

	while (pp != points.end()) {

		if (pp->visible) {
			// draw touchpoint
			glPushMatrix();
				glTranslatef(pp->getX(), (oriention_side_up>0?1024:600) - pp->getY(), 0);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				glVertexPointer(2, GL_FLOAT, 0, verticesTouchpoint);
				glTexCoordPointer(2, GL_FLOAT, 0, tex_coord_touchpoint);
				glBindTexture(GL_TEXTURE_2D, touchpoint);
				glPushMatrix();
					glRotatef((float) ((float)(pp->startRotation) + (float) counter / 0.25f), 0, 0, 1);
					glPushMatrix();
						glTranslatef(-60, -60, 0);
						glColor4f(pp->r,pp->g,pp->b,1);
						glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
					glPopMatrix();
				glPopMatrix();
			glPopMatrix();

			// draw touchpoint number
			glPushMatrix();
				glColor4f(0.3f,0.3f,0.3f,1.0f);
				char buffer [33];
				itoa (pp->id+1,buffer,10);
				glTranslatef(pp->getX()+50,(oriention_side_up>0?1024:600)-pp->getY()+50,0);
				glPushMatrix();
					bbutil_render_text(font,buffer,0,0);
				glPopMatrix();
			glPopMatrix();

		}
		pp++;
	}

	glColor4f(1.0f,1.0f,1.0f,1.0f);

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);

	//Use utility code to update the screen
	bbutil_swap();
}
Ejemplo n.º 15
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;
}