Before you begin

You should have a basic understanding of the C language and some experience running applications with the QNX Momentics IDE. Before starting this tutorial, you should have the following things ready:

  • The BlackBerry Native SDK for Tablet OS
  • Your BlackBerry PlayBook
  • A BlackBerry Tablet OS C project created in the QNX Momentics IDE using the BlackBerry Tablet OS OpenGL ES 1.1 Application Template Project (or follow along with the sample app)

Let's get started

There are two important files you get with the template, main.c and bbutil.c. The main.c file is where you put all your application-specific code. The bbutil.c file is provided by the template to contain functions that are common across all applications that want to do basic screen and OpenGL ES operations. Here, we'll jump back and forth between the two files so that you understand the key steps of creating a native window within the context of the template (so hopefully, you won't need the template after this).

To create an OpenGL ES window, we first have to create a native window. This is provided to you in the bbutil_init_egl() function in bbutil.c. There is a lot of EGL set up code in there, which we'll discuss later, but to create a native window, we first declare a place to store the window, screen_win and call the screen_create_window() function. It would look something like this:

screen_window_t screen_win;

screen_create_window(&screen_win, screen_ctx);

What is that other parameter you ask? It's a screen context variable. A context is just some information about something - the screen in this case. Having the information in a single variable makes it easy to get at when it's needed. Since the screen context is required by functions that are specific to our application (event handling, for example), it is declared and initialized in the main() function in main.c:

screen_context_t screen_ctx;
screen_create_context(&screen_ctx,0);

The screen context is passed in to bbutil_init_egl() later in main(). So, to set up a native window, you create a screen context and a screen window. The end result is that screen_win refers to a native window that has some associated information about it stored in screen_ctx.