void zaFont::initbyPath(const char * path ,int size) { m_dpi = bbutil_calculate_dpi(0); if (path ==NULL || path[0]==0) { if (access("/usr/fonts/font_repository/adobe/AdobeHeitiStd-Regular.otf",F_OK)>=0) { sprintf(m_path,"%s","/usr/fonts/font_repository/adobe/AdobeHeitiStd-Regular.otf"); } else if (access("/usr/fonts/font_repository/monotype/MHeiB.GB18030_200910.ttf",F_OK)>=0) { sprintf(m_path,"%s","/usr/fonts/font_repository/monotype/MHeiB.GB18030_200910.ttf"); } initFont(m_path); } else { sprintf(m_path,"%s",path); initFont(m_path); } m_size = size; char en_charmap[128*2]; for (int i = 0 ; i < 128; i ++) { en_charmap[i*2] = (char) (i % 256); en_charmap[i*2+1] =(char) (i/ 256); } load_font(en_charmap,128*2); }
int initialize() { //Query width and height of the window surface created by utility code EGLint surface_width, surface_height; int dpi = bbutil_calculate_dpi(screen_cxt); font = bbutil_load_font("/usr/fonts/font_repository/monotype/tahoma.ttf", 6, dpi); if (!font) return EXIT_FAILURE; localDraw.SetFont(font); localDraw.SetScreenSize(width, height); eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); width = surface_width; height = surface_height; // calculate the position of the next/prev buttons in world coordinates centerPrev.x = width / 2 - 88; centerNext.x = width / 2 + 88; centerPrev.y = height / 10; centerNext.y = height / 10; radius = 24; EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query egl surface dimensions\n"); return EXIT_FAILURE; } glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepthf(1.0); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Resize(width, height); return EXIT_SUCCESS; }
int initialize() { int dpi = bbutil_calculate_dpi(screen_ctx); if (dpi == EXIT_FAILURE) { fprintf(stderr, "init(): Unable to calculate dpi\n"); return EXIT_FAILURE; } //As bbutil renders text using device-specifc dpi, we need to compute a point size //for the font, so that the text string fits into the bubble. Note that Playbook is used //as a reference point in this equation as we know that at dpi of 170, font with point size of //15 fits into the bubble texture. int point_size16 = (int)(16.0f / ((float)dpi / 170.0f )); fontBold16 = bbutil_load_font("/usr/fonts/font_repository/dejavu-ttf-2.17/DejaVuSans-Bold.ttf", point_size16, dpi); if (!fontBold16) { return EXIT_FAILURE; } return EXIT_SUCCESS; }
int init() { EGLint surface_width, surface_height; //On initialize bbutil loads arial as a default font. We are going to load MyriadPro-Bold as it looks a little better and scale it //to fit out bubble nicely. int dpi = bbutil_calculate_dpi(screen_cxt); font = bbutil_load_font( "/usr/fonts/font_repository/adobe/MyriadPro-Bold.otf", 15, dpi); if (!font) { return EXIT_FAILURE; } //Load background texture float tex_x, tex_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/HelloWorld_smaller_bubble.png", NULL, NULL, &tex_x, &tex_y, &background)) { fprintf(stderr, "Unable to load background texture\n"); } //Query width and height of the window surface created by utility code eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } width = (float) surface_width; height = (float) surface_height; //Initialize GL for 2D rendering 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(); //Set world coordinates to coincide with screen pixels glScalef(1.0f / height, 1.0f / height, 1.0f); float text_width, text_height; bbutil_measure_text(font, "Hello world", &text_width, &text_height); pos_x = (width - text_width) / 2; pos_y = height / 2; //Setup background polygon vertices[0] = 0.0f; vertices[1] = 0.0f; vertices[2] = width; vertices[3] = 0.0f; vertices[4] = 0.0f; vertices[5] = height; vertices[6] = width; vertices[7] = height; tex_coord[0] = 0.0f; tex_coord[1] = 0.0f; tex_coord[2] = tex_x; tex_coord[3] = 0.0f; tex_coord[4] = 0.0f; tex_coord[5] = tex_y; tex_coord[6] = tex_x; tex_coord[7] = tex_y; return EXIT_SUCCESS; }
int init() { // Initialize our static variables and controllers. _font = NULL; _shutdown = false; _polling = false; int i; for (i = 0; i < MAX_CONTROLLERS; ++i) { initController(&_controllers[i], i); _activeButton[i] = NULL; } // Populate an array of button mappings. for (i = 0; i < 32; ++i) { _buttonMappings[i] = 1 << i; } EGLint surface_width, surface_height; // Query width and height of the window surface created by utility code. eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, 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; } _surfaceHeight = (float) surface_height; _surfaceWidth = (float) surface_width; // Calculate our display's DPI and load our font using utility code. int dpi = bbutil_calculate_dpi(_screen_ctx); _font = bbutil_load_font("/usr/fonts/font_repository/monotype/cour.ttf", FONT_SIZE, dpi); if (!_font) { fprintf(stderr, "Unable to load font.\n"); return EXIT_FAILURE; } // Load our gamepad texture atlas. int w, h; float tx, ty; if (bbutil_load_texture("./app/native/gamepad.png", &w, &h, &tx, &ty, &_gamepadTexture) == EXIT_FAILURE) { fprintf(stderr, "Unable to load texture.\n"); return EXIT_FAILURE; } // Set the initial positions of all joysticks and buttons. for (i = 0; i < MAX_CONTROLLERS; ++i) { /** * Quads | Buttons * * 0-3 | Analog sticks. * 4-7 | D-Pad. Up, Down, Left, Right. * 8-11 | A, B, X, Y Buttons. * 12,13 | Analog stick triggers (L3, R3) -- represented as buttons below the sticks. * 14-17 | Triggers: L1, L2, R1, R2. * 18,19 | Select, Start. */ int controllerIndex = 20*i; float xOffset = (_surfaceWidth * 0.5f)*i; Quad* analog0Outer = &_quads[0 + controllerIndex]; analog0Outer->x = ANALOG0_X + xOffset; analog0Outer->y = ANALOG_Y; analog0Outer->width = analog0Outer->height = ANALOG_SIZE; analog0Outer->uvs = _outerUVs; _analog0Inner[i] = &_quads[1 + controllerIndex]; _analog0Inner[i]->x = ANALOG0_X + xOffset; _analog0Inner[i]->y = ANALOG_Y; _analog0Inner[i]->width = _analog0Inner[i]->height = ANALOG_SIZE; _analog0Inner[i]->uvs = _innerUVs; Quad* analog1Outer = &_quads[2 + controllerIndex]; analog1Outer->x = ANALOG1_X + xOffset; analog1Outer->y = ANALOG_Y; analog1Outer->width = analog1Outer->height = ANALOG_SIZE; analog1Outer->uvs = _outerUVs; _analog1Inner[i] = &_quads[3 + controllerIndex]; _analog1Inner[i]->x = ANALOG1_X + xOffset; _analog1Inner[i]->y = ANALOG_Y; _analog1Inner[i]->width = _analog1Inner[i]->height = ANALOG_SIZE; _analog1Inner[i]->uvs = _innerUVs; // Common to all buttons. int j; for (j = 0; j < 16; ++j) { // Default mappings. _buttons[i][j].mapping = _buttonMappings[j]; // Assign quads. _buttons[i][j].quad = &_quads[j+4 + controllerIndex]; } // D-Pad. for (j = 0; j < 4; ++j) { _buttons[i][j].type = DPAD_UP + j; } // Buttons. for (j = 4; j < 10; ++j) { _buttons[i][j].type = BUTTON; _buttons[i][j].quad->width = BUTTON_SIZE; _buttons[i][j].quad->height = BUTTON_SIZE; _buttons[i][j].quad->uvs = _buttonUpUVs; } // Triggers for (j = 10; j < 16; ++j) { _buttons[i][j].type = TRIGGER; _buttons[i][j].quad->width = TRIGGER_WIDTH; _buttons[i][j].quad->height = TRIGGER_HEIGHT; _buttons[i][j].quad->uvs = _triggerUpUVs; } // Set quad positions and sizes. // Up _buttons[i][0].label = "U"; _buttons[i][0].quad->x = DPAD_X + DPAD_SHORT + xOffset; _buttons[i][0].quad->y = DPAD_Y + DPAD_LONG; _buttons[i][0].quad->width = DPAD_SHORT; _buttons[i][0].quad->height = DPAD_LONG; _buttons[i][0].quad->uvs = _upDPadUpUVs; _buttons[i][0].mapping = SCREEN_DPAD_UP_GAME_BUTTON; // Down _buttons[i][1].label = "D"; _buttons[i][1].quad->x = DPAD_X + DPAD_SHORT + xOffset; _buttons[i][1].quad->y = DPAD_Y; _buttons[i][1].quad->width = DPAD_SHORT; _buttons[i][1].quad->height = DPAD_LONG; _buttons[i][1].quad->uvs = _downDPadUpUVs; _buttons[i][1].mapping = SCREEN_DPAD_DOWN_GAME_BUTTON; // Left _buttons[i][2].label = "L"; _buttons[i][2].quad->x = DPAD_X + xOffset; _buttons[i][2].quad->y = DPAD_Y + DPAD_SHORT; _buttons[i][2].quad->width = DPAD_LONG; _buttons[i][2].quad->height = DPAD_SHORT; _buttons[i][2].quad->uvs = _leftDPadUpUVs; _buttons[i][2].mapping = SCREEN_DPAD_LEFT_GAME_BUTTON; // Right _buttons[i][3].label = "R"; _buttons[i][3].quad->x = DPAD_X + DPAD_LONG + xOffset; _buttons[i][3].quad->y = DPAD_Y + DPAD_SHORT; _buttons[i][3].quad->width = DPAD_LONG; _buttons[i][3].quad->height = DPAD_SHORT; _buttons[i][3].quad->uvs = _rightDPadUpUVs; _buttons[i][3].mapping = SCREEN_DPAD_RIGHT_GAME_BUTTON; // A, B, X, Y _buttons[i][4].label = "A"; _buttons[i][4].quad->x = BUTTONS_X + BUTTON_SIZE + xOffset; _buttons[i][4].quad->y = BUTTONS_Y; _buttons[i][4].mapping = SCREEN_A_GAME_BUTTON; _buttons[i][5].label = "B"; _buttons[i][5].quad->x = BUTTONS_X + 2*BUTTON_SIZE + xOffset; _buttons[i][5].quad->y = BUTTONS_Y + BUTTON_SIZE; _buttons[i][5].mapping = SCREEN_B_GAME_BUTTON; _buttons[i][6].label = "X"; _buttons[i][6].quad->x = BUTTONS_X + xOffset; _buttons[i][6].quad->y = BUTTONS_Y + BUTTON_SIZE; _buttons[i][6].mapping = SCREEN_X_GAME_BUTTON; _buttons[i][7].label = "Y"; _buttons[i][7].quad->x = BUTTONS_X + BUTTON_SIZE + xOffset; _buttons[i][7].quad->y = BUTTONS_Y + 2*BUTTON_SIZE; _buttons[i][7].mapping = SCREEN_Y_GAME_BUTTON; // L3, R3 _buttons[i][8].label = "L3"; _buttons[i][8].quad->x = ANALOG0_X + BUTTON_SIZE*2.0f + xOffset; _buttons[i][8].quad->y = ANALOG_Y + BUTTON_SIZE; _buttons[i][8].mapping = SCREEN_L3_GAME_BUTTON; _buttons[i][9].label = "R3"; _buttons[i][9].quad->x = ANALOG1_X - BUTTON_SIZE*2.0f + xOffset; _buttons[i][9].quad->y = ANALOG_Y + BUTTON_SIZE; _buttons[i][9].mapping = SCREEN_R3_GAME_BUTTON; // Triggers: L1, L2, R1, R2 _buttons[i][10].label = "L1"; _buttons[i][10].quad->x = LEFT_TRIGGERS_X + xOffset; _buttons[i][10].quad->y = TRIGGERS_Y; _buttons[i][10].mapping = SCREEN_L1_GAME_BUTTON; _buttons[i][11].label = "L2"; _buttons[i][11].quad->x = LEFT_TRIGGERS_X + xOffset; _buttons[i][11].quad->y = TRIGGERS_Y + TRIGGER_HEIGHT + 25.0f; _buttons[i][11].mapping = SCREEN_L2_GAME_BUTTON; _buttons[i][12].label = "R1"; _buttons[i][12].quad->x = RIGHT_TRIGGERS_X + xOffset; _buttons[i][12].quad->y = TRIGGERS_Y; _buttons[i][12].mapping = SCREEN_R1_GAME_BUTTON; _buttons[i][13].label = "R2"; _buttons[i][13].quad->x = RIGHT_TRIGGERS_X + xOffset; _buttons[i][13].quad->y = TRIGGERS_Y + TRIGGER_HEIGHT + 25.0f; _buttons[i][13].mapping = SCREEN_R2_GAME_BUTTON; // Select, Start _buttons[i][14].label = "Select"; _buttons[i][14].quad->x = SELECT_X + xOffset; _buttons[i][14].quad->y = SELECT_Y; _buttons[i][14].mapping = SCREEN_MENU1_GAME_BUTTON; _buttons[i][15].label = "Start"; _buttons[i][15].quad->x = SELECT_X + xOffset; _buttons[i][15].quad->y = SELECT_Y + TRIGGER_HEIGHT + 25.0f; _buttons[i][15].mapping = SCREEN_MENU2_GAME_BUTTON; } // Finally, one last quad is used for the "polling" button. Quad* pollingQuad = &_quads[40]; pollingQuad->x = (surface_width * 0.5f) - TRIGGER_WIDTH * 0.5f; pollingQuad->y = 5.0f; pollingQuad->width = TRIGGER_WIDTH; pollingQuad->height = TRIGGER_HEIGHT; pollingQuad->uvs = _triggerUpUVs; _pollingButton.quad = pollingQuad; _pollingButton.type = TRIGGER; _pollingButton.label = "Polling"; // Create our vertex and texture coordinate arrays. _vertices = (GLfloat*) calloc(VERTEX_COORD_COUNT, sizeof(GLfloat)); _textureCoords = (GLfloat*) calloc(TEXCOORD_COUNT, sizeof(GLfloat)); // Create and initialize our index array. _indices = (GLushort*) calloc(INDEX_COUNT, sizeof(GLushort)); _indices[0] = 0; _indices[1] = 1; _indices[2] = 2; _indices[3] = 3; _indices[4] = 3; _indices[5] = 4; int vertexCount = 4; for (i = 1; i < QUAD_COUNT; ++i) { _indices[i*6] = vertexCount; _indices[i*6 + 1] = 1 + vertexCount; _indices[i*6 + 2] = 2 + vertexCount; _indices[i*6 + 3] = 3 + vertexCount; _indices[i*6 + 4] = 3 + vertexCount; vertexCount += 4; _indices[i*6 + 5] = vertexCount; } // Initialize OpenGL for 2D rendering. glViewport(0, 0, surface_width, 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 / _surfaceHeight, 1.0f); return EXIT_SUCCESS; }
int initialize() { //Load shadow and button textures float tex_x = 1.0f, tex_y = 1.0f; //Load textures for radio buttons int size_x = 64, size_y = 64; if (EXIT_SUCCESS != bbutil_load_texture("app/native/radio_btn_unselected.png", NULL, NULL, &tex_x, &tex_y, &radio_btn_unselected)) { fprintf(stderr, "Unable to load non-selected radio button texture\n"); } radio_btn_unselected_vertices[0] = 0.0f; radio_btn_unselected_vertices[1] = 0.0f; radio_btn_unselected_vertices[2] = size_x; radio_btn_unselected_vertices[3] = 0.0f; radio_btn_unselected_vertices[4] = 0.0f; radio_btn_unselected_vertices[5] = size_y; radio_btn_unselected_vertices[6] = size_x; radio_btn_unselected_vertices[7] = size_y; radio_btn_unselected_tex_coord[0] = 0.0f; radio_btn_unselected_tex_coord[1] = 0.0f; radio_btn_unselected_tex_coord[2] = tex_x; radio_btn_unselected_tex_coord[3] = 0.0f; radio_btn_unselected_tex_coord[4] = 0.0f; radio_btn_unselected_tex_coord[5] = tex_y; radio_btn_unselected_tex_coord[6] = tex_x; radio_btn_unselected_tex_coord[7] = tex_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/radio_btn_selected.png", NULL, NULL, &tex_x, &tex_y, &radio_btn_selected)) { fprintf(stderr, "Unable to load selected radio button texture\n"); } radio_btn_selected_vertices[0] = 0.0f; radio_btn_selected_vertices[1] = 0.0f; radio_btn_selected_vertices[2] = size_x; radio_btn_selected_vertices[3] = 0.0f; radio_btn_selected_vertices[4] = 0.0f; radio_btn_selected_vertices[5] = size_y; radio_btn_selected_vertices[6] = size_x; radio_btn_selected_vertices[7] = size_y; radio_btn_selected_tex_coord[0] = 0.0f; radio_btn_selected_tex_coord[1] = 0.0f; radio_btn_selected_tex_coord[2] = tex_x; radio_btn_selected_tex_coord[3] = 0.0f; radio_btn_selected_tex_coord[4] = 0.0f; radio_btn_selected_tex_coord[5] = tex_y; radio_btn_selected_tex_coord[6] = tex_x; radio_btn_selected_tex_coord[7] = tex_y; button_size_x = (float) size_x; button_size_y = (float) size_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/shadow.png", NULL, NULL, &tex_x, &tex_y, &shadow)) { fprintf(stderr, "Unable to load shadow texture\n"); } shadow_size_x = (float) 512; shadow_size_y = (float) 256; shadow_tex_coord[0] = 0.0f; shadow_tex_coord[1] = 0.0f; shadow_tex_coord[2] = tex_x; shadow_tex_coord[3] = 0.0f; shadow_tex_coord[4] = 0.0f; shadow_tex_coord[5] = tex_y; shadow_tex_coord[6] = tex_x; shadow_tex_coord[7] = tex_y; angle = 0.0f; pos_x = 0.0f; pos_y = 0.0f; //Load MyriadPro bold to use for our color menu int dpi = bbutil_calculate_dpi(screen_cxt); if (dpi == EXIT_FAILURE) { fprintf(stderr, "Unable to calculate dpi\n"); return EXIT_FAILURE; } font = bbutil_load_font( "/usr/fonts/font_repository/adobe/MyriadPro-Bold.otf", 15, dpi); if (!font) { return EXIT_FAILURE; } float text_width, text_height; bbutil_measure_text(font, "Color Menu", &text_width, &text_height); menu_height = text_height + 10.0f + button_size_y * 4; //See if a savefile exists. If not, initialize to a hidden menu and a red cube. if (!read_from_file()) { selected = 3; cube_color[0] = 1.0f; cube_color[1] = 0.0f; cube_color[2] = 0.0f; cube_color[3] = 1.0f; menu_animation = 0.0f; menu_active = false; menu_show_animation = false; menu_hide_animation = false; } //Initialize positions of graphics assets on the screen, but don't resize the surface if (EXIT_FAILURE == resize(NULL)) { fprintf(stderr, "Initialize surface\n"); return EXIT_FAILURE; } //Common gl setup glShadeModel(GL_SMOOTH); glClearColor(0.775f, 0.775f, 0.775f, 1.0f); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction); glEnable(GL_CULL_FACE); return EXIT_SUCCESS; }
int initOpenGL(screen_context_t screen_cxt) { fprintf(stderr, "init openGL\n"); //Initialize vertex and color data vertices[0] = 0.0f; vertices[1] = 0.0f; vertices[2] = 1024.0f; vertices[3] = 0.0f; vertices[4] = 0.0f; vertices[5] = 600.0f; vertices[6] = 1024.0f; vertices[7] = 600.0f; verticesH[0] = 0.0f; verticesH[1] = 0.0f; verticesH[2] = 600.0f; verticesH[3] = 0.0f; verticesH[4] = 0.0f; verticesH[5] = 1024.0f; verticesH[6] = 600.0f; verticesH[7] = 1024.0f; verticesTouchpoint[0] = 0.0f; verticesTouchpoint[1] = 0.0f; verticesTouchpoint[2] = 120.0f; verticesTouchpoint[3] = 0.0f; verticesTouchpoint[4] = 0.0f; verticesTouchpoint[5] = 120.0f; verticesTouchpoint[6] = 120.0f; verticesTouchpoint[7] = 120.0f; //Query width and height of the window surface created by utility code EGLint surface_width, surface_height; eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); width = (float) surface_width; height = (float) surface_height; if (width < height) { oriention_side_up = 1; } //On initialize bbutil loads arial as a default font. We are going to load MyriadPro-Bold as it looks a little better and scale it //to fit out bubble nicely. dpi = bbutil_calculate_dpi(screen_cxt); font = bbutil_load_font( "/usr/fonts/font_repository/adobe/MyriadPro-Bold.otf", 9, dpi); if (!font) { return EXIT_FAILURE; } EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query egl surface dimensions\n"); return EXIT_FAILURE; } //Load background texture float tex_x, tex_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/bg.png", NULL, NULL, &tex_x, &tex_y, &background)) { fprintf(stderr, "Unable to load background texture\n"); } //Load background portrait texture float texH_x, texH_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/bg_hochformat.png", NULL, NULL, &texH_x, &texH_y, &backgroundH)) { fprintf(stderr, "Unable to load background portrait texture\n"); } //Load background texture float tex_x_touch, tex_y_touch; if (EXIT_SUCCESS != bbutil_load_texture("app/native/zeiger.png", NULL, NULL, &tex_x_touch, &tex_y_touch, &touchpoint)) { fprintf(stderr, "Unable to load zeiger texture\n"); } tex_coord[0] = 0.0f; tex_coord[1] = 0.0f; tex_coord[2] = tex_x; tex_coord[3] = 0.0f; tex_coord[4] = 0.0f; tex_coord[5] = tex_y; tex_coord[6] = tex_x; tex_coord[7] = tex_y; tex_coordH[0] = 0.0f; tex_coordH[1] = 0.0f; tex_coordH[2] = texH_x; tex_coordH[3] = 0.0f; tex_coordH[4] = 0.0f; tex_coordH[5] = texH_y; tex_coordH[6] = texH_x; tex_coordH[7] = texH_y; tex_coord_touchpoint[0] = 0.0f; tex_coord_touchpoint[1] = 0.0f; tex_coord_touchpoint[2] = tex_x_touch; tex_coord_touchpoint[3] = 0.0f; tex_coord_touchpoint[4] = 0.0f; tex_coord_touchpoint[5] = tex_y_touch; tex_coord_touchpoint[6] = tex_x_touch; tex_coord_touchpoint[7] = tex_y_touch; glShadeModel(GL_SMOOTH); //set clear color to white glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glViewport(0, 0, surface_width, surface_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0.0f, (float) (surface_width) / (float) (surface_height), 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glScalef(1.0f / surface_height, 1.0f / surface_height, 1.0f); //init texture glEnable(GL_TEXTURE_2D); return EXIT_SUCCESS; }
static int initialize() { EGLint surface_width, surface_height; //Load button texture float tex_x = 1.0f, tex_y = 1.0f; //Load texture for button int size_x = 544, size_y = 207; if (EXIT_SUCCESS != bbutil_load_texture("app/native/button.png", NULL, NULL, &tex_x, &tex_y, &button)) { fprintf(stderr, "Unable to load button texture\n"); } button_vertices[0] = 0.0f; button_vertices[1] = 0.0f; button_vertices[2] = size_x; button_vertices[3] = 0.0f; button_vertices[4] = 0.0f; button_vertices[5] = size_y; button_vertices[6] = size_x; button_vertices[7] = size_y; button_tex_coord[0] = 0.0f; button_tex_coord[1] = 0.0f; button_tex_coord[2] = tex_x; button_tex_coord[3] = 0.0f; button_tex_coord[4] = 0.0f; button_tex_coord[5] = tex_y; button_tex_coord[6] = tex_x; button_tex_coord[7] = tex_y; button_size_x = (float) size_x; button_size_y = (float) size_y; eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } width = (float) surface_width; height = (float) surface_height; pos_x = 0.0f; pos_y = 0.0f; //Load a typical arial font to use for our color menu int dpi = bbutil_calculate_dpi(screen_cxt); if (dpi == EXIT_FAILURE) { fprintf(stderr, "Unable to calculate dpi\n"); return EXIT_FAILURE; } //As bbutil renders text using device-specifc dpi, we need to compute a point size //for the font, so that the text string fits into the bubble. Note that Playbook is used //as a reference point in this equation as we know that at dpi of 170, font with point size of //15 fits into the bubble texture. int point_size = (int)(15.0f / ((float)dpi / 170.0f )); font = bbutil_load_font("/usr/fonts/font_repository/monotype/arial.ttf", point_size, dpi); if (!font) { return EXIT_FAILURE; } //Initialize positions of graphics assets on the screen, but don't resize the surface if (EXIT_FAILURE == resize(NULL)) { fprintf(stderr, "Initialize surface\n"); return EXIT_FAILURE; } //Common gl setup glShadeModel(GL_SMOOTH); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_CULL_FACE); return EXIT_SUCCESS; }
int initialize() { EGLint surface_width, surface_height; //Load background and button textures float tex_x = 1.0f, tex_y = 1.0f; //Load textures for radio buttons int size_x = 64, size_y = 64; if (EXIT_SUCCESS != bbutil_load_texture("app/native/radio_btn_unselected.png", NULL, NULL, &tex_x, &tex_y, &radio_btn_unselected)) { fprintf(stderr, "Unable to load non-selected radio button texture\n"); } radio_btn_unselected_vertices[0] = 0.0f; radio_btn_unselected_vertices[1] = 0.0f; radio_btn_unselected_vertices[2] = size_x; radio_btn_unselected_vertices[3] = 0.0f; radio_btn_unselected_vertices[4] = 0.0f; radio_btn_unselected_vertices[5] = size_y; radio_btn_unselected_vertices[6] = size_x; radio_btn_unselected_vertices[7] = size_y; radio_btn_unselected_tex_coord[0] = 0.0f; radio_btn_unselected_tex_coord[1] = 0.0f; radio_btn_unselected_tex_coord[2] = tex_x; radio_btn_unselected_tex_coord[3] = 0.0f; radio_btn_unselected_tex_coord[4] = 0.0f; radio_btn_unselected_tex_coord[5] = tex_y; radio_btn_unselected_tex_coord[6] = tex_x; radio_btn_unselected_tex_coord[7] = tex_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/radio_btn_selected.png", NULL, NULL, &tex_x, &tex_y, &radio_btn_selected)) { fprintf(stderr, "Unable to load selected radio button texture\n"); } radio_btn_selected_vertices[0] = 0.0f; radio_btn_selected_vertices[1] = 0.0f; radio_btn_selected_vertices[2] = size_x; radio_btn_selected_vertices[3] = 0.0f; radio_btn_selected_vertices[4] = 0.0f; radio_btn_selected_vertices[5] = size_y; radio_btn_selected_vertices[6] = size_x; radio_btn_selected_vertices[7] = size_y; radio_btn_selected_tex_coord[0] = 0.0f; radio_btn_selected_tex_coord[1] = 0.0f; radio_btn_selected_tex_coord[2] = tex_x; radio_btn_selected_tex_coord[3] = 0.0f; radio_btn_selected_tex_coord[4] = 0.0f; radio_btn_selected_tex_coord[5] = tex_y; radio_btn_selected_tex_coord[6] = tex_x; radio_btn_selected_tex_coord[7] = tex_y; button_size_x = (float) size_x; button_size_y = (float) size_y; eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } width = (float) surface_width; height = (float) surface_height; if (EXIT_SUCCESS != bbutil_load_texture("app/native/background-landscape.png", NULL, NULL, &tex_x, &tex_y, &background_landscape)) { fprintf(stderr, "Unable to load landscape background texture\n"); } size_x = (width > height) ? width : height; size_y = (width > height) ? height : width; background_landscape_vertices[0] = 0.0f; background_landscape_vertices[1] = 0.0f; background_landscape_vertices[2] = size_x; background_landscape_vertices[3] = 0.0f; background_landscape_vertices[4] = 0.0f; background_landscape_vertices[5] = size_y; background_landscape_vertices[6] = size_x; background_landscape_vertices[7] = size_y; background_landscape_tex_coord[0] = 0.0f; background_landscape_tex_coord[1] = 0.0f; background_landscape_tex_coord[2] = tex_x; background_landscape_tex_coord[3] = 0.0f; background_landscape_tex_coord[4] = 0.0f; background_landscape_tex_coord[5] = tex_y; background_landscape_tex_coord[6] = tex_x; background_landscape_tex_coord[7] = tex_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/background-portrait.png", NULL, NULL, &tex_x, &tex_y, &background_portrait)) { fprintf(stderr, "Unable to load portrait background texture\n"); } size_x = (height > width) ? width : height; size_y = (height > width) ? height : width; background_portrait_vertices[0] = 0.0f; background_portrait_vertices[1] = 0.0f; background_portrait_vertices[2] = size_x; background_portrait_vertices[3] = 0.0f; background_portrait_vertices[4] = 0.0f; background_portrait_vertices[5] = size_y; background_portrait_vertices[6] = size_x; background_portrait_vertices[7] = size_y; background_portrait_tex_coord[0] = 0.0f; background_portrait_tex_coord[1] = 0.0f; background_portrait_tex_coord[2] = tex_x; background_portrait_tex_coord[3] = 0.0f; background_portrait_tex_coord[4] = 0.0f; background_portrait_tex_coord[5] = tex_y; background_portrait_tex_coord[6] = tex_x; background_portrait_tex_coord[7] = tex_y; angle = 0.0f; pos_x = 0.0f; pos_y = 0.0f; //Load a typical arial font to use for our color menu int dpi = bbutil_calculate_dpi(screen_cxt); if (dpi == EXIT_FAILURE) { fprintf(stderr, "Unable to calculate dpi\n"); return EXIT_FAILURE; } //As bbutil renders text using device-specifc dpi, we need to compute a point size //for the font, so that the text string fits into the bubble. Note that Playbook is used //as a reference point in this equation as we know that at dpi of 170, font with point size of //15 fits into the bubble texture. int point_size = (int)(15.0f / ((float)dpi / 170.0f )); font = bbutil_load_font("/usr/fonts/font_repository/monotype/arial.ttf", point_size, dpi); if (!font) { return EXIT_FAILURE; } float text_width, text_height; bbutil_measure_text(font, "Color Menu", &text_width, &text_height); menu_height = text_height + 10.0f + button_size_y * 4; //See if a savefile exists. If not, initialize to a hidden menu and a red cube. if (!read_from_file()) { selected = 3; cube_color[0] = 1.0f; cube_color[1] = 0.0f; cube_color[2] = 0.0f; cube_color[3] = 1.0f; menu_animation = 0.0f; menu_active = false; menu_show_animation = false; menu_hide_animation = false; } //Initialize positions of graphics assets on the screen, but don't resize the surface if (EXIT_FAILURE == resize(NULL)) { fprintf(stderr, "Initialize surface\n"); return EXIT_FAILURE; } //Common gl setup glShadeModel(GL_SMOOTH); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction); glEnable(GL_CULL_FACE); menu_show_animation = true; return EXIT_SUCCESS; }
int init() { EGLint surface_width, surface_height; //Load background texture float tex_x, tex_y; int size_x, size_y; if (EXIT_SUCCESS != bbutil_load_texture("app/native/HelloWorld_bubble_portrait.png", &size_x, &size_y, &tex_x, &tex_y, &background)) { fprintf(stderr, "Unable to load background texture\n"); return EXIT_FAILURE; } //Query width and height of the window surface created by utility code eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width); eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height); EGLint err = eglGetError(); if (err != 0x3000) { fprintf(stderr, "Unable to query EGL surface dimensions\n"); return EXIT_FAILURE; } width = (float) surface_width; height = (float) surface_height; int dpi = bbutil_calculate_dpi(screen_ctx); //As bbutil renders text using device-specifc dpi, we need to compute a point size //for the font, so that the text string fits into the bubble. We use 15 pt as our //font size. // // This app assumes the use of a Z10 in portrait mode. For other devices and // orientations, you need to modify the code and settings accordingly. // font with point size of //15 fits into the bubble texture. const float Z10_DPI = 358.0f; const float FONT_PT_SIZE = 15.0f; float stretch_factor = (float)surface_width / (float)size_x; int point_size = (int)(FONT_PT_SIZE * stretch_factor / ((float)dpi / Z10_DPI )); font = bbutil_load_font("/usr/fonts/font_repository/monotype/arial.ttf", point_size, dpi); if (!font) { return EXIT_FAILURE; } //Initialize GL for 2D rendering 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(); //Set world coordinates to coincide with screen pixels glScalef(1.0f / height, 1.0f / height, 1.0f); float text_width, text_height; bbutil_measure_text(font, message, &text_width, &text_height); pos_x = (width - text_width) / 2; pos_y = height / 2; //Setup background polygon vertices[0] = 0.0f; vertices[1] = 0.0f; vertices[2] = width; vertices[3] = 0.0f; vertices[4] = 0.0f; vertices[5] = height; vertices[6] = width; vertices[7] = height; tex_coord[0] = 0.0f; tex_coord[1] = 0.0f; tex_coord[2] = tex_x; tex_coord[3] = 0.0f; tex_coord[4] = 0.0f; tex_coord[5] = tex_y; tex_coord[6] = tex_x; tex_coord[7] = tex_y; return EXIT_SUCCESS; }