Tutorial: Create a basic 2-D app in C
In this tutorial, we explore the OpenGL ES 1.1 project template and demonstrate how to set up the BlackBerry Platform Services library, the screen.h library, and EGL to display a rotating, 2-D, colored square on a white background.
You will learn to:
- Set up the BlackBerry Platform Services library
- Create a screen context
- Initialize EGL for 2-D rendering
- Clean up graphics
Before you begin
You should have the following things ready:
- The BlackBerry 10 Native SDK
- A device or simulator running BlackBerry 10
This app is available by creating a project in the Momentics IDE for BlackBerry and choosing the BlackBerry 10 OS OpenGL ES 1.1 template.
Set up your project
Because we don't want to write all of the setup code from scratch, let's create a project using the BlackBerry 10 OS OpenGL ES 1.1 Application Template. This template includes a file called bbutil.h. The bbutil.h file contains convenient functions that you can call from your app. These functions help you perform common tasks such as initializing and terminating EGL, loading and rendering text and textures, and resizing your EGL surface as a part of orientation change handling.
- In the Momentics IDE, on the File menu, click New > BlackBerry Project.
- In the Project Type section, select Core Native. Click Next.
- In the Templates section, select the version of OpenGL that you want to use. Click Next.
- In the Basic Settings section, enter a name for your project (for example, MyProject). Click Next.
- In the API Level section, select the API level that you want to use.
- Click Finish.
A new project appears in the Project Explorer view. If you expand the project, you'll notice that it contains three source files in the src folder: bbutil.c, bbutil.h, and main.c. These files contain the fundamental code for our app.
- main.c includes the main() function as well as initialization, event handling, and rendering functions.
- bbutil.h and bbutil.c provide convenient utility functions for commonly used operations such as loading textures and rendering text.
Now we are ready to take a closer look at the app.
Last modified: 2015-03-31