Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
111 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

An Introduction to BREW and OpenGL ES


Introduction

It was only a matter of time until someone decided to put a 3d graphics API onto a phone handset. OpenGL has long been a graphics industry standard for 3d, and now OpenGL ES is fast becoming the standard for 3d on limited devices. Limited devices is an apt description though, even a high end phone might only have a 50Mhz ARM processor and 1MB of memory. But don't be put off, even with these limitations you can still create some very impressive games.

Writing games for mobile phones is unlike writing for the PC. With the design more limited by the platform restrictions you don't need a huge team with multiple programmers and an army of artists, its well within reason for a single person to turn out a quality title from the comfort of their bedroom.

This article will go from installing and setting up a BREW development environment and emulator, through to getting an Open GL ES system up and running and displaying a single triangle. From there existing OpenGL resources can take you further into the process of developing your 3d application.

Installing the BREW SDK

You really need to use Internet Explorer for this process. The BREW SDK is installed by an ActiveX control which only seems to work in Internet Explorer 6 or better. During this article I am going to assume you create a c:\BREW directory, and then install the BREW SDK into c:\BREW\BREW 3.0.1. If you want to install it somewhere else (like the default c:\program files\BREW 3.0.1), then just adapt the paths I mention as you proceed.

First, go here and register for a free BREW developer account, then install the BREW 3.0.1 SDK from here. Its a web based installer, just start it going, give it a directory to install to and wait. At around 20MB it won't take too long to install, even on a 56k modem. Towards the end it will ask if you want it to set a BREWDIR environment variable. Say yes or various things won't work correctly.

From this page, install the Visual C++ addon, and download the BREW SDK Extension for OpenGL ES. Extract the OpenGL ES zip file, and:

  • Move all files from inc into c:\BREW\BREW 3.0.1\sdk\inc
  • Move all files from src into c:\BREW\\BREW 3.0.1\sdk\src
  • Move the dll from BREW 3.x into c:\BREW\BREW 3.0.1\sdk\bin\modules
  • Move all files from devices into c:\BREW\BREW 3.0.1\sdk\devices

Directory structure

BREW is a bit tricky sometimes when it comes to where it expects to find various files, and tends to give the same cryptic error message for pretty much any case of missing or misplaced files. Below is how I have my machine setup. For this article I am assuming you have the same setup, again if you install BREW somewhere else just substitute your paths as appropriate.

c:\BREW\ My BREW root directory
c:\BREW\BREW 3.0.1\   The 3.0.1 SDK. You can have several SDKs installed at once and chose between them by setting an environment variable
c:\BREW\project1\ A project directory
c:\BREW\project1.mif The MIF file for project 1 (note that its here and not inside the project1 directory, very important)

Create new project

  • Select the Brew App Wizard (under Visual c++ projects)
  • Set the "location" to c:\BREW
  • Enter a project name. Make it lower case with no spaces or special symbols, lets choose "test_project1" (this is what I'll refer to through out the article as the project name)
  • Hit OK, and then Finish without making any changes on the Wizard dialog or running the MIF editor
  • It will probably say that the project has been modified outside Visual C++, so say OK to reload

MIF editor

  • Run the MIF editor. On the Visual C++ BREW toolbar (which should be on by default, if not right click in the toolbar are and enable it) its third button
  • Click the new button (NOT File -> New)
  • Assuming your not a licensed BREW developer you will need to generate a class id locally. Select that option.
  • Make up a class id, I started at A0000001 and went up as I created more projects. Pick anything, but if you create more projects they must have unique class id's
  • Enter your project name as the class name, so in our case "test_project1"
  • Click OK, and you will be prompted to save. Save into the project directory, so c:\BREW\test_project1\test_project1.bid
  • File->save, save into the PARENT of the project directory, so c:\BREW\test_project1.mif
  • Now compile the MIF by choosing Build -> compile MIF script. Click OK a couple of times and you're done.

Setting up to run and debug through Visual Studio

  • Right click on the project in solution explorer to get up project properties
  • Configuration properties -> Debugging -> Command, Select BREW_Simulator.exe in your BREW SDK bin directory (in my case, C:\BREW\BREW 3.0.1\sdk\bin\BREW_Simulator.exe)
  • Configuration properties -> Linker -> Debugging, Change "Generate debug info" to "Yes (/DEBUG)"

Compile and run the project. It should compile with no errors and start the emulator. If you get compile errors you probably didn't set your class name in the MIF editor to exactly the same as the project name.

Now if you set a break point in your code it will get triggered correctly when the emulator is running your dll.

The emulator

Select Blackcap16 as your emulator profile. From File -> Load Device browse to the devices directory of the SDK and select Blackcap16.qsc. It remembers which device you are using, so you will only have to do this the first time you run the emulator.

In the emulator, File -> Change applet directory. Set it to the directory that contains your .mif file and your project directory, for me thats c:\BREW.

You should now see the emulator with two icons, your projects and Settings. Use the arrow keys to select which application you want to run, and enter to start it. When you run your project it looks like nothing happens! Thats because the app wizard only generates boiler plate start up code for you. You should see in the output window of Visual C++ a message saying that your dll was loaded, assuming it does and you get no errors, success!

If you get a message saying "This app was disabled to save space. Would you like to restore it now?", that's the cryptic message I mentioned earlier. It almost always means you have your files in the wrong places (probably the .dll in the wrong place.) Assuming you used the app wizard to generate your initial code, check you saved the .mif file into the right place.



Data storage, timers, math and input


Contents
  Introduction
  Data storage, timers, math and input
  OpenGL ES

  Printable version
  Discuss this article