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.
- In the QNX Momentics IDE, click File > New > BlackBerry Project.
- Select Application>OpenGL and click Next.
- 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.
- Click Finish.
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:
- In the Project Explorer view, expand your project and double-click bar-descriptor.xml.
- 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.
- 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.
- Right-click your project and click Build Project.
- Right-click your project again and click Run As > BlackBerry C/C++ Application.
Celebrate! You've successfully built your first BlackBerry app!