Create your first core Native app

Now that you've set up your environment, let's build an app together. In this tutorial, we'll create a basic 2-D application that displays a 2-D, rotating, colored square on a white background. This tutorial assumes that you have a basic understanding of the C/C++ programming language but, rather than have you input all your own code, we'll provide you with the code and you can follow along. You can create the project and run the sample and then you can play with the code a little bit.

You will learn to:

  • Set up a project
  • Use the IDE to build and run a sample app
  • Update the sample code to create a 3-D rotating cube using OpenGL ES 1.1 or 2.0.

Setting up a project

Since we don't want to create a project from scratch, we'll create one using a sample project provided with the IDE.

  1. In the QNX Momentics IDE, click File > New > BlackBerry Project.
  2. Select Application>OpenGL and click Next.
  3. Select OpenGL ES 1.1 and click Next. On this screen, you can change the name of the project, the language you want to use (C or C++), whether you want to use a Managed or Makefile build, and more. We're going to accept the defaults, but to find out more about the settings on this screen, see Creating apps.
  4. Click Finish.
After you've finished all that, a new project appears in the Project Explorer view with the name that you specified. The BAR application descriptor file is displayed in the editor view.

What's in your project

Your new project contains a few folders and files. All source code is in the src folder; images are directly under the project folder. When you build the project, the binaries will appear in the Binaries folder. All the include files you need to compile your project are in the Includes folder. In the src folder, there are three source code files:

  • main.c, which includes the main() function as well as initialization, event handling, and rendering functions.
  • bbutil.h and bbutil.c, which provide convenient utility functions for commonly used operations such as loading textures and rendering text.

Running the app

Now you are just a few steps away from seeing a brightly colored, rotating image. Let's build and run it to see the output.

Before you try to run the application, you need to make sure that you have a device or simulator set up as a target in the QNX Momentics IDE. You'll also need to create a debug token and upload it to the device.

For information about setting up the development environment, see Set up your environment.

To run the application:

  1. In the Project Explorer view, expand your project and double-click bar-descriptor.xml.
  2. When the descriptor opens in the editor, click Set from Debug Token to set the author information for the app.

    If a debug token cannot be found, you need to create a new one.

  3. Right-click your project and select Build Configurations > Set Active. From the list, select Device-Debug if you are going to run the application on a device, or Simulator-Debug if you plan to test on the simulator.
  4. Right-click your project and click Build Project.
  5. Right-click your project again and click Run As > BlackBerry C/C++ Application.

Celebrate! You've successfully built your first BlackBerry app!