Functions in the bbutil API

The template projects provide several useful utility functions that you can use to set up your EGL app. These functions are in the bbutil.c file within the project. Let's take a look at the functions in the bbutil API and what they do for us. We'll state the function and its signature, and then discuss it.

int bbutil_init_egl(screen_context_t ctx)

This function initializes a native window and EGL for use. The ctx parameter is the libscreen context that will be used for the EGL setup and must be created before it is passed to this function. If initialization is successful, EXIT_SUCCESS is returned; otherwise EXIT_FAILURE is returned.

void bbutil_terminate()

This function cleans up EGL and the native window, so all the components that were allocated during initialization are deallocated.

void bbutil_swap()

This function swaps the default window surface to the screen using the eglSwapBuffers() function.

font_t* bbutil_load_font(const char* font_file, int point_size, int dpi)

This function loads a font file and should be called after a successful return of the bbutil_init_egl() function. The font_file parameter is a string of the absolute path of the font file. The point_size parameter specifies the height and width of the glyphs to be generated. The dpi parameter specifies the horizontal and vertical resolution, which is used with the point_size to generate glyphs. If the font file is loaded successfully, a pointer to a font_t structure is returned; otherwise, NULL is returned.

void bbutil_destroy_font(font_t* font)

This function deletes the specified font texture from memory.

void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r, float g, float b, float a)

This function renders the specified message using the current font from the specified bottom-left coordinates. The font parameter specifies the font to use for rendering. The msg parameter specifies the message to display. The x and y parameters specify the position of the bottom-left corner of the text string in the overall coordinate space where you want to render the text. Finally, the r, g, b, and a parameters specify the RGBA color for the text to render with.

void bbutil_measure_text(font_t* font, const char* msg, float* width, float* height)

This function returns the non-scaled width and height of a string. The font parameter specifies the font to use for measuring a string size. The msg parameter specifies the message to get the size of. The width and height pointer parameters are filled with calculated width and height, respectively.

int bbutil_load_texture(const char* filename, int* width, int* height, float* tex_x, float* tex_y, unsigned int* tex)

This function creates and loads a texture from a .png file and must be called after a successful return of the bbutil_init_egl() function. The filename parameter specifies the path to the texture .png file to load. The pointer parameters, height and width, are returned with the height and width of the created texture. The pointer parameters, tex_x and tex_y, are returned with the modified texture coordinates. Finally, the pointer parameter, tex, is returned with a handle of the created texture.

int bbutil_calculate_dpi(screen_context_t ctx)

This function returns the DPI for a given screen. The ctx parameter specifies the screen context that corresponds to the given screen.

int bbutil_rotate_screen_surface(int angle)

This function rotates the screen to a given angle. The angle parameter must be set to 0, 90, 180, or 270. If the screen was successfully rotated, EXIT_SUCCESS is returned; otherwise EXIT_FAILURE is returned.

So, that's the breakdown of the functions available to you in the bbutil API. However, if you're using OpenGL ES 1.1 and OpenGL ES 2.0 in the same application, you will need to handle the setup provided by the bbutil API yourself.

Last modified: 2014-05-14



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus